One Star

XML output as string

Hi
I am working on project which need to be output as csv and xml file.
However the XML file or data from this file to be change to variable (string) which I will use or execute in my store procedure in SQL database.
Is anyone has idea is any component in talend which I can use to do this or any way for this to be done.
Thanks
Zeljka
5 REPLIES
Community Manager

Re: XML output as string

Hi
I think the tWriteXMLField component fit your need.
Best regards
Shong
----------------------------------------------------------
Talend | Data Agility for Modern Business
One Star

Re: XML output as string

Hi Shong,
I have look your componet and not sure that one is really right one.
could you please see my job and you will see that for my output I am having tAdvanceFileOutput and from that output I need to create variable (string) which I will use in SQL Database
Community Manager

Re: XML output as string

Hi
Yes, the tWriteXMLField component fit your need, use a tWriteXMLField instead of tAdvanceFileOutputXML to output a string and store it to context variable or global variable, and then you can use it on other component. Please read the user documentation and learn the tWriteXMLField usage.
Best regards
Shong
----------------------------------------------------------
Talend | Data Agility for Modern Business
One Star

Re: XML output as string

Thanks
Will try
One Star

Re: XML output as string

I have created some XML output using the AdvancedFileOutputXML component, now I want the entire XML output to be inserted into an XML field in the database:
example:
<?xml version="1.0">
<directory>
<person @id="1">
<first_name>Arthur</first_name>
<last_name>Daly</last_name>
<age>49</age>
<sex>often</sex>
<addresses>
<address @name="Home">
<address1>11 London Road</address1>
<City>London</City>
<Country>GB</Country>
</address>
<address @name="Work">
<address1>135 Bath Road</address1>
<City>London</City>
<Country>GB</Country>
</address>
</addresses>
</person>
</directory>

In the database:
create table DailyInventory(
Id int identity(1,1) not null constraint PK_DailyInventory primary key clustered,
Date datetime identity(1,1) not null,
Inventory xml not null
)
Now I want to insert the XML into the table as described above, for example:
insert into DailyInventory (Date, Inventory) values (getdate(), '<?xml version="1.0">
<directory>
<person @id="1">
<first_name>Arthur</first_name>
<last_name>Daly</last_name>
<age>49</age>
<sex>often</sex>
<addresses>
<address @name="Home">
<address1>11 London Road</address1>
<City>London</City>
<Country>GB</Country>
</address>
<address @name="Work">
<address1>135 Bath Road</address1>
<City>London</City>
<Country>GB</Country>
</address>
</addresses>
</person>
</directory>')

The tWriteXMLField component is not the component I need, I need a component that will read the contents of a file and store it into a single variable which can be passed to other objects as a single string. Is there a way to do this?