Parse an XML response from tRest in 2 different ways depending on the same XML

Highlighted
Eight Stars

Parse an XML response from tRest in 2 different ways depending on the same XML

Hi,

 

My situation is this. Im making an API call and getting an XML response. Depending on whether it is a successful response or failure response I want to extract different fields. the success response is in the below format and I want to extract FILE_PATH from here.

<Envelope>

<Body>

<RESULT>

<SUCCESS>TRUE</SUCCESS>

<JOB_ID>13681777</JOB_ID>

<FILE_PATH>/download/Test Contact X - All - Dec 21 2018 06-29-31 PM.CSV</FILE_PATH>

</RESULT>

</Body>

</Envelope>

 

And the failure response is this and I want to extract FaultString from here

 

<Envelope>

    <Body>

    <RESULT>

        <SUCCESS>false</SUCCESS>

    </RESULT>

    <Fault>

        <Request/>

        <FaultCode>invalid_token</FaultCode>

        <FaultString><![CDATA[The access token is invalid. Token provided was: aYrVV8SyBUoXvXn8USth/]]></FaultString>

        <detail>

            <error>

                <errorid>145</errorid>

                <module/>

                <class>SP.Admin</class>

                <method/>

            </error>

        </detail>

    </Fault>

    </Body>

</Envelope>

 

When I use tExtractXMLField to do this , the Loop XPath query and Path query has to be different for different response.

when it is a successful callI have to assign the FILE_PATH to a context variable and continue.When it is an error response I have to stop the processing(tDie) and add assign the FaultString as the error msg in tDie.

 

Does anyone have any thoughts/suggestions about this?

Please help me with this. I tried several different ways but could never accomplish this. Looking forward for some inputs from you guys.

 

Thanks !!


Accepted Solutions
Employee

Re: Parse an XML response from tRest in 2 different ways depending on the same XML

Hi,

 

    The first step will be to capture the response details to a context variable (success and failure). Then based on the failure condition (using an if condition), you can pass the corresponding context variable to down stream flow. You will have to create two flows here to parse the response i.e. one for success flow and other for failure flow.

 

    Then you will be able to parse them using tXMLMap components since you are managing them through two different flows.

 

Warm Regards,
Nikhil Thampi

Please appreciate our Talend community members by giving Kudos for sharing their time for your query. If your query is answered, please mark the topic as resolved :-)

View solution in original post


All Replies
Employee

Re: Parse an XML response from tRest in 2 different ways depending on the same XML

Hi,

 

    The first step will be to capture the response details to a context variable (success and failure). Then based on the failure condition (using an if condition), you can pass the corresponding context variable to down stream flow. You will have to create two flows here to parse the response i.e. one for success flow and other for failure flow.

 

    Then you will be able to parse them using tXMLMap components since you are managing them through two different flows.

 

Warm Regards,
Nikhil Thampi

Please appreciate our Talend community members by giving Kudos for sharing their time for your query. If your query is answered, please mark the topic as resolved :-)

View solution in original post

2019 GARNER MAGIC QUADRANT FOR DATA INTEGRATION TOOL

Talend named a Leader.

Get your copy

OPEN STUDIO FOR DATA INTEGRATION

Kickstart your first data integration and ETL projects.

Download now

What’s New for Talend Summer ’19

Watch the recorded webinar!

Watch Now

Best Practices for Using Context Variables with Talend – Part 2

Part 2 of a series on Context Variables

Blog

Best Practices for Using Context Variables with Talend – Part 1

Learn how to do cool things with Context Variables

Blog

Migrate Data from one Database to another with one Job using the Dynamic Schema

Find out how to migrate from one database to another using the Dynamic schema

Blog