kala-tamin XDocument parses but isnt searchable from string


XDocument parses but isnt searchable from string



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 doesnt return an error, but I dont seem to have a searchable xDocument.

Can anyone see anything obviously wrong with what I am doing?

Cheers, Al




Mathematica: Determine if all integers in a list are less than a number?

1:



All picks of a list in F# - more elegant and simple
You don't need to create a new XDocument before calling XDocument.Parse.


CSS horizontal menu - equally spaced?
This won't cause any problems, it's just pointless..
Scala best way of turning a Collection into a Map-by-key? (2nd variant)
However, this line is wrong because email is not a child of the document root:.
Which data structure best represents this data?
doc.Element("email").Value; 
Your second example looks fine.


Most elegant combinations of elements in F#
This works for me:.
Can I get all the file extensions of text files in the repository in CVS?
string s = "<?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>"; XDocument doc = XDocument.Parse(s); foreach (XElement e in doc.Descendants("data"))     Console.WriteLine(e); 
Result:.
How to create more than one group in List , SSRS 2005?
<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> 
In response to your second third question (see comments to this answer) try this:.
using System; using System.Xml.XPath; using System.Xml.Linq;  class Program {     public static void Main()     {         string xml = "<?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>";         XDocument doc = XDocument.Parse(xml);         foreach (XElement e in doc.XPathSelectElements("/searchResponse/pso/psoID/data/*"))                 Console.WriteLine(e);     } } 
Output:.
<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> 



77 out of 100 based on 87 user ratings 437 reviews