请问下以下XML如何读取到元素值
- <DataTable>- <xs:schema id="NewDataSet" xmlns="" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
- <xs:element name="NewDataSet" msdata:IsDataSet="true" msdata:MainDataTable="file" msdata:UseCurrentLocale="true">
- <xs:complexType>
- <xs:choice minOccurs="0" maxOccurs="unbounded">
- <xs:element name="file">
- <xs:complexType>
- <xs:sequence>
<xs:element name="Id" type="xs:int" minOccurs="0" />
<xs:element name="FolderId" type="xs:int" minOccurs="0" />
<xs:element name="Name" type="xs:string" minOccurs="0" />
<xs:element name="ExtName" type="xs:string" minOccurs="0" />
<xs:element name="Size" type="xs:long" minOccurs="0" />
<xs:element name="RelateId" type="xs:string" minOccurs="0" />
<xs:element name="Code" type="xs:string" minOccurs="0" />
<xs:element name="Version" type="xs:string" minOccurs="0" />
<xs:element name="CreateTime" type="xs:dateTime" minOccurs="0" />
<xs:element name="IsDeleted" type="xs:boolean" minOccurs="0" />
<xs:element name="DeleteTime" type="xs:dateTime" minOccurs="0" />
<xs:element name="DeleteReason" type="xs:string" minOccurs="0" />
<xs:element name="Src" type="xs:string" minOccurs="0" />
<xs:element name="OnSrc" type="xs:boolean" minOccurs="0" />
<xs:element name="OnMaster" type="xs:boolean" minOccurs="0" />
<xs:element name="ServerName" type="xs:string" minOccurs="0" />
<xs:element name="FileLocation" type="xs:string" minOccurs="0" />
<xs:element name="Guid" type="xs:string" minOccurs="0" />
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:choice>
</xs:complexType>
</xs:element>
</xs:schema>
比如 Id Name --------------------编程问答-------------------- 好像是先读到那个节点,然后获得节点里面的属性或者文本。 --------------------编程问答-------------------- public string GetNodeName(string MsgName)
{
XmlNode xn = FormNode.SelectSingleNode(MsgName);
try
{
return xn.Attributes[Language].Value;
}
catch (Exception ex)
{
return "";
}
} --------------------编程问答-------------------- 参考这个:http://www.cnblogs.com/linlf03/archive/2011/11/30/2268705.html --------------------编程问答-------------------- 你这是个还命名空间的,得用xpath,写个吧
XmlDocument xml = new XmlDocument();
xml.Load("test.xml");
XmlNamespaceManager xnm = new XmlNamespaceManager(xml.NameTable);
xnm.AddNamespace("xs", "http://www.w3.org/2001/XMLSchema");
string xpath = "//xs:sequence/xs:element";
XmlNodeList nodes = xml.SelectNodes(xpath, xnm);
foreach (XmlNode item in nodes)
{
string title = item.Attributes["name"].InnerText;
string type = item.Attributes["type"].InnerText;
listBox1.Items.Add(title+" "+type);
}
补充:.NET技术 , C#