Skip to main content
1-Visitor
September 13, 2017
Question

How to parse simple XML-response from PostXML/PostText

  • September 13, 2017
  • 2 replies
  • 2853 views

Hi!

I'm trying to post a device serialnumber to remote URL (not Thingworx) with PostXML-function and get a response with some device details (see below).

By using var xmlDocument = Resources["ContentLoaderFunctions"].PostText(params) I get the following response nicely as string:

<?xml version="1.0" encoding="UTF-8"?>

<Devices>

    <Total>0</Total>

  <Device>

    <DeviceData>

      <SerialNumber>A66M38</SerialNumber>

      <DeviceType>10</DeviceType>

    </DeviceData>

    <ItemData Quantity="1" Version="">

      <Description1 Lang="EN">Development engine</Description1>

    </ItemData>

  </Device>

</Devices>

But if I try to do anything with PostXML (e.g. xmlDocument to Infotable) it seems that I do not get any XML data to Thingworx. I wonder, whether PostXML can be used in a case like this to get result as XML object? Am I missing something in PostXML usage?

Quite a simple result so I could even use some sort of light-weight parser inside service? Any hints?

Br,

Pasi

2 replies

22-Sapphire I
September 13, 2017

Should work, if this is what you get back when you do PostText, then your PostXML should be able to get this back as an XML object.

So if you had var myXML = Resources.["ContentLoaderFunctions"].PostXML

Then you should be able to get information from myXML.Devices.Total

1-Visitor
September 14, 2017

PostText delivers the content nicely. PostXML just like you said, but myXML.Devices.Total is empty. Any idea where to start hunting the reason for this behavior? Could it be that content-type is a problem for Thingworx? Using Postman I see that the content-type for response is text/xml; charset=utf-8.

22-Sapphire I
September 14, 2017

Do you have the UTF-8 option configured in the Java opts?

1-Visitor
September 15, 2017

Hi Pasi,

Don't lose time with PostXML, use PostText and then if you want you can try to parse to XML the content you receive with new XML(postTextResult); or alike.

Just my recommendation,

Carles.

1-Visitor
September 15, 2017

Thanks. I will check the encoding issue first and if it does not help, continue with building the case with posttext.