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

阅读更多
文章标签: string null path xml
个人分类: XML
下一篇读写XML
想对作者说点什么? 我来说一句

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

关闭
关闭
关闭