Getting XML correctly from .net webbrowser object

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • !NoItAll
    Contributor
    • May 2006
    • 297

    Getting XML correctly from .net webbrowser object

    I am loading an xml document into a vb.net webbrowser object. I can not figure out how to get the xml out of it though. Basically I am going to a URL that has an xml document. It loads just fine - but now I need to write the xml to a file.
    Here's my code:

    Code:
            Dim sXML As String
    
            With WebBrowser1
                .Navigate("http://www.redactive.com/wxc/Race1.xml")
                Do Until .ReadyState = WebBrowserReadyState.Complete
                    Application.DoEvents()
                Loop
                If .DocumentType = "XML Document" Then
                    sXML = .Document.Body.OuterText
                    sXML = .Document.Body.InnerText
                Else
                    MsgBox("Document is not XML", MsgBoxStyle.OkOnly Or MsgBoxStyle.Information)
                End If
    
    
            End With
    Notice that I try to assign OuterText and then InnerText to sXML. This was just so I could see what they contain. They contain the XML - but exactly what is displayed - including the silly little "-" or "+" to expand and contract the XML nodes - which makes the text basically malformed XML. I can remove these with sXML = sXML.Replace("-", " "), but that seems like it's not really the right thing to do. Since the DocumentType actually returns "XML Document" I assume there is a proper way to get XML out of the WebBrowser object. For the life of me though - I just can't find it!
    By the way - you can run this code - the xml document for the test is at the specified URL.
  • jg007
    Contributor
    • Mar 2008
    • 283

    #2
    try this -

    Code:
    Imports System.Xml
    Imports System.Net
    
    
    Public Class Form1
    
    
        Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
            Dim client As New webclient
            Dim xmlfeed As String = client.DownloadString("http://www.redactive.com/wxc/Race1.xml")
    
            Dim doc As New XmlDocument
            doc.LoadXml(xmlfeed)
            doc.Save("c:\test.xml")
    
        End Sub
    
        
    End Class
    this just saves the XML to a file but you can loop through it for information if you need to instead of saving it

    Comment

    • !NoItAll
      Contributor
      • May 2006
      • 297

      #3
      Yup - that's a much much better way to do it. Though it doesn't reveal in a control I really didn't need that. Thanks for pointing me in the right direction - I could have (already had) wasted a lot of time working on this. Handling it nativly like an XML document keeps it canonical!

      Comment

      Working...