XMLParse - extracting values within tags

Technical support and scripting issues

Moderators: Dorian (MJT support), JRL

Post Reply
Trevor Hughes
Junior Coder
Posts: 24
Joined: Sun Dec 15, 2013 9:27 pm

XMLParse - extracting values within tags

Post by Trevor Hughes » Fri Aug 12, 2016 4:11 am

Hello

I want to be able to extract some values within the tags of an XML string. I am trying to achieve this by copying the contents of the XML file onto the Clipboard, using GetClipBoard to place the string into a variable and trying to use XMLParse to extract the value TG0508I10-SOV. (<reqresp:CustomerReference>TG0508I10-SOV</reqresp:CustomerReference>)

Unfortunately I have not been able to work out how to do this successfully. If some kind sould could assist, I would greatly appreciate it.

My Macro code is below and the XML string is below that:

Code: Select all

GetClipBoard>XMLString

StringReplace>XMLString,soapenv:,,XMLString
StringReplace>XMLString,reqresp:,,XMLString

Let>tmp0=Envelope/Body/CustomerReference/text()
XMLParse>XMLString,tmp0,CustomerReference,numBooks

msg>%CustomerReference%
XMLString:
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<soapenv:Header>
<wsse:Security xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/ ... xt-1.0.xsd"/>
</soapenv:Header>
<soapenv:Body>
<reqresp:RequestResponseResponse xmlns:reqresp="http://somewhere.co.nz/folder/msggate/reqresp/v1">
<reqresp:CustomerReference>TG0508I10-SOV</reqresp:CustomerReference>
<reqresp:MailboxMsgId>5997</reqresp:MailboxMsgId>
<reqresp:DocumentSize>2130</reqresp:DocumentSize>
<reqresp:ReceivedDate>2016-08-05 16:48:56.269</reqresp:ReceivedDate>
<reqresp:ReqStatus>OK</reqresp:ReqStatus>
<reqresp:AckStatus>OK</reqresp:AckStatus>
</reqresp:RequestResponseResponse>
<mesa:attachment href="cid:attachment=-[email protected]" xmlns:mesa="http://www.sterlingcommerce.com/mesa"/>
</soapenv:Body>
</soapenv:Envelope>

hagchr
Macro Veteran
Posts: 277
Joined: Mon Jul 05, 2010 7:53 am
Location: Stockholm, Sweden

Re: XMLParse - extracting values within tags

Post by hagchr » Sat Aug 13, 2016 10:49 am

Hi, almost there, there is one tag missing so you just need to change to:

Code: Select all

Let>tmp0=Envelope/Body/RequestResponseResponse/CustomerReference/text()

Trevor Hughes
Junior Coder
Posts: 24
Joined: Sun Dec 15, 2013 9:27 pm

Re: XMLParse - extracting values within tags

Post by Trevor Hughes » Sat Aug 13, 2016 11:48 pm

Thank you very much for the help.

Your suggestion worked great. This will be extremeley helpful. I now have a much better understanding of what the code is doing.

Post Reply
Sign up to our newsletter for free automation tips, tricks & discounts