0

I am trying to use XDocument.Parse(string s) to parse some XML that is being returned from a REST based API. After the XML is parsed, it creates a new XDocument, but the document doesn't contain the properly parsed XML nodes. The name of the first node is the correct node name, but the value is the the concatenation of all the text from the XML, regardless of which Element is belongs to. Can anybody help me figure out what is going on?

XML

<sci_reply version="1.0">
  <send_message>
    <device id="00000000-00000000-00000000-00000000">
      <error id="303">
        <desc>Invalid target. Device not found.</desc>
      </error>
    </device>
    <error>Invalid SCI request. No valid targets found.</error>
  </send_message>
</sci_reply>

Debug View of XDocument Object enter image description here

1
  • Wait, so what's wrong with it? The debugger is just displaying the string that you would get if you called ToString() on the object. There's nothing wrong with it, if there was, an exception would have been raised when it was parsed. Commented Jun 6, 2011 at 1:59

2 Answers 2

2

That's the expected behavior. The Value of a an XML element is concatenation of values of all its children. If you want to actually access the XML, read something about LINQ to XML or classes in the System.Xml.Linq namespace.

Sign up to request clarification or add additional context in comments.

Comments

0

Thats just the debugger being nice.

The root is being displayed with all of its children.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.