Question

After a Digest authentication:

var resultText = Digester.GrabResponse("/blabla");

I have this in the var resulText:

<?xml version="1.0" encoding="utf-8"?>
<response>
 <HELLO>
  <time>08:10</time>
  <date>11.08.09</date>
  <temp>35.5</temp>
  <humi>37.7</humi>
 </HELLO>
</response>

I tried to fetch the value of the date with XDocument but it didn't work.

Était-ce utile?

La solution

This is really simple: -

XDocument xml = XDocument.Parse(resultText.ToString());

var date = (from n in xml.Descendants("HELLO")
            select n.Element("date").Value).SingleOrDefault().ToString();

You need to use the XDocument.Parse method. Looks like you're passing an XML string as a URI to the Load method which obviously wont work.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top