Read XML Data From Web

Visual Basic:
'create a stream reader give it the path of your xml file as a parameter
Dim streader As New StreamReader(XmlFilePath)
'read the content of the file into a string
Dim FileContent As String = streader.ReadToEnd
'close the stream reader
streader.Close()

'Now you have your file in a string
'we will parse it through XMLReader Class
'create a nametable
Dim nt As NameTable = New NameTable()
Dim nsmgr As XmlNamespaceManager = New XmlNamespaceManager(nt)
        nsmgr.AddNamespace("bk", "urn:sample")
 'Create the XmlParserContext
 Dim context As XmlParserContext = New XmlParserContext(Nothing, nsmgr, Nothing, XmlSpace.None)
 'Create the reader, giving it the string and the context
  Dim reader As XmlTextReader = New XmlTextReader(FileContent, XmlNodeType.Document, context)

'move to first node
reader.MoveToContent()

'Keep reading until you reach the desired node (in your case) Temp

While reader.Read
            If reader.Name = "Temp" Then
                reader.Read()
                'place the value in a textbox
                txtTemp.Text = reader.Value
                Exit While
            End If
        End While
'close the reader
 reader.Close()

Hope this helps,
 
yeah, also let us know if this can be done if the xml comes from a webservice, I want to do something similar using XSLT and a web service ( I've postedon the ASP.NET thread).
Cheers
 
Pagego,

As i understand you have a windows form, Is this website yours ?

If it is then why dont you create a web service that retireves the value and send it to the client, in this case you would parse the xml file on the web service.
 
Back
Top