09-29-2020 02:55 PM
Hello.
I have a custom gadget that calls a REST API endpoint that returns text/xml response. For example like:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<resp>
<member>
<child1>name1</child1>
<child2>name2</child2>
<child3>name3</child3>
</member>
<member>
<child1>name1</child1>
<child2>name2</child2>
<child3>name3</child3>
</member>
</resp>
I have to display the contents of each member (the child1, child2 and child3 node values) from above to the agent in a table.
I am trying to parse this XML in my gadget.js file (I have used ExternalRestApiSampleGadget as a reference), and when I try to create a DomParser by doing: var parser = new DomParser(); - nothing seems to be happening.
I feel like I am missing something simple here. How can I use a XML parser to read the values of the XML content.
Or is there a different way to parse XML in Finesse gadget?
Thank you for your help.
Praveen
Solved! Go to Solution.
09-29-2020 05:03 PM
Update:
I found saxparser in the finesse.js file (finesse.utilities.SaxParser), but no domparser. I still think I am missing something simple here
I did find another utility function xml2json in the finesse.js file and that seems lot easier to parse XML:
_util.xml2json(xmlResponseObj, "");
Once XML is converted to JSON, I was able to parse child nodes with for-in loop.
09-29-2020 05:03 PM
Update:
I found saxparser in the finesse.js file (finesse.utilities.SaxParser), but no domparser. I still think I am missing something simple here
I did find another utility function xml2json in the finesse.js file and that seems lot easier to parse XML:
_util.xml2json(xmlResponseObj, "");
Once XML is converted to JSON, I was able to parse child nodes with for-in loop.
Discover and save your favorite ideas. Come back to expert answers, step-by-step guides, recent topics, and more.
New here? Get started with these tips. How to use Community New member guide