Skip to main content
Announcements
Introducing a new Enhanced File Management feature in Qlik Cloud! GET THE DETAILS!
cancel
Showing results for 
Search instead for 
Did you mean: 
Anonymous
Not applicable

TRest XML response and parsing body

I am setting up a process to receive xml data via the tRest component. The problem I am having is that the data is returned like:
<?xml version="1.0" encoding="ISO-8859-15"?>
<root>
<row>
<Body><webServiceResponse><response ResponseName="GET_COMPANY_LAST_LOCATION_RESPONSE"><responseList><responseItem id="DVN" value="991600"></responseItem><responseItem id="ActivityType" value="In Motion"></responseItem><responseItem id="LastLatitude" value="33.62412"></responseItem><responseItem id="LastLongitude" value="-84.45783"></responseItem><responseItem id="LastActivityDate" value="2012-07-20 19:00:05.0"></responseItem></responseList><responseList><responseItem id="DVN" value="991601"></responseItem><responseItem id="ActivityType" value="No Movement Today"></responseItem><responseItem id="LastLatitude" value="33.85838"></responseItem><responseItem id="LastLongitude" value="-117.8925"></responseItem><responseItem id="LastActivityDate" value="2012-07-19 21:53:51.0"></responseItem></responseList></responseList></response></webServiceResponse></Body>
</row>
</root>
You can see that the xml that I want is embedded in the <root><row><Body> structure. I am very new to Talend and cannot for the life of me figure out how to get this to look like what I need which is:
<?xml version="1.0" encoding="ISO-8859-15"?>
<webServiceResponse>
<response ResponseName="GET_COMPANY_LAST_LOCATION_RESPONSE">
<responseList>
<responseItem id="DVN" value="991600"></responseItem>
<responseItem id="ActivityType" value="In Motion"></responseItem>
<responseItem id="LastLatitude" value="33.62412"></responseItem>
<responseItem id="LastLongitude" value="-84.45783"></responseItem>
<responseItem id="LastActivityDate" value="2012-07-20 19:00:05.0"></responseItem>
</responseList>
<responseList>
<responseItem id="DVN" value="991601"></responseItem>
<responseItem id="ActivityType" value="No Movement Today"></responseItem>
<responseItem id="LastLatitude" value="33.85838"></responseItem>
<responseItem id="LastLongitude" value="-117.8925"></responseItem>
<responseItem id="LastActivityDate" value="2012-07-19 21:53:51.0"></responseItem>
</responseList>
</response>
</webServiceResponse>
Labels (4)
5 Replies
Anonymous
Not applicable
Author

Hi
You might create a job like this.
tREST--main-->tExtractXMLFields--main-->tAdvancedXMLOutput
Please download the document here. Then you can get the instructions and scenarios about these components.
Regards,
Pedro
alevy
Specialist
Specialist

You might need to pass the response through a tReplace to change " > and < to " > and < respectively.
Anonymous
Not applicable
Author

Pedro/Alevy,
Thanks for the input. When I use the tExtractXMLFields, I am able to get to my data by using the correct Xpath and inserting to fields for example /webServiceResponse/response/responseList/responsItem/@value and so on mapped to variables. Unfortunately, while it appears to be pulling the correct number of records, it is, in fact pulling the first record and duplicating it for every row. I have not been able to use the tExtractXMLFiield to pull only the body out of the data that comes from tRest.
alevy
Specialist
Specialist

If your Loop Xpath is "/root/row/Body/webServiceResponse/response/responseList" then your field values should be just "responseItem/@value". Including the full path in the Xpath query is causing it to read the value for the first responseItem each time.
To pull the whole Body as one, just set your Loop Xpath to "/root/row/Body" and the Xpath query to ".".
Anonymous
Not applicable
Author

Alevy,
That did it. Thanks, I knew I was missing something minor (and dumb to have not seen on my part).