4 Replies Latest reply on Jan 13, 2016 2:22 AM by pharlapur RSS
    varathanran Apprentice

    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

      • Thingworx treats the XML output from Rest Services as HTML
        paic Collaborator

        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.

          • Thingworx treats the XML output from Rest Services as HTML
            varathanran Apprentice

            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