0

我想将 xml 文件中的数据部分显示为 listview 一个 listview(winapp)。欢迎任何想法。提前致谢!

这是我的示例 xml 文件:

<xml xmlns:s="uuid:BDC6E3F0-6DA3-11d1-A2A3-00AA00C14882" 
xmlns:dt="uuid:C2F41010-65B3-11d1-A29F-00AA00C14882" 
xmlns:rs="urn:schemas-microsoft-com:rowset" 
xmlns:z="#RowsetSchema"> 
  <s:Schema id="RowsetSchema"> 
    <s:ElementType name="row" content="eltOnly" rs:updatable="true"> 
      <s:AttributeType name="ShipperID" rs:number="1" 
        rs:basetable="shippers" rs:basecolumn="ShipperID"
        rs:keycolumn="true"> 
        <s:datatype dt:type="int" dt:maxLength="4" rs:precision="10" 
          rs:fixedlength="true" rs:maybenull="false"/> 
      </s:AttributeType> 
      <s:AttributeType name="CompanyName" rs:number="2" 
        rs:nullable="true" rs:write="true" rs:basetable="shippers" 
        rs:basecolumn="CompanyName"> 
        <s:datatype dt:type="string" dt:maxLength="40" /> 
      </s:AttributeType> 
      <s:AttributeType name="Phone" rs:number="3" rs:nullable="true" 
        rs:write="true" rs:basetable="shippers" 
        rs:basecolumn="Phone"> 
        <s:datatype dt:type="string" dt:maxLength="24"/> 
      </s:AttributeType> 
      <s:extends type="rs:rowbase"/> 
    </s:ElementType> 
  </s:Schema> 

  <rs:data> 
    <z:row ShipperID="1" CompanyName="Speedy Express" 
      Phone="(503) 555-9831"/> 
    <z:row ShipperID="2" CompanyName="United Package" 
      Phone="(503) 555-3199"/> 
    <z:row ShipperID="3" CompanyName="Federal Shipping" 
      Phone="(503) 555-9931"/> 
  </rs:data> 
</xml>

结果应该是:

ShipperID   CompanyName     Phone
---------   --------------      --------------
1       Speedy Express      (503) 555-9831
2       United Package      (503) 555-3199
3       Federal Shipping    (503) 555-9931
4

1 回答 1

0

知道了..

var xml = XDocument.Load(xmlstring);
XNamespace ns = "#RowsetSchema";
foreach (var element in xml.Descendants().Elements(ns + "row"))
{
    MessageBoc.Show(element.Attribute("ShipperID").Value +"-"+ element.Attribute("CompanyName").Value +"-"+ element.Attribute("Phone").Value); 
}
于 2013-07-12T08:52:05.557 回答