XML 内联构架搜索与修改
XML 文件如下:StorehouseClass.xml
<?xml version="1.0" standalone="yes"?>
<dsPubs xmlns="http://www.tempuri.org/dsPubs.xsd">
   <xs:schema id="dsPubs" targetNamespace="http://www.tempuri.org/dsPubs.xsd" xmlns:mstns="http://www.tempuri.org/dsPubs.xsd" xmlns="http://www.tempuri.org/dsPubs.xsd" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata" attributeFormDefault="qualified" elementFormDefault="qualified">
     <xs:element name="dsPubs" msdata:IsDataSet="true" msdata:Locale="en-US">
       <xs:complexType>
         <xs:choice minOccurs="0" maxOccurs="unbounded">
           <xs:element name="StorehouseClass">
             <xs:complexType>
               <xs:sequence>
                 <xs:element name="SC_ID" type="xs:string" />
                 <xs:element name="SC_Name" type="xs:string" />
                 <xs:element name="SC_IsWave" type="xs:string" />
               </xs:sequence>
             </xs:complexType>
           </xs:element>
         </xs:choice>
       </xs:complexType>
     </xs:element>
   </xs:schema>
   <StorehouseClass>
     <SC_ID>1</SC_ID>
     <SC_Name>城网库房</SC_Name>
     <SC_IsWave>否</SC_IsWave>
   </StorehouseClass>
   <StorehouseClass>
     <SC_ID>2</SC_ID>
     <SC_Name>农网库房</SC_Name>
     <SC_IsWave>是</SC_IsWave>
   </StorehouseClass>
   <StorehouseClass>
     <SC_ID>5</SC_ID>
     <SC_Name>55</SC_Name>
     <SC_IsWave>是</SC_IsWave>
   </StorehouseClass>
   <StorehouseClass>
     <SC_ID>8</SC_ID>
     <SC_Name>8</SC_Name>
     <SC_IsWave>是</SC_IsWave>
   </StorehouseClass>
</dsPubs>
我现在想找到SC_ID为8的StorehouseClass元素,写了几个测试程序,都不行,头痛啊!
(注,这个XML 文件属于内联架构,和MSDN给出的例子有局别)。
测试程序如下:
XmlDocument doc = new XmlDocument();
      doc.Load(HttpContext.Current.Server.MapPath("~/App_Data/StorehouseClass.xml"));
      XmlNode node = doc.SelectSingleNode("/*");
      Response.Write(node.Name + "<br>");
      node = doc.SelectSingleNode(".");
      Response.Write(node.Name + "<br>");
      node = doc.SelectSingleNode("child::node()");
      Response.Write(node.Name + "<br>");
      XmlNodeList xmlList = node.SelectNodes("child::node()");       
      Response.Write(xmlList.Count+"<br>");
      foreach (XmlNode mc in xmlList)
      {
          Response.Write(mc.Name+"=="+mc.NodeType+"<br>");
      }
      xmlList = node.SelectNodes("StorehouseClass");
      Response.Write(xmlList.Count + "<br>");
      xmlList = node.SelectNodes("./StorehouseClass");
      Response.Write(xmlList.Count + "<br>");
============================================================================
输出结果为:
dsPubs
#do