I can’t seem to find an article with this same problem.
I have an XML file like this:
<user id="" name="" termsofuse="http://boardgamegeek.com/xmlapi/termsofuse">
<firstname value="" />
<lastname value="" />
<avatarlink value="N/A" />
<yearregistered value="" />
<lastlogin value="2012-10-04" />
<stateorprovince value="" />
<country value="" />
<webaddress value="" />
<xboxaccount value="" />
<wiiaccount value="" />
<psnaccount value="" />
<battlenetaccount value="" />
<steamaccount value="" />
<traderating value="363" />
</user>
And I am using the following code to extract the data:
static string QueryTheData(XDocument doc)
{
var data = from item in doc.Descendants("user")
select new
{
avatarlink = item.Element("avatarlink").Value,
lastlogin = item.Element("lastlogin").Value,
};
var t = "";
foreach (var p in data)
t += p.ToString();
return t;
}
But my values returned are null. I’m wondering if it’s because the XML file begins:
<user id="" name="" termsofuse="http://boardgamegeek.com/xmlapi/termsofuse">
Whereas in all the examples I have found the XML begins like this:
<user> ... etc
How can I read these values in this format?
You want to get the value of attribute
value. Try thisBut I would go this way
where every item of the final list contains a dictionary of elements and their values