Reputation: 1075
i am using C# windows phone 8 and I have the following XML
<?xml version="1.0" encoding="UTF-8" ?>
<login res="SUCCESS" encstatus="DEFAULT" usedquota="0" />
I need to extract the values of res, encstatus and usedQuota.
How do I do that in xml parsing?
I tried this
XDocument xDoc = XDocument.Parse(str);
var pol = xDoc.Element("res");
var items = xDoc.Descendants("res");
Where str is the xml file, but all the elements are empty / null.
Upvotes: 1
Views: 311
Reputation: 236208
Those nodes are attributes:
XDocument xDoc = XDocument.Parse(str)
XElement login = xDoc.Root;
string res = (string)login.Attribute("res");
string encstatus = (string)login.Attribute("encstatus");
int usedquota = (int)login.Attribute("usedquota");
Upvotes: 2
Reputation: 125620
You're trying to get the attribute values, no element:
XDocument xDoc = XDocument.Parse(str);
var pol = (string)xDoc.Root.Attribute("res");
Upvotes: 3