473,386 Members | 1,815 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Getting XML correctly from .net webbrowser object

!NoItAll
297 100+
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:

Expand|Select|Wrap|Line Numbers
  1.         Dim sXML As String
  2.  
  3.         With WebBrowser1
  4.             .Navigate("http://www.redactive.com/wxc/Race1.xml")
  5.             Do Until .ReadyState = WebBrowserReadyState.Complete
  6.                 Application.DoEvents()
  7.             Loop
  8.             If .DocumentType = "XML Document" Then
  9.                 sXML = .Document.Body.OuterText
  10.                 sXML = .Document.Body.InnerText
  11.             Else
  12.                 MsgBox("Document is not XML", MsgBoxStyle.OkOnly Or MsgBoxStyle.Information)
  13.             End If
  14.  
  15.  
  16.         End With
  17.  
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.
Oct 22 '08 #1
2 7540
jg007
283 100+
try this -

Expand|Select|Wrap|Line Numbers
  1.  
  2. Imports System.Xml
  3. Imports System.Net
  4.  
  5.  
  6. Public Class Form1
  7.  
  8.  
  9.     Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
  10.         Dim client As New webclient
  11.         Dim xmlfeed As String = client.DownloadString("http://www.redactive.com/wxc/Race1.xml")
  12.  
  13.         Dim doc As New XmlDocument
  14.         doc.LoadXml(xmlfeed)
  15.         doc.Save("c:\test.xml")
  16.  
  17.     End Sub
  18.  
  19.  
  20. End Class
  21.  
  22.  
this just saves the XML to a file but you can loop through it for information if you need to instead of saving it
Oct 22 '08 #2
!NoItAll
297 100+
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!
Oct 23 '08 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

5
by: Noozer | last post by:
I've got a WebBrowser control (AxBrowse - VCMAXB.DLL) and I'm having a few difficulties with it. Just looking for a few pointers, not whole solutions here. I've tried looking at the MSDN help files...
5
by: Randy | last post by:
Hi, in C# I'm able to access a webbrowser control with the following code and print out all "tags": IHTMLDocument2 HTMLDocument = (IHTMLDocument2)browser.Document; IHTMLElementCollection...
0
by: Sharon | last post by:
Hi all. I'm using the WebBrowser class and sometimes i get this exception: System.Windows.Forms.IWebBrowser2.Navigate2(Object& URL, Object& flags, Object& targetFrameName, Object& postData,...
1
by: UJ | last post by:
How can I get rid of the scroll bars when I use a WebBrowser control? If the page/object I'm trying to display is to big - tough! I don't want the scroll bars. Thanks. Jeff.
1
by: L. Chernov | last post by:
Hello, I am trying to work with .Net 2005 WebBrowser object, and put it on a "Windows control library" (embedded in a user control class) and then I am executing it from an ASP.Net webform(with...
5
by: mabond | last post by:
Hi recently read a posting and reply about Excel processs still running after the Appliction.Quit was called. Thought I might be able to use the same...
18
by: Zytan | last post by:
I have multiple threads writing to WebBrowser (using a function that checks InvokedRequired, and if so, invokes itself on the WebBrowser thread) and they are getting deadlocked. They only...
7
by: - Electronic.HR - | last post by:
I have very strange and stupid problem with .NEt's webBrowser control... If I do this: ---------------------------------- private void btnGoogle_click(object sender, EventArgs e) { ...
11
by: kimiraikkonen | last post by:
Hi there, I needed to use MouseOver event on Webbrowser which is NOT provided by webbrowser control natively(what a disappointment), so i decided to go with another route to simulate this like: ...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.