现有一个xml文件<?xml version="1.0" encoding="utf-8" ?>
<Countries>
<country>
<value>GB</value>
<text>United KingDom</text>
</country>
<country>
<value>CA</value>
<text>China</text>
</country>
<country>
<value>US</value>
<text>United America</text>
</country>
<country>
<value>AU</value>
<text>Austrila</text>
</country>
</Countries>现假设知道值 value = "CA",请问如何得到 text = "China"????
就是一个查询的过程,请问如何写呢??运行效率高点,因为如果里面内容多的话可能读取会慢.
请给出代码示例谢谢.
<Countries>
<country>
<value>GB</value>
<text>United KingDom</text>
</country>
<country>
<value>CA</value>
<text>China</text>
</country>
<country>
<value>US</value>
<text>United America</text>
</country>
<country>
<value>AU</value>
<text>Austrila</text>
</country>
</Countries>现假设知道值 value = "CA",请问如何得到 text = "China"????
就是一个查询的过程,请问如何写呢??运行效率高点,因为如果里面内容多的话可能读取会慢.
请给出代码示例谢谢.
then you may get the node's parent's node
foreach in your parent's node when in the second node record this value what you want
node.SelectSingleNode("text").InnerText;
try
{
xmlDoc.Load("c:\\1.xml");//FilePath_Style为文件路径
}
catch
{
return;
}
XmlNode book;
XmlNode root1 = xmlDoc.DocumentElement;
book=root1.SelectSingleNode("descendant::country[value='CA']");
Response.Write(book.SelectSingleNode("descendant::text").InnerText);=========================
//C盘1.xml文件是你给出的那个XML文件