Results 1 to 4 of 4

Thread: How to read an XML Byte?

  1. #1
    trevorjdaniel is offline VB.NET Forum Newbie
    .NET Framework
    .NET 3.5 (VS 2008)
    Join Date
    Sep 2009
    Posts
    8
    Reputation
    0

    How to read an XML Byte?

    Hello,

    I am trying to work out how to read some xml that is being returned from an external URL.

    Firstly, to get the XML response I have to send it some relevant information. I have done this with the following code:

    Code:
    Dim url = "http://XX.XX.XX.XX/test"
            Dim client As New WebClient
    
            client.Headers.Add("Content-Type", "application/xml")
            Dim sentXml As Byte() = System.Text.Encoding.ASCII.GetBytes(xml.OuterXml)
            Dim response As Byte() = client.UploadData(url, "POST", sentXml)
    When I check Fiddler, I can see that well formed XML is being returned and looking at the above code it seems to be stored as a byte in "response"

    But I cannot work out how to now read this XML and returns the values within it.

    Any help would be much appreciated

    Thanks

    Trev

  2. #2
    JohnH's Avatar
    JohnH is offline VB.NET Forum Moderator
    .NET Framework
    .NET 4.0
    Join Date
    Dec 2005
    Location
    Norway
    Posts
    14,200
    Reputation
    2369
    System.Text.Encoding.ASCII.GetString method is the counterpart.

  3. #3
    trevorjdaniel is offline VB.NET Forum Newbie
    .NET Framework
    .NET 3.5 (VS 2008)
    Join Date
    Sep 2009
    Posts
    8
    Reputation
    0
    Brilliant! that worked perfectly. I know have the response as a sting variable using :

    Code:
    Dim trev As String = System.Text.Encoding.ASCII.GetString(response)
    I now need to pull out some values.. for example there is a node in the XML like the following

    <PDSM>1.23</PDSM>

    How would I do that please? Am I correct to have put it in a string?

    Thanks for your help!

    Much appreciated!

    Trev

  4. #4
    JohnH's Avatar
    JohnH is offline VB.NET Forum Moderator
    .NET Framework
    .NET 4.0
    Join Date
    Dec 2005
    Location
    Norway
    Posts
    14,200
    Reputation
    2369
    You can for example load a XDocument or XmlDocument and work with that.

Bookmarks

Posting Permissions

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