62,074
社区成员
发帖
与我相关
我的任务
分享
<?xml version="1.0" encoding="utf-8" ?>
<ArrayOfModel xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://tempuri.org/">
<Model>
<Name>Liu</Name>
<Numer>13211235578</Numer>
</Model>
<Model>
<Name>Yan</Name>
<Numer>13211235578</Numer>
</Model>
<Model>
<Name>Tony</Name>
<Numer>13211235578</Numer>
</Model>
<Model>
<Name>Jaz</Name>
<Numer>13211235578</Numer>
</Model>
</ArrayOfModel>
XmlDocument doc = new XmlDocument();
doc.Load(@"e:\model.xml");
XmlNamespaceManager nsmgr = new XmlNamespaceManager(doc.NameTable);
nsmgr.AddNamespace("Name", doc.DocumentElement.NamespaceURI);
XmlNodeList nodeList;
XmlElement root = doc.DocumentElement;
nodeList = root.SelectSingleNode("//Name:ArrayOfModel", nsmgr).ChildNodes;
foreach (XmlNode node in nodeList)
{
foreach (XmlNode n in node.ChildNodes)
{
Console.WriteLine(n.InnerText);
}
}
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 and display the value of all the ISBN attributes.
XmlNodeList nodeList;
XmlElement root = doc.DocumentElement;
nodeList = root.SelectNodes("/bookstore/book/@bk:ISBN", nsmgr);
foreach (XmlNode isbn in nodeList){
Console.WriteLine(isbn.Value);
}
}
}
http://msdn.microsoft.com/en-us/library/4bektfx9(v=VS.100).aspx