cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
605
Views
5
Helpful
1
Replies

parse XML response from REST API in custom gadget

1veenmudi
Level 1
Level 1

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

 

 

1 Accepted Solution

Accepted Solutions

1veenmudi
Level 1
Level 1

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.

 

View solution in original post

1 Reply 1

1veenmudi
Level 1
Level 1

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.

 

Getting Started

Find answers to your questions by entering keywords or phrases in the Search bar above. New here? Use these resources to familiarize yourself with the community: