现有一个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"????
就是一个查询的过程,请问如何写呢??运行效率高点,因为如果里面内容多的话可能读取会慢.
请给出代码示例谢谢.

解决方案 »

  1.   

    agree with "直接找到等于CA的节点,然后找其父亲,再找其第二个儿子就行了"
      

  2.   

    XmlNode node = root.SelectSingleNode(name);  //find  the value is CA return the node
    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
      

  3.   

    像这种比较规则的xml直接用dataset就可以loadxml了,然后就像操作数据表一样操作就Ok了
      

  4.   

    XmlNode node = root.SelectSingleNode(//Countries/country[value="CA"]);
    node.SelectSingleNode("text").InnerText;
      

  5.   

    XmlNode node = root.SelectSingleNode("//Countries/country[value='CA']");
      

  6.   

    XmlDocument xmlDoc=new XmlDocument();
    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文件