doc.loadxml(axwebbrowser1.document.body.outerhtml), doesn't work?

cgchris99

Member
Joined
Sep 29, 2003
Messages
14
I am automating the navigation of a website.

When I reach the end, it changes to xml.

So my axwebbrowser1 has a bunch of xml data in it.

So here is what I am trying to do

Dim xmlText As String
Dim doc As New XmlDocument()
Dim myElem As XmlElement
xmlText = AxWebBrowser1.Document.Body.OuterHTML
doc.LoadXml(xmlText)

But the problem is I get an exception error at the doc.loadxml(xmltext)
I found a streamreader example but I already have the xml data in the axwebbrowser control.
How do I get it so I can parse through the nodes?

Thanks for any information
 
What EX are you getting. I think the problem is that you are trying to load an object or string as a stream.
ala :: Doc.LoadXml(This_Should_Be_A_Stream)
Im not 100% sure though, but double check for invalid type casting and make sure option Strict is on.
 
what EX? I dont know what you mean here.

I am trying to take the data that is displayed in the AXwebbrowser control and get the xml information from it.

I am using the webbrowser control because I have to step through the website to get to the correct page. There is NO url that gets to the right pages because it is an ASP based website.

thanks for any additional help on this, I really need it.
 
why not load straight from the browsers location, eg:
Code:
        Dim xmldoc As New Xml.XmlDocument()
        xmldoc.Load(AxWebBrowser1.LocationURL)
        MessageBox.Show(xmldoc.ChildNodes.Count) /// test to see if it has loaded / has any nodes.
 
I tried the code you gave. and Received and exception error.

An unhandled exception of type System.Xml.XmlException occurred in system.xml.dll
Additional information: System Error.

The error occurs on the xmldoc.load line
Any other ideas?

Thanks so much for trying to help me with this.
 
Its probably not valid XML (missing closing tags, invalid attributes, etc.). If you use Try and Catch(e as XmlException) you should be able to view e.Message to get the exact error, line number, and position.

By the way, LoadXml loads a string, Load loads a stream from a string (a filename, url, etc.). There was confusion earlier, I think.

-Nerseus
 
Ok, capturing the error shows invalid data.
BUT...

If the loadxml(axwebbrowser1.locationURL) refreshes then, it will not have valid data in it.

What I mean is this. The axwebbrowser is navigating an ASP based website. I only get to the correct page my clicking on a special submit button. This is done automatically by the program of course.

But if you manually type in the URL that is displayed it will come up with the form that you have to press the submit button. Not the one with the correct xml data.

I have the correct data displayed in the axwebbrowser control. And it is only showing the xml data. But how can I get this into the xmldoc?

I hope I explained this ok. If not please respond.
 
Id go back to your original idea of using the OuterHTML and using the LoadXml method. The problem with navigating directly is that the page is expecting a form to be submitted. You cant duplicate that in just a URL.

Id "look at" the string in OuterHTML and possibly save it to a file for testing. Id bet a dollar that the XML just isnt valid. If there are any HTML tags along with the actual XML data, theyre probably not meeting the strict requirements for XML. For example, in HTML you can have "<td nowrap>". In XML all attributes must have a value, as in "<td nowrap="true">", but thats not valid in HTML :) Also, many elements dont require a closing tag, such as "<p>" and "<br>" but XML does require them. Those you can mostly fix by changing them to "<br/> or somesuch (I think).

You may have to extract out the XML from the OuterHTML string, some simple string manipulation might do it, based on what the HTML looks like.

If you want help, show us the value of OuterHTML so we can take a peek.

-Ner
 
What I dont understand is why when I view source in IE6 all I see is the perfect xml code. But when I view the outerhtml in VB.net it has so much extra code.

Here is what I get by xmltext=axwebbrowser1.document.body.outhtml

xmltext=
"<body clas=st><DIV class=e><SPAN class=b>&nbsp;</SPAN> <SPAN<SPAN class=m>&lt;?</SPAN><SPAN class=pi>xml version="1.0" encoding="ISO-8859-1" </SPAN><SPAN class=m>?&gt;</SPAN> </DIV> etc etc.

Now I dont see any of the xml tags like <ShipmentForecasts>xyz</ShipmentForecasts>

But it displays the xml perfectly in the axwebbrowser control.

Thanks for any additional advice
 
I Seee the problem. Since you are using document.body you are gettting html formatting tags for the body of the page as its being rendered by IExplorer.
 
While viewing the source to the webpage, I cant find any reference to an xslt file at all. I even checked the previous page that has the selection criteria on it.
 
I believe a better solution is to use the httprequest object and return the page in question into the fileStream / Temp File. Yes you can send the required post data with this method.
 
Back
Top