图片刮XML时,我有这样的XML:获取错误信息的LINQ
<ipb>
<profile>
<id>335389</id>
<name>stapia.gutierrez</name>
<rating>0</rating>
</profile>
</ipb>
我试图让ID,名称和等级。任何指导?
这里是我有什么,我得到:
public User FindInformation()
{
string xml = new WebClient().DownloadString(String.Format("http://www.dreamincode.net/forums/xml.php?showuser={0}", userID));
XDocument doc = XDocument.Parse(xml);
var id = from u in doc.Descendants("profile")
select (string)u.Element("id");
var name = from u in doc.Descendants("profile")
select (string)u.Element("name");
var rating = from u in doc.Descendants("profile")
select (string)u.Element("rating");
User user = new User();
user.ID = id.ToString();
user.Name = name.ToString();
user.Rating = rating.ToString();
return user;
}
这是我在我的文本框用于测试目的得到。
System.Linq.Enumerable+WhereSelectEnumerableIterator`2[System.Xml.Linq.XElement,System.String] System.Linq.Enumerable+WhereSelectEnumerableIterator`2[System.Xml.Linq.XElement,System.String] System.Linq.Enumerable+WhereSelectEnumerableIterator`2[System.Xml.Linq.XElement,System.String]
谢谢,这正是我所需要的。还没有用过很多XML。 :] – 2010-07-04 19:24:15
别担心我总是这样做。计时器有8分钟才能接受。 – 2010-07-04 19:50:21
系统需要一段时间才能通过aswer标记回答。不要跳枪。 – 2010-07-04 19:50:35