cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 

Community Tip - When posting, your subject should be specific and summarize your question. Here are some additional tips on asking a great question. X

Thingworx treats the XML output from Rest Services as HTML

vranganathan
12-Amethyst

Thingworx treats the XML output from Rest Services as HTML

Hi,

 

I created a RESt Services which sends back the XML content. I tested this using IE and Firefox and renders as XML within the browser.

 

I created a ThingTemplate and implemented a service which invokes this REST service and returns as XML. (My end goal is to parse XML and take the values out and use them in my mashup. I will be using a datashape to accomplish this. I tried that the values were blank and during debuggin I find this issue).

I tested this using my Thing and test service, it is successful. I wanted to see the content I used the URL http://localhost:8080/Thingworx/Things/TestWPAConnection/Services/getSupplierEiccSurveySummary?method=post and displays my XML as text. (meaning it hides all my XML tags and displays only those values). The XML is wrapped around HTML and see the Content type as HTML/TXT.

I am wondering how to render this as XML. Is there any configuration or setting I need to use,

I would appreciate your help.

 

Thanks in advance.

Varathan

4 REPLIES 4
paic
12-Amethyst
(To:vranganathan)

Good to see you already are successful with the call.
A lot of browsers will interpret XML and render it as a regular web page, you can look at the page source to see if it is actual XML vs. Text.

One little tip, to truly check the content that is coming back from a call, I set the output type of my Service to String first, this will show you exactly what you are returning. And since you are looking to parse the content, you don't actually need to have the service return XML, once you have verified the content is read in properly, you can go ahead and create your parsing logic.

vranganathan
12-Amethyst
(To:paic)

Thanks for your tip. When I return my XML (output of as String from Resources["ContentLoaderFunctions"].GetXML(params);), I get "Unable To Convert From com.sun.org.apache.xerces.internal.dom.DocumentImpl to STRING".

I used to GetText and returning that as String shows what I expect.

I added some debug statment and tried to get them as XML and Text. The following are the outputs.

 

// result: XML
var xmlPage = Resources["ContentLoaderFunctions"].GetXML(params);
// result: STRING
var txtPage = Resources["ContentLoaderFunctions"].GetText(params);
logger.debug(xmlPage);
logger.debug(txtPage);

 

xmlPage returns only my top node name.

txtPage returns the entire XML as expected.

If I parse txtPage as XML, I see undefined variable when I assign the values to datashape. In case of XML, it is not going through my for loop as there is no content inside it.

I would appreciate your help.

 

Thanks,

Varathan

 

 

We are also looking for solution where external application needs json as response , where thingworx is returning JSON, XML and Text wrapped up with HTML.

Dear Pai,

Could you please provide any alernative solution to return as JSON. We have tested with Multiple REST clints and results comes back as HTML

ideaally it should be JSON if your return type is JSON..

Thanks,
Prabhas

Got the solution.

Please add a header tag with “Accept”  with value application/json

Testbed with POSTMAN..

Will get the JSON Only data back.

Thanks,
Prabhas

Announcements


Top Tags