Insert nodes in a xml file using tWriteXMLfield or tXMLMap

One Star

Insert nodes in a xml file using tWriteXMLfield or tXMLMap

Hi, in my job i am extracting nodes from an xml file with tExtractXMLfield component (option get node) and i would like to insert this node in a new xml file using tWriteXMLfield. Is it possible and how can i do it ?
thx
Moderator

Re: Insert nodes in a xml file using tWriteXMLfield or tXMLMap

Hi,
If I understand you well, you can use tWriteXMLField to read an input XML file and extract the structure to insert it in defined fields of the output file directly.
Please see the related scenario in component reference TalendHelpCenter:tWriteXMLFieldSmiley Frustratedcenario: Extracting the structure of an XML file and inserting it int....
Best regards
Sabrina
--
Don't forget to give kudos when a reply is helpful and click Accept the solution when you think you're good with it.
One Star

Re: Insert nodes in a xml file using tWriteXMLfield or tXMLMap

Hi Sabrina, thank you for your reply. But this is not exactly what I want. That's part of my job.

tExtractXMLField -----> tMap ------>tjavaflex------->tWriteXMLField or tXMLMap
From tExtracXMLField component i recieve single data like codcli = "12345" and complex data (nodes) like this
address = "<adresse>
<rue>1 avenue Lavenue</rue>
<code postal>35001</code postal>
<ville>Laville</ville>
</adresse>"
I can't do otherwrise because the xml in input is very complex and XPath don't give all datas as i want.
So the data flux recieve by my tWriteXMLField contain this two types of data. And i want using. From my tWriteXMLField or tXMLMap I want this xml.
<code client>12345</code client>
<adresse>
<rue>1 avenue Lavenue</rue>
<code postal>35001</code postal>
<ville>Laville</ville>
</adresse>
how use variable "adress" for insert, merge this data structure in the xml file outing. I tried tXMLMap too using "Create as sub-element of taget node" option but "<" and ">" symbol are change in "&lt" and "&gt". How can I do this to have the result that i want.
thx
Highlighted
One Star

Re: Insert nodes in a xml file using tWriteXMLfield or tXMLMap

I have exactly the same problem. What is the recommended way to fulfill this requirement?
Community Manager

Re: Insert nodes in a xml file using tWriteXMLfield or tXMLMap

Hi elelik
tXMLMap is the proper component for you to read data from a document or output a document. You need to re-create the node in the output document on tXMLMap component, see my screenshots, I am using Talend Open Studio For Data Integration v5.4.1 and it works well, I don't get the symbol problem.
Result on console:
Starting job test at 18:15 03/04/2014.
connecting to socket on port 3992
connected
<?xml version="1.0" encoding="UTF-8"?>
<addresse>
<rue>rue1</rue>
<post_code>521000</post_code>
</addresse>
<?xml version="1.0" encoding="UTF-8"?>
<root><person><id>1</id><name>Shong</name><addresse><rue>rue1</rue><post_code>521000</post_code></addresse></person></root>
disconnected
Job test ended at 18:15 03/04/2014.

----------------------------------------------------------
Talend | Data Agility for Modern Business
One Star

Re: Insert nodes in a xml file using tWriteXMLfield or tXMLMap

Hi,
Is it possible to use the previous solution but without recreating the complete node.
Example, to pass the root of "input.adresse" to a node "output.adresse" ?
I have a complex .xml (500 element) with a really bad .xsd so I am forced to do the mapping by hand, but If I could generate the main complexElement before, this would be much faster.
Thanks in advance