Answer the question
In order to leave comments, you need to log in
How, in an XML document, using the .NET framework, to get data from the text node of some element that has a certain attribute?
Hello.
There is some XLM code:
<ROOT>
<data>
<record>
<field name="Country or Area">Australia</field>
<field name="Year">2012</field>
<field name="Value">0.411643502534169</field>
<field name="Value Footnotes"></field>
</record>
<record>
<field name="Country or Area">Russia</field>
<field name="Year">2011</field>
<field name="Value">0.427343851420981</field>
<field name="Value Footnotes"></field>
</record>
<record>
<field name="Country or Area">Spain</field>
<field name="Year">2010</field>
<field name="Value">0.438586168922878</field>
<field name="Value Footnotes"></field>
</record>
</data>
</ROOT>
Answer the question
In order to leave comments, you need to log in
Here is an example in C #, I think I can rewrite it in VB without any problems. For the purpose of searching for anything in XML, there is XPATH.
using System;
using System.Linq;
using System.Xml.Linq;
using System.Xml.XPath;
public class Program
{
public static void Main()
{
var xml = XDocument.Load("test.xml");
xml.XPathSelectElements("//field[@name='Country or Area']").ToList().ForEach(n =>
Console.WriteLine(n.Value)
);
}
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question