简体   繁体   English

如何解析此XML中的信息?

[英]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.

相关问题 在 XML/XSD 模式文件中,我们如何从元素中提取(解析)某些信息? - In an XML/XSD schema file, how can we extract (parse) certain information from an element? 如何从XML文件解析CCD文档 - How can I parse CCD document from XML file 如何使用XmlSerializer属性解析此XML? - How can I parse this XML with XmlSerializer attributes? 如何解析Axis XML文件? - How can I parse an Axis XML file? 如何解析该XML并正确映射? - How can I parse this XML and map it properly? 如何从C#ASP.NET中的JSON字符串中仅解析纬度和经度信息? - How can I parse just the latitude and longitude information from a JSON string in C# ASP.NET? 如何使用组合框从xml文件中获取所需信息到列表框? - How can I fetch from xml file the wanted information to listbox using combobox? 如何防止DateTime与文化信息一起在XML中序列化? - How can I prevent a DateTime from getting serialized in XML with culture information? 如何从XML文件读取信息并将其设置为类中的属性? - How can I read information from an XML file and set them to attributes in a class? 如何从xml文件中仅逐行读取带有xml文件中日期和时间解析的文本? - How can i read from xml file only the text line by line with date and time parse from the xml file?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM