<?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>
上面是通过一个webservice调用返回的结果,怎么解析呢? 我想解析实体类```
我用XElement.Descendants("Model")怎么查不出来呢?
7 个解决方案
#1
#2
照解析不误
#3
上msdn,有函数的
#4
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
#5
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);
}
}
帮你解决了,我在控制台输出了一下,你看你想怎么处理吧。。
#6
解析成功,不过不是你的方法,给你分吧 ~呵呵~
#7
和规划规划规划个
#1
#2
照解析不误
#3
上msdn,有函数的
#4
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
#5
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);
}
}
帮你解决了,我在控制台输出了一下,你看你想怎么处理吧。。
#6
解析成功,不过不是你的方法,给你分吧 ~呵呵~
#7
和规划规划规划个