如何解析此 XML 中的信息?
这是我想要抓取的 XML 示例:
http://www.dreamincode .net/forums/xml.php?showuser=335389
请注意,contactinformation 标记有许多 contact 元素,每个元素相似但具有不同的值。
例如,其中包含 AIM 内容的元素,如何获取与 AIM 内容元素属于同一族的 Value 标签的内容?
这就是我被困住的地方。谢谢!
基本上:我需要找到 AIM 内容标签,记下它的位置,并找到同一系列中的 Value 元素。希望这能让问题更清楚
this is an example of the XML I want to scrape:
http://www.dreamincode.net/forums/xml.php?showuser=335389
Notice that the contactinformation tag has many contact elements, each similar but with different values.
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?
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. Hope this makes the question clearer
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
LINQToXML
这将为您提供一个字符串列表,其中保存标题为 AIM 的联系人的值元素的值,如果您认为应该只有 1,则可以执行 First() 或 FirstOrDefault
LINQToXML
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
使用如下所示的 xpath 将为您提供联系人/值节点,其中联系人/标题为“AIM”:
Using an xpath like the one below will get you the contact/value node where contact/title is "AIM":
您是否尝试过解析 XML 而不是“抓取”它?
Have you tried to parse the XML rather than "scraping" it?