简体   繁体   中英

Parsing XML from webbrowser control?

I need to parse a XML file (which is generated by PHP) from a webbrowser control as the page I am trying to parse requires cookies to track some things. When I use something like:

string xmlURL = "urltophpfile";    
XmlTextReader reader = null;
reader = new XmlTextReader(xmlUrl);

to parse it, cookies aren't enabled so I need to use a webbrowser control or something which will allow me to use cookies.

The problem I am having is that when I try to put the webbrowser text to a string ( string info = webBrowser2.DocumentText.ToString(); it gives the full source of the web page and therefore I can't parse it.

Does anyone have any suggestions on how I can work this out please?

You should use HttpWebRequest and specify the CookieContainer property.

This URL has a good example of it: http://msdn.microsoft.com/en-us/library/system.net.httpwebrequest.cookiecontainer.aspx

EDIT: To be clear, I mean use HttpWebRequest to fetch the XML, and then load the xml using XmlTextReader.Create with one of the overloads that supports a stream or direct string input.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM