读写XML

读:
public static string GetNodeString(XmlDocument doc, string xpath)
{
string nodeValue = "";

XmlElement root = doc.DocumentElement;
XPathNavigator nav = root.CreateNavigator();

XPathNodeIterator xpNodIter = nav.Select(xpath);

if (xpNodIter.MoveNext()) {
nodeValue = xpNodIter.Current.ToString();
}
return nodeValue;
}

写:
private static bool setNodeValue(XmlDocument doc, String path, String nodeValue)
{
if(doc == null || labelType == "" || labelType == null ) return false;
XmlNode node = doc.SelectSingleNode(path);
XmlNode valueNode = node.NextSibling;
if(valueNode != null)
{
if( nodeValue == null || "".Equals(nodeValue))
{
valueNode.InnerText = "";
}
else
{
valueNode.InnerText = text;
}
                  doc.Save();
return true;
}
else
return false;
}

阅读更多
想对作者说点什么?

博主推荐

换一批

没有更多推荐了,返回首页