SOAP Webservices & parsing XML & JSON
- November 10, 2021
- 3 replies
- 3469 views
Sometimes you have to work with XML in Thingworx, e.g. when processing the result of a SOAP Webservice call.
This can be done using E4X, but it's not comfortable to use, especially when there are namespaces involved.
Therefore, I took a publicly available (GPLed) script which converts the whole reply to JSON and adapted it to Thingworx. It creates an object from the XML and returns the JSON.stringify representation of it. You can take it and extend it to your needs. If you know what you need from the reply and E4X, using E4X directly is probably faster, as it does need the intermediate object and JSON creation, but this is much more convenient (you can work with either the object or the JSON).
Beware this only works with valid XML, so an error message returned from a failed WS call, which could be HTML will not be parsed.
The thing was exported from TWX 9.2 but should work with older versions as well.

