0

Newbie looking for help on getting xml http response in vb.net this is what im looking to do ,getting these attributes values(Red,Green,Yellow,Black) to a 4 different textbox's on vb.net project.any help learning this would be very helpfull. thanks

<system ver="1.0">
<colors>
<type red="Red" green="Green" yellow="Yellow" Black="Black" />
</colors>
</system>

Here is what I have so far,and tried different ways but always ending up erasing it.:(

 Sub GetData()


        Dim request As System.Net.HttpWebRequest = System.Net.HttpWebRequest.Create("target url")
        request.Credentials = New System.Net.NetworkCredential("user", "pass")
        Dim response As System.Net.HttpWebResponse = request.GetResponse()
        If response.StatusCode = System.Net.HttpStatusCode.OK Then

          Dim stream As Stream = response.GetResponseStream()
            ' Create a reader for the stream object
            Dim reader As New StreamReader(stream)
            ' Read from the stream object using the reader, put the contents in a string
            Dim contents As String = reader.ReadToEnd()
            ' Create a new, empty XML document
            Dim HttpResult As New XmlDocument
            Dim UserInfo As XmlNodeList
            Dim Discription As XmlNode
            HttpResult = New XmlDocument
            HttpResult.LoadXml(contents)


            'Create the XML Document
            HttpResult = New XmlDocument()
            Dim _XPath As String =
            UserInfo = HttpResult.SelectNodes("")



            'Get the Gender Attribute Value
            Dim DetailsAttribute = Discription.Attributes.GetNamedItem("").Value
     endif

    End Sub

1 Answer 1

1

Start with this...

Dim MyDoc as New System.Xml.XmlDocument
MyDoc.Load("c:\path\to\your\xml\file")

Dim MyNode as System.Xml.XmlNode = MyDoc.SelectSingleNode("//system/colors/type")

Dim RedAttribute as String = MyNode.Attributes("red").Value
Dim GreenAttribute as String = MyNode.Attributes("green").Value
Dim YellowAttribute as String = MyNode.Attributes("yellow").Value
Dim BlackAttribute as String = MyNode.Attributes("black").Value

I think that should get you where you want to go.

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

1 Comment

well thanks:) that worked fine i had to add myDoc.loadxml cause it added other illegal characters to it without it. only issue now is ,it says it cant convert the red,green.. attributes to a string.any ideas on how to convert it to string? again thanks alot for the help!

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.