[RESOLVED] Retrieving XML into document
I'm trying to retrieve xml information from an XMLDocument object, but I'm getting an error.
I'm using Visual Studio 2008, I have this XML as a string :
<customerresponse status="valid">
<custid>58485843543</custid>
<message>Submission Accepted</message>
</customerresponse>
This is my code:
Dim XMLResult as new XMLDocument
XMLResult.LoadXML(xmlstring)
status = XMLResult.Item("customerresponse").Attributes("status").Value
message = XMLResult.Item("customerresponse").Item("message").Value
The first line (status) works perfectly to retrieve the attribute, but the second line ( message ) gives me a Null Reference error when trying to get the value in the sub-node.
The Item is supposed to be an XMLElement, which should include its sub-elements, I would think. What am I doing wrong here?
Re: Retrieving XML into document
you might want to try posting this in the VB.NET forum rather than here. this forum is more about XML itself, not working with it via other languages.
Re: Retrieving XML into document
I believe you need to switch ".Value" to ".InnerText" when you try to retrieve "message." From MSDN, regarding the "Value" property:
Quote:
The value returned depends on the NodeType of the node:
Attribute - The value of the attribute.
Element - null. You can use the XmlElement.InnerText or XmlElement.InnerXml properties to access the value of the element node.
Re: Retrieving XML into document
See if InnerText works instead of Value