how to parse xml Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
jaccotjuhhh
Posts: 27
Joined: 16 Mar 2018, 08:45

how to parse xml

Post by jaccotjuhhh » 03 Feb 2024, 10:17

so basically, "msgbox ontvangst" works like a charm. but everything after that, just doesnt do what it needs to do.
i cant get fileappend to create the XML file. and i cant get my 2nd comobj to parse the xml as well.

my objective is to eventually have all the values exported to CSV (my work soap request contains a response with hundreds of values)

Code: Select all

xml =
(
<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
  <soap:Body>
    <NumberToWords xmlns="http://www.dataaccess.com/webservicesserver/">
      <ubiNum>500</ubiNum>
    </NumberToWords>
  </soap:Body>
</soap:Envelope>
)



SendRequest(xml)
{
	WebRequest := ComObjCreate("WinHttp.WinHttpRequest.5.1")
	WebRequest.Open("POST", "https://www.dataaccess.com/webservicesserver/NumberConversion.wso")
	WebRequest.SetRequestHeader("Content-Type", "application/soap+xml; charset=utf-8")
	WebRequest.SetRequestHeader("Host", "www.dataaccess.com")

	try
		WebRequest.Send(xml)
	catch
		return

	Ontvangst := WebRequest.ResponseText

	Msgbox, Ontvangst

	FileAppend, Ontvangst, "C:\Users\admin\Desktop\test.xml"

;~ xmlPath := "C:\Users\admin\Desktop\test.xml"
xmlp := ComObjCreate("MSXML2.DOMDocument.6.0")
xmlp.async := false
xmlp.load(Ontvangst)

for n2w in xmlp.getElementsByTagName("soap:Body") {
    Text := ""
    Text .= n2w.getElementsByTagName("m:NumberToWordsResult").item(0).text
    ;~ Text .= n2w.getElementsByTagName("m:2").item(0).text
    ;~ Text .= n2w.getElementsByTagName("m:3").item(0).text
    MsgBox % Text
}

}

F1::SendRequest(xml)
^r::reload

[Mod action: Topic moved from "Ask for Help (v2)" since this is v1 code. Please post in the correct section going forward.]

User avatar
lmstearn
Posts: 698
Joined: 11 Aug 2016, 02:32
Contact:

Re: how to parse xml  Topic is solved

Post by lmstearn » 03 Feb 2024, 22:36

Hi, does this help?

Code: Select all

xml =
(
<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
  <soap:Body>
    <NumberToWords xmlns="http://www.dataaccess.com/webservicesserver/">
      <ubiNum>500</ubiNum>
    </NumberToWords>
  </soap:Body>
</soap:Envelope>
)



SendRequest(xml)
{
	WebRequest := ComObjCreate("WinHttp.WinHttpRequest.5.1")
	WebRequest.Open("POST", "https://www.dataaccess.com/webservicesserver/NumberConversion.wso")
	WebRequest.SetRequestHeader("Content-Type", "application/soap+xml; charset=utf-8")
	WebRequest.SetRequestHeader("Host", "www.dataaccess.com")

	try
		WebRequest.Send(xml)
	catch
		return

	Ontvangst := WebRequest.ResponseText

	Msgbox, Ontvangst
	Ontvangst_FileName := % A_Desktop . "\test.xml"
	FileAppend, %Ontvangst%, %Ontvangst_FileName%

;~ xmlPath := "C:\Users\admin\Desktop\test.xml"
xmlp := ComObjCreate("MSXML2.DOMDocument.6.0")
xmlp.async := false
if (xmlp.load(Ontvangst_FileName)) {

	for n2w in xmlp.getElementsByTagName("soap:Body") {
		Text := ""
		Text .= n2w.getElementsByTagName("m:NumberToWordsResult").item(0).text
		;~ Text .= n2w.getElementsByTagName("m:2").item(0).text
		;~ Text .= n2w.getElementsByTagName("m:3").item(0).text
		MsgBox % Text
	}
	}
	else
	msgbox Load Failed


}

F1::SendRequest(xml)
Esc::ExitApp
^r::reload
:arrow: itros "ylbbub eht tuO kaerB" a ni kcuts m'I pleH

Post Reply

Return to “Ask for Help (v1)”