Recently I needed to be able to parse and handle XML data natively inside of a ThingWorx script, and this XML file happened to have a SOAP namespace as well. I learned a few things along the way that I couldn’t find a lot of documentation on, so am sharing here.
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" headers="">
<SOAP-ENV:Body>
<get_part_schResponse xmlns="urn:schemas-iwaysoftware-com:iwse">
<get_part_schResult>
<get_part_schRow>
<PART_NO>123456</PART_NO>
<ORD_PROC_DIV_CD>E</ORD_PROC_DIV_CD>
<MFG_DIV_CD>E</MFG_DIV_CD>
<SCHED_DT>2020-01-01</SCHED_DT>
</get_part_schRow>
<get_part_schRow>
<PART_NO>789456</PART_NO>
<ORD_PROC_DIV_CD>E</ORD_PROC_DIV_CD>
<MFG_DIV_CD>E</MFG_DIV_CD>
<SCHED_DT>2020-01-01</SCHED_DT>
</get_part_schRow>
</get_part_schResult>
</get_part_schResponse>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
var data = resultXML.*::Body.*::get_part_schResponse.*::get_part_schResult.*;
var result = String(data);
for each (var row in data) {
result.AddRow({
PartNumber: row.*::PART_NO,
OrderProcessingDivCD: row.*::ORD_PROC_DIV_CD,
ManufacturingDivCD: row.*::MFG_DIV_CD,
ScheduledDate: row.*::SCHED_DT
});
}
Very cool. should also add the @ part as well when you have multiple elements within a row.
i,
Does this code still working ?
var data = resultXML.*::Body.*::get_part_schResponse.*::get_part_schResult.*;
If yes, should i add something to make it work ?
I think the example was developed on Thingworx 8.x not sure what version you are using, but it should still be valid.
Yes, it was developed in 8.5.3. As mentioned in the original post, you will get Linting warnings but it does actually work. I have not tested on any newer versions 8.5.3, but the Rhino engine hasn't changed versions, so I would assume it still works.