0

I have this XML and i try to read the scpefic nodes but not work =(

the my code is:

XmlDocument doc = new XmlDocument();

            doc.Load("https://apps.db.ripe.net/whois/search.xml?query-string=193.200.150.125&source=ripe");

            XmlNode node = doc.SelectSingleNode("/whois-resources/objects/attributes/descr");

            MessageBox.Show(node.InnerText);

enter image description herethe two circled values on image

Url: https://apps.db.ripe.net/whois/search.xml?query-string=193.200.150.125&source=ripe

it is possible?

4

2 回答 2

1

当您正在寻找属性“名称”设置为特定值的节点时,您需要使用不同的语法。

您正在寻找类似的东西:

XmlNode node = doc.SelectSingleNode("/whois-resources/objects/object/attributes/attribute[@name=\"descr\"]");

XmlAttribute attrib = node.Attributes["value"];

MessageBox.Show(attrib.Value);

这将选择您的第二个节点示例,获取 value 属性的值并显示它。

于 2013-07-27T23:28:33.817 回答
1

使用 Linq To Xml 怎么样?

var xDoc = XDocument.Load("https://apps.db.ripe.net/whois/search.xml?query-string=193.200.150.125&source=ripe");
var desc = xDoc.Descendants("attribute")
            .Where(a => (string)a.Attribute("name") == "descr")
            .Select(a => a.Attribute("value").Value)
            .ToList();

或者

var desc = xDoc.XPathSelectElements("//attribute[@name='descr']")
            .Select(a => a.Attribute("value").Value)
            .ToList();
于 2013-07-27T23:43:35.237 回答