Results 1 to 4 of 4

Thread: [RESOLVED] Retrieving XML into document

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Jun 2005
    Posts
    625

    Resolved [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?

  2. #2
    PowerPoster
    Join Date
    Sep 2003
    Location
    Edmonton, AB, Canada
    Posts
    2,629

    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.

  3. #3
    Frenzied Member
    Join Date
    Apr 2009
    Location
    CA, USA
    Posts
    1,516

    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:
    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.

  4. #4
    PowerPoster
    Join Date
    Jun 2001
    Location
    Trafalgar, IN
    Posts
    4,141

    Re: Retrieving XML into document

    See if InnerText works instead of Value

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width