I'm getting a string returned from a website that looks like this
<?xml version=\"1.0\" encoding=\"UTF-8\"?><searchResponse requestID=\"500\" status=\"success\"><pso><psoID ID=\"61F2C644-F93A-11DE-8015-73A11AB14291\" targetID=\"mezeoAccount\"><data><email>sholobfc@bluefire.com.au</email><quotaMeg>2048</quotaMeg><quotaUsed>1879736</quotaUsed><active>true</active><unlocked>true</unlocked><allowPublic>true</allowPublic><realm>mezeo</realm><bandwidthQuota>1000000000</bandwidthQuota><billingDay>1</billingDay></data></psoID></pso></searchResponse>"
I then try and create an XDocument from it so I can enumerate through the elements
XDocument doc = new XDocument();
doc = XDocument.Parse(respStr);
but if I query the elements or descendants everytime it returns null. I can't go
string s = doc.Element("email").Value;
// or
doc.Descendants("data"); // returns null as well
XDocument.Parse doesn't return an error, but I don't seem to have a searchable xDocument.
Can anyone see anything obviously wrong with what I am doing?
You don't need to create a new XDocument before calling XDocument.Parse. This won't cause any problems, it's just pointless.
However, this line is wrong because email is not a child of the document root:
Your second example looks fine. This works for me:
Result:
In response to your
secondthird question (see comments to this answer) try this:Output: