GregB
GregB

Reputation: 5725

Why doesn't XDocument.Parse() parse my XML properly?

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

Upvotes: 0

Views: 662

Answers (2)

svick
svick

Reputation: 244767

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.

Upvotes: 2

Richard Schneider
Richard Schneider

Reputation: 35477

Thats just the debugger being nice.

The root is being displayed with all of its children.

Upvotes: 0

Related Questions