我是从网上读取的,用webrequest来读取,现在是一个stream 我如何把他放入xmltxtread中去检索,我用dom可以读string,但xmltxtread怎么读stream流,二是我如何在xmltxtread中确定一个我想我的节点,然后可以读取节点的子节点的值<root>
<map>
<rot1>sdf</rot1>
<map>
<st>
  <rot2  chil="M4>
     <value>sdf</value>
     <stdate>
        <stvalue>123</stvalue>
     </stdate>
  </rot2>  <rot2  chil="M12>
     <value>sdf</value>
     <stdate>
        <stvalue>123</stvalue>
     </stdate>
  </rot2>
  <rot2  chil="M6>
     <value>sdf</value>     <stdate>
        <stvalue>123</stvalue>
     </stdate>
  </rot2>
....
我如何可以快速找到M12这个节点然后读取这个节点,谢谢大家

解决方案 »

  1.   

    [C#] 
    using System;
    using System.IO;
    using System.Xml;public class Sample
    {
      public static void Main()
      {      XmlDocument doc = new XmlDocument();
          doc.Load("booksort.xml");      //Create an XmlNamespaceManager for resolving namespaces.
          XmlNamespaceManager nsmgr = new XmlNamespaceManager(doc.NameTable);
          nsmgr.AddNamespace("bk", "urn:samples");      //Select the book node with the matching attribute value.
          XmlNode book;
          XmlElement root = doc.DocumentElement;
          book = root.SelectSingleNode("descendant::book[@bk:ISBN='1-861001-57-6']", nsmgr);      Console.WriteLine(book.OuterXml);  }
    }
    该示例使用文件 booksort.xml 作为输入。<?xml version="1.0"?>
    <!-- A fragment of a book store inventory database -->
    <bookstore xmlns:bk="urn:samples">
      <book genre="novel" publicationdate="1997" bk:ISBN="1-861001-57-8">
        <title>Pride And Prejudice</title>
        <author>
          <first-name>Jane</first-name>
          <last-name>Austen</last-name>
        </author>
        <price>24.95</price>
      </book>
      <book genre="novel" publicationdate="1992" bk:ISBN="1-861002-30-1">
        <title>The Handmaid's Tale</title>
        <author>
          <first-name>Margaret</first-name>
          <last-name>Atwood</last-name>
        </author>
        <price>29.95</price>
      </book>
      <book genre="novel" publicationdate="1991" bk:ISBN="1-861001-57-6">
        <title>Emma</title>
        <author>
          <first-name>Jane</first-name>
          <last-name>Austen</last-name>
        </author>
        <price>19.95</price>
      </book>
      <book genre="novel" publicationdate="1982" bk:ISBN="1-861001-45-3">
        <title>Sense and Sensibility</title>
        <author>
          <first-name>Jane</first-name>
          <last-name>Austen</last-name>
        </author>
        <price>19.95</price>
      </book>
    </bookstore>orXmlDocument doc = new XmlDocument();
    doc.Load("coil.xml");
    XmlElement root = doc.DocumentElement;
    XmlNode elem = root.SelectSingleNode("descendant::coil[coil_id='A131']");
    if (elem!=null)
    {
    Console.WriteLine(elem.ChildNodes[1].InnerText.ToString());
    return true;
    }
    else
    {
    Console.WriteLine("not found node");
    return false;
    }
      

  2.   

    你这是用dom来读的,我已经完成,只是用一XmlNode elem = root.SelectSingleNode("descendant::coil[coil_id='A131']");
    一句定位我不知如何写,现在如果不知道,我想改用xmltextread来读,听说快一点,所以我想问xmltextread能读流吗
      

  3.   

    <root>
    <book buyDate="2005-02-30" Type="1">
       <smallDate>2003-03-31</smallDate>
       <Detail Tvip="M3">
             <Value>27.8</Value>
             <name>C++高级编程</name> 
         </Detail>
    </book >
    <book buyDate="2005-02-30" Type="1">
       <smallDate>2003-03-31</smallDate>
       <Detail Tvip="M4">
             <Value>27.8</Value>
             <name>C++高级编程</name> 
         </Detail>
    </book >
    <book buyDate="2005-02-30" Type="1">
       <smallDate>2003-03-31</smallDate>
       <Detail Tvip="M12">
             <Value>27.8</Value>
             <name>C++高级编程</name> 
         </Detail>
    </book ><book buyDate="2005-02-30" Type="1">
       <smallDate>2003-03-31</smallDate>
       <Detail Tvip="M6">
             <Value>27.8</Value>
             <name>C++高级编程</name> 
         </Detail>
    </book ><book smallDate="2005-02-30" Type="1">
       <smallDate>2003-03-31</smallDate>
       <Detail Tvip="M12">
             <Value>27.8</Value>
             <name>C++高级编程</name> 
         </Detail>
    </book >
    </root>
    我如何找到Tvip的这个book大节点,因为我要取smallDate  和smallDate加上value和name的值,哪
    XmlNode elem = root.SelectSingleNode("descendant::coil[coil_id='A131']");
    这样一句我如何写,谢谢