读:
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;
}