TRest XML response and parsing body

One Star

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>
One Star

Re: TRest XML response and parsing body

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
Seven Stars

Re: TRest XML response and parsing body

You might need to pass the response through a tReplace to change " > and < to " > and < respectively.
One Star

Re: TRest XML response and parsing body

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.
Seven Stars

Re: TRest XML response and parsing body

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 ".".
One Star

Re: TRest XML response and parsing body

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