[英]How can I parse the information from this XML?
this is an example of the XML I want to scrape: 这是我想要抓取的XML的一个例子:
http://www.dreamincode.net/forums/xml.php?showuser=335389 http://www.dreamincode.net/forums/xml.php?showuser=335389
Notice that the contactinformation tag has many contact elements, each similar but with different values. 请注意,contactinformation标签有许多接触元素,每个接触元素相似但具有不同的值。
For example, the element that has the AIM content in it, how can I get the content of the Value tag that's in the same family as the AIM content element? 例如,其中包含AIM内容的元素,如何获取与AIM内容元素位于同一系列的Value标记的内容?
That's where I'm stuck. 那就是我被困住的地方。 Thanks!
谢谢!
Basically: I need to find the AIM content tag, make a note of where it is, and find the Value element within that same family. 基本上:我需要找到AIM内容标记,记下它的位置,并在同一个系列中找到Value元素。 Hope this makes the question clearer
希望这会使问题更加清晰
LINQToXML LINQToXML
var doc = XDocument.Load(@"http://www.dreamincode.net/forums/xml.php?showuser=335389");
var aimElements = doc.Descendants("contact").Where(a=>a.Element("title").Value == "AIM").Select(a=>a.Element("value").Value);
this will give you a list of strings that hold the value of the value element for a contact that has the title AIM, you can do a First() or a FirstOrDefault if you believe there should only be 1 这将为您提供一个字符串列表,其中包含具有标题AIM的联系人的value元素的值,如果您认为应该只有1,则可以执行First()或FirstOrDefault
使用类似下面的xpath将获得联系人/标题,其中联系人/标题是“AIM”:
/ipb/profile/contactinformation/contact[title='AIM']/value
您是否尝试过解析XML而不是“刮”它?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.