cgchris99 Posted October 14, 2003 Posted October 14, 2003 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 Quote
vsnt Posted October 20, 2003 Posted October 20, 2003 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. Quote
cgchris99 Posted October 20, 2003 Author Posted October 20, 2003 what EX? I don't 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. Quote
vsnt Posted October 20, 2003 Posted October 20, 2003 EX = Exception ala Error Number: 21 Description: Something went wrong Quote
Leaders dynamic_sysop Posted October 20, 2003 Leaders Posted October 20, 2003 why not load straight from the browser's location, eg: 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. Quote
cgchris99 Posted October 21, 2003 Author Posted October 21, 2003 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. Quote
*Experts* Nerseus Posted October 21, 2003 *Experts* Posted October 21, 2003 It's 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 Quote "I want to stand as close to the edge as I can without going over. Out on the edge you see all the kinds of things you can't see from the center." - Kurt Vonnegut
cgchris99 Posted October 21, 2003 Author Posted October 21, 2003 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. Quote
*Experts* Nerseus Posted October 21, 2003 *Experts* Posted October 21, 2003 I'd 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 can't duplicate that in just a URL. I'd "look at" the string in OuterHTML and possibly save it to a file for testing. I'd bet a dollar that the XML just isn't valid. If there are any HTML tags along with the actual XML data, they're 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 that's not valid in HTML :) Also, many elements don't 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 Quote "I want to stand as close to the edge as I can without going over. Out on the edge you see all the kinds of things you can't see from the center." - Kurt Vonnegut
cgchris99 Posted October 21, 2003 Author Posted October 21, 2003 What I don't 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> </SPAN> <SPAN<SPAN class=m><?</SPAN><SPAN class=pi>xml version="1.0" encoding="ISO-8859-1" </SPAN><SPAN class=m>?></SPAN> </DIV> etc etc. Now I don't 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 Quote
vsnt Posted October 22, 2003 Posted October 22, 2003 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. Quote
cgchris99 Posted October 22, 2003 Author Posted October 22, 2003 Do you know how to get around this problem? Thx Quote
Administrators PlausiblyDamp Posted October 22, 2003 Administrators Posted October 22, 2003 Does the document reference any external files (XSLT for example)? Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
cgchris99 Posted October 22, 2003 Author Posted October 22, 2003 While viewing the source to the webpage, I can't find any reference to an xslt file at all. I even checked the previous page that has the selection criteria on it. Quote
vsnt Posted October 22, 2003 Posted October 22, 2003 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. Quote
Recommended Posts