Jump to content
Sign in to follow this  

XML String Parsing

Recommended Posts


Hey guys, perhaps you can help me with a small issue I'm having.

My goal is to use wininet.dll to submit POST variables to a webpage and download the contents of an XML file in return.

I can successfully submit my variables and I have my XML returned in string form. I would like to keep this in string form, inside the AutoIT script, but I have not found any methods that can directly parse a string, they can only parse files.

So, with a file temporarily created, using AutoIT's FileWrite() function, I am using the XMLDomWrapper script found elsewhere in the forums to parse the XML file.

However, for whatever reason, the string have is not correctly formatted. It looks exactly as I want it to:

<?xml version="1.0"?><output><msg>Hello World!</msg></output>

But, when i pass it to the XML parser, the _GetFirstValue function fails to parse the string, returning 0.

If I manually type in the contents of the file (vs downloading it from the internet), it works perfectly.

Do you all have any suggestions as to why the string I am getting from my webpage looks okay, but for whatever reason will not work when run through the XML parser?

If you know of a way that I can directly parse my string, without having to save a file, that would be the best solution for me.

You assistance is much appreciated. Thank you! :mellow:

Share this post

Link to post
Share on other sites

You might want to look at _StringInsert(), StringReplace(), and StringRegExpReplace(). I have used all of them to edit strings in my scripts. (I have never used the XMLDomWrapper, so I don't know if these directly apply.)

Share this post

Link to post
Share on other sites

There is an undocumented function in the XML Dom Wrapper called _XMLLoadXML. See if that works for you.

Share this post

Link to post
Share on other sites

That would be perfect, but I'm still having issues.

If I pass a hand-typed string, it works perfectly. But, if I pass the output from the web page, it crashes the function call with the attached error message.

So you all can see what I'm doing, here's the relevant code:

#include <guiconstants.au3>
#include "WinINet.au3"
#Include <_XMLDomWrapper.au3>

HotKeySet("{ESC}", "Terminate")

$internet = _WinINet_InternetOpen("Mozilla")
If $internet == 0 Then
    MsgBox(0, "Error", "Setup Error")

$internetconnect = _WinINet_InternetConnect($internet, $INTERNET_SERVICE_HTTP, "mydomain.com", "80")

If @error Then MsgBox(0, "Error", "Error connecting to the internet.")

$data = "field=value"&@CRLF
$type = "Content-Type: application/x-www-form-urlencoded"&@CRLF
$agent = "User-Agent: Mozilla/4.0"&@CRLF

$newdata = $agent & $type

$httprequest = _WinINet_HttpOpenRequest($internetconnect, "POST", "/getxml.php")
$addheader = _WinINet_HttpAddRequestHeaders($httprequest, $newdata, $HTTP_ADDREQ_FLAG_ADD)
ConsoleWrite($addheader & @CRLF)

$sendrequest = _WinINet_HttpSendRequest($httprequest,Default,StringToBinary($data))
local $readfile = Binary("")
$readfile &= _WinINet_InternetReadFile($httprequest, 5000)
Until @error<>0 Or Not @extended

ConsoleWrite("XMLLoadXML: "&$loadedXML&@CRLF)




Share this post

Link to post
Share on other sites

It might have to do with the encoding of the returned data. Maybe you can specify a content type for xml in the return request?

"Content-Type", "text/xml"

Share this post

Link to post
Share on other sites

Yep, already delivered as text/xml. Even tried text/plain. I've checked the source in browsers, and it looks perfect. x-(

Must be something else wrong with it...


*facepalm* :)

Yeah... I forgot to convert it back from binary... whoops... :mellow:

Thanks for the help with the rest of it guys! :(

Edited by HopkinsProg

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this  


Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.