How to extract string between tags from an XML file

One Star

How to extract string between tags from an XML file

Hi all,
I am trying to extract text between two tags of an xml file, but with negative results.
This is the xml structure and I need to extract the contents of the body, for some post processing.
<soap:Envelope>
<soap:Header>
...
</soap:Header>
<soap:Body>
<ns1:Response>
<Object id="id:1234567890">
....
</Object>
</ns1:Response>
</soap:Body>
</soap:Header>
</soap:Envelope>

I'm using the command tExtractXMLField, and these component properties:
- Property Type: Built-In
- Schema Type: Built-In
- XML field: Body
- Loop XPath query: "/Envelope/Body/*"
- Mapping: Column XPath query
Body "Body"
- Schema: Column Type ...
Body String ...
What's wrong? Probably wrong with the "Loop XPath query"?
Thanks in advance
Nic
Community Manager

Re: How to extract string between tags from an XML file

Hi
As a newbie, I would suggest you to use metadata manager to create a XML metadata follows the wizards, refer to Setting up an XML schema for an input file.
Here the Loop Xpath query should be:
"/soap:Envelope/soap:Body"
Shong
----------------------------------------------------------
Talend | Data Agility for Modern Business
One Star

Re: How to extract string between tags from an XML file

Hi Shong,
first of all thanks for your response. The script xml I posted, is a soap response.
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
<soapenv:Header>
<capabilities xmlns=........</capabilities>
</soapenv:Header>
<soapenv:Body>
<ibisag:queryRegObjResponse xsi:schemaLocation=.........>
<regObj id="id:obj:a1b2c3d4" objType="type:obj:abc0000">
<rim:Slot name="Author" xmlns:rim=.......>
<rim:ValueList>
<rim:Value>MyName</rim:Value>
</rim:ValueList>
</rim:Slot>
...
...
<rim:Slot name="email" xmlns:rim=".......>
<rim:ValueList>
<rim:Value>a@b.com</rim:Value>
</rim:ValueList>
</rim:Slot>
</registryObject>
</ibisag:queryRegistryRegObjResponse>
</soapenv:Body>
</soapenv:Envelope>

My goal is to extract the contents of the tag email ... I did some testing with an xml file with "simple" tag (without namespace, etc.) and it works, unfortunately I can not with this structure .. would you help me please?
thank you so much
Nic
Community Manager

Re: How to extract string between tags from an XML file

Hi
You can extract the value of a element or an attribute, for example, you can extract the value
MyName
a@b.com
from the element rim:Value, rather than the whole content under the element <soapenv:Body>.
Can you please email me an exmaple of your soap response and let me know what data would you like to extract?
Shong
----------------------------------------------------------
Talend | Data Agility for Modern Business
Highlighted
One Star

Re: How to extract string between tags from an XML file

Hi
You can extract the value of a element or an attribute, for example, you can extract the value
MyName
a@b.com
from the element rim:Value, rather than the whole content under the element <soapenv:Body>.
Can you please email me an exmaple of your soap response and let me know what data would you like to extract?
Shong

Email sent...
thanks
One Star

Re: How to extract string between tags from an XML file

Hi Shong,
did you get my email?
One Star

Re: How to extract string between tags from an XML file

Hi shong,
I want to remind you, when you can, to read my email.
Thanks for your interest.
Nic

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 4

Pick up some tips and tricks with Context Variables

Blog

How Media Organizations Achieved Success with Data Integration

Learn how media organizations have achieved success with Data Integration

Read

Agile Data lakes & Analytics

Accelerate your data lake projects with an agile approach

Watch