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.
The built-in linter in ThingWorx will complain about E4X syntax, but it still works.
I learned how to get to the data I wanted and loop through to create an InfoTable. Hopefully this is what you want to do as well.
Selecting an Element and Iterating
My data came inside of a SOAP envelope, which was meaningless information to me. I wanted to get down a few layers. Here’s a sample of my data that has made-up information in place of the customer's original data:
resultXML is a variable in the service that contains the XML data.
I skipped the Envelope tag since that’s the root.
The .* syntax does not mean “all the following”, it means “all namespaces”. You can define and specify the namespaces instead of using .*, but I didn’t find value in that. I found some sample code that theoretically should work on a VMware forum: https://communities.vmware.com/thread/592000.
This gives me schRow as an XML List that I can iterate through. You can see what you have at this point by converting the data to a String and outputting it:
varresult = String(data);
Now that I am to the schRow data, I can use a for loop to add to an InfoTable: