如何检索XML?
<?xml version= "1.0 " encoding= "GB2312 "?>
<contact>
<person>
<name> xyz </name>
<number> 333 </number>
<email> ert </email>
</person>
</contact>
我想通过输入xyz检索并确定节点,请问该怎么做?
------解决方案--------------------try..
XmlDocument doc = new XmlDocument();
doc.Load(@ "../../test.xml ");
string itemname = "xyz ";
XmlNodeList nodes = doc.SelectNodes(@ "//*[text()= ' "+itemname + " '] ");
foreach (XmlNode node in nodes)
{
Console.WriteLine(node.Name);
}
------解决方案--------------------itemname= 'xyz '
要有引号的
string itemname = "xyz ";
XmlNodeList nodes = doc.SelectNodes(@ "//*[text()= ' "+itemname + " '] ");