XML Attribute Namespace, Lookup Tables

One Star

XML Attribute Namespace, Lookup Tables

(1) I'm trying to generate:
<Host xlink:type="simple" xlink:href="#SomeElement1"/>
I'm not able to set namespaces for attributes such as xlink:type in the above example.
(2) Next I need to populate the values for xlink:href to some other xml elements within the document.
What would be possible ways to achieve this?
(a) One way would be to have a Map/LookupTable which I can query to retrieve the right element I need to link to, with which I can populate xlink:href.
How do I do this?
One Star

Re: XML Attribute Namespace, Lookup Tables


Could you show me more details, input files and results you want?
I can't catch your point now.
Best regards!
One Star

Re: XML Attribute Namespace, Lookup Tables

Thanks Pedro.
Basically my output is of the following format:
<root xmlns:xlink="http://www.w3.org/1999/xlink">
<SomeElement1 id="1" >
<Host xlink:type="simple" xlink:href="nil"/>
<SomeElement2 id="2">
<Host xlink:type="simple" xlink:href="#1"/>
<SomeElement3 id="3">
<Host xlink:type="simple" xlink:href="#2"/>
Case 1:
I'm using tAdvancedFileOutputXML, my input is an interfaceRegEx.
In the "Configure XML Tree option", I added xlink namespace on the root element.
However there was no way to "specify" a namespace for the attribute "type" in the element "Host".
So i just clicked on add attribute and typed "xlink:type".
My point here is Talend does not intelligently allow me to add a namespace to an attribute. This is however not a problem yet.
Case 2:
In the above XML snippet, you can see that each element is referencing some other element using xlink
SomeElement1 with id="1" is referencing nil.
SomeElement2 with id="2" is referencing SomeElement1 (xlink:href="#1")
SomeElement3 with id="3" is referencing SomeElement3
Now the information of which element references any other element should be stored in a map like this:
key Value
SomeElement1 nil
SomeElement2 #1
SomeElement3 #2
Next in my XML Output, as you can see above, as per the values in the map, I want to populate the xlink:href attribute of the host element.
when generating
<SomeElement2 id="2">, it should check the map and retrieve the value #1, and then this value should be populated in the href attribute of its host subelement.
Which component do I use to populate/create a map?
How do I query the map to fill up the values of the href attribute.
Hope I made things clear, and my question is probably very preliminary, in that case only provide the components and approach, I'll try working with it Smiley Tongue
One Star

Re: XML Attribute Namespace, Lookup Tables

I feel impossible to retrieve the value from 'SomeElement' dynamically.
But you may use a lookup input file, set the data as follows.
Then join two input flows with tMap.

Still i feel a little confused why you use a tFileInputRegex here and the detail of your input data.
Welcome to Talend Community.
Best regards!
One Star

Re: XML Attribute Namespace, Lookup Tables

Sorry if I have confused you.
Let me make it clear.
Input: A flat file which I'm using RegEx to extract data (details not required)
Output: XML file.
The output is the XML file, I'm not trying to "retrieve the value from 'SomeElement' dynamically."
(1) Given Input from any file, I want to create a map as shown above.
(2) From the map I want to populate the href field of the xml.
One Star

Re: XML Attribute Namespace, Lookup Tables

For case 1, you can right click on the Attribute 'xmlns:link', choose 'Set A Fixed Value' and type 'http://www.w3.org/1999/xlink'.
For case 2, I can come up with one way. Create a lookup table as follows.
id     href
1 nil
2 #1
3 #2
4 #3
5 #4

Then use component tMap to join your input file and this lookup file.
You may find more details in the following images.
Best regards!


Talend named a Leader.

Get your copy


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 1

Learn how to do cool things with Context Variables


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


Best Practices for Using Context Variables with Talend – Part 4

Pick up some tips and tricks with Context Variables