例子:
一个xml.xml文件:
<?xml version="1.0" encoding="UTF-8"?>
<user>
<persons 序号="1" value="2ec192fa-4a43-4da1-a65c-1765529839a1" name="张三"/>
</user>
如果要获取xml.xml中value的值
方法:
XmlDocument xmldoc = new XmlDocument();
xmldoc.Load("xml.xml");
string Temp = String.Empty;
XmlNode nodes = xmldoc.SelectSingleNode("user");
for (int i = 0; i < nodes.ChildNodes.Count; i++)
{
XmlNode c = nodes.ChildNodes[i];
Temp = c.Attributes["value"].Value;
if (Temp.ToString() == null || Temp.ToString() == "")
{
c.Attributes["value"].Value = Temp;
}
}