XmlDocument xmlDoc=new XmlDocument();
xmlDoc.Load(your.xml");
//get first element
XmlElement xmlRoot=xmlDoc.DocumentElement;
XmlNode node=xmlRoot.SelectSingleNode("//bb[id='xxxx']");
XmlNode n=node.SelectSingleNode("//filepath");
this.txtOut.Text=n.InnerText.ToString();

解决方案 »

  1.   

    <aa>
       <a1>ddd</a1>
       <a2>jjj</a2>
        ....
       <filepath>...</filepath>
    </aa><bb>
    ...
    </b><bb>
       <id>xxxx</id>
       <filepath>xxxxx</filepath>
       ...
    </bb>xml是这样的,楼上写的不行,只能得到<aa>中的filepath
      

  2.   

    XmlNode n=node.SelectSingleNode("//filepath");
    改为
    XmlNode n=node.SelectSingleNode("filepath");
      

  3.   

    那这样不是变成这样了吗?<bb>
    ..
      <id>
         <filepath>xxx</filepath>
      </id></bb>
    XmlNode n=node.SelectSingleNode("filepath");
    试了也不行~
      

  4.   

    xml是这样子
    <root>
    <aa>
       <a1>ddd</a1>
       <a2>jjj</a2>
       <filepath>tmd</filepath>
    </aa>
    <bb>
       <id>xxxx</id>
       <filepath>xxxxx</filepath>
     </bb>
    <bb>
       <id>www</id>
       <filepath>xxwwwxx</filepath>
     </bb>
    </root>
      

  5.   

    请不要用这样的方法;可用如下的xml;
    <root>
    <aa>
       <a1>ddd</a1>
       <a2>jjj</a2>
       <filepath>tmd</filepath>
    </aa>
    <bb id=xxxx>
       <filepath>xxxxx</filepath>
     </bb>
    <bb id=www>
       <filepath>xxwwwxx</filepath>
     </bb>
    </root>
      

  6.   

    如要忠于你提供的xml,需要自己写方法。
    1、 通过SelectNodes方法获得所有名称为ID的接点。
    2、 找出其值为xxxx 的接点(需要自己写,一个循环判断);
    3、 获得找到接点的父接点。
    4、 读取字节点filePath的值。
    can understand?
      

  7.   

    我的id值是唯一的xmlnode nd=root.selectsinglenode("//bb/id[text()='xxx']");这样得到了id为xxx的节点的父节点为:xmlnode ndP=nd.parentnode;那我怎么读取到filepath的值?
      

  8.   

    少了一个P
    XmlNode nd1=ndP.NextSibling;
      

  9.   

    你试一下
    XmlNode curNode = nd.parentnode.selectsingleNode("filepath");
    string strNeed = curNode.nodeValue;