i am trying to read an xml file, the format of the file as follow:
<rootnode>
<a>first<b>1st</b></a>
<a>second<b>2nd</b></a>
</rootnode>
i tried to use XDocument like this:
XDocument loadedData = XDocument.Load("file.xml");
var data = from query in loadedData.Descendants("a")
select new myClass
{
Word = (string)query.Value,
secondWord = (string) query.Element("b")
};
but it didnt work, as the (string)query.Value will bring me the whole line;"first1st"
is there any way to get the text instead of the whole element?
<item><a>first</a><b>1st</b></item>
. If you can do that, your code becomes cleaner, and less likely to break in the event of needing to add a<c>
element later. – ZombieSheep