XML parsing and XML creation with Xpath queries problem

One Star

XML parsing and XML creation with Xpath queries problem

Hai,
i want to read values from input XML and needs to create output XML. i am facing some problems . i put my queries below if any one know please answer me.
InputXML:
<Article>
<Id>rfssee343433534534jdjc</Id>
<Title><!]></Title>
<AdTags>
<AdTag><!]></AdTag>
<AdTag><!]></AdTag>
<AdTag><!]></AdTag>
</AdTags>
<Data>
<Item>
<ItemEntityType>Image</ItemEntityType>
<ItemFilePath>/Image/mgptHFeghebbf.jpg</ItemFilePath>
</Item>
<Item>
<ItemEntityType>Image</ItemEntityType>
<ItemFilePath>/Image/mgptHFeghfrgtd.jpg</ItemFilePath>
</Item>
</Data>
</Article>

My queries:
1.when i read Title using XPATH query : Article/Title
I am getting data without CDATA. how can i get with CDATA.
2. To get AdTag's values i am using below XPATH Queries.
i) Article/AdTags/* --> returns only first AdTag value .
ii) Article/AdTags --> if i select with GetNodes option checked, schema type as object. returns Parent element <AdTags> and child elements.
But i am expecting only child elements with nodes. how can i get this.
3. i need to add new element in ItemId using ItemFilePath value it will be added next to I ItemFilePath element.

eg:
ItemFilePath=/Image/mgptHFeghebbf.jpg
ItemId=mgptHFeghebbf
How can i do this one?

I am using tFileInputXML and tAdvancedOutputXML components as of now.
One Star

Re: XML parsing and XML creation with Xpath queries problem

Hi
1. Because CDATA indicates Unparsed Character Data. It will be ignored by XML parser.
If you want to get CDATA, select "Get Nodes" option for this column and use tReplace to remove its node.
2. To get all AdTags, the Xpath loop expression should be /Article/AdTags/AdTag.
Fields to Extract
. AdTag
../../Id Id
../../Title Title
3. In your input XML file, there are two loops: AdTag and Item.
So you'd better use two tFileInputXML.
tFileInputXML(loop AdTag)--main-------------------------------------------------------tFileOutputMSXML
tFileInputXML(loop Item)--main----tJavaRow(add ItemId column here)---main---------|
Regards,
Pedro
One Star

Re: XML parsing and XML creation with Xpath queries problem

Hi
You'd better use tFileOutputMSXML instead of tadvancedoutputXML.
Regards,
Pedro
One Star

Re: XML parsing and XML creation with Xpath queries problem

Ok pedro. i will try. thank you.
One Star

Re: XML parsing and XML creation with Xpath queries problem

Hai,
I am trying to merge 2 files but talend not drawing a Main line between ArticleTagParser to MSXML component. please check my job drawing and comment.
One Star

Re: XML parsing and XML creation with Xpath queries problem

Hi,
I think you should be using the tFileInputMSXML component here.
Regards,
Arno
One Star

Re: XML parsing and XML creation with Xpath queries problem

Hai,
tried with tFileInputMSXML instead of tFileInputXML . but i am getting error "talend the schema from the input link is different from the schema defined in the component" .
It's working one of the Log row either AdTag or Data. if i enable both getting error.
the schema from the input link "AdTag\" is different from the schema defined in the component.
i attached screens . please check it.
One Star

Re: XML parsing and XML creation with Xpath queries problem

Hai,
I am trying to Split and merge XML using MSXML. but unable to merge. any one and tell me my job design will work .
job design image attached for reference
One Star

Re: XML parsing and XML creation with Xpath queries problem

Hi
Talend forbids that any loop linking exists in its job.
You'd better use two tFileInputXML with different schemas.
tFileInputXML(loop AdTag)--main-------------------------------------------------------tFileOutputMSXML
tFileInputXML(loop Item)--main----tJavaRow(add ItemId column here)---main---------|
Regards,
Pedro
One Star

Re: XML parsing and XML creation with Xpath queries problem

Hai,
i have to read xml's from a directory . so i am getting loop in tFileInputXML. can u design a job without loop to read files from directory.
I attached my design job for your reference.
One Star

Re: XML parsing and XML creation with Xpath queries problem

Hi
I don't know why you put tFileList here.
You might see the following images to know more about loop linking.
Regards,
Pedro
One Star

Re: XML parsing and XML creation with Xpath queries problem

I have a directory which contains articles as xml files. i need to read each file from that directory and then process it . For this purpose i am using tFileList here. do u have any other idea to read files from directory.
One Star

Re: XML parsing and XML creation with Xpath queries problem

Hi
Child job:
tFileInputXML(loop AdTag)--main-------------------------------------------------------tFileOutputMSXML
tFileInputXML(loop Item)--main----tJavaRow(add ItemId column here)---main---------|
Main job:
tFileList --Iterate-->tRunjob(Child job)
Pass the current file path into child job.
Regards,
Pedro
One Star

Re: XML parsing and XML creation with Xpath queries problem

Hai,
i don't know how to pass xml file name value from main job to child job . i attached my job designs. please check it.
i added column xmlfile - ((String)globalMap.get("tFileList_1_CURRENT_FILEPATH")) in iteratetoFlow component.
One Star

Re: XML parsing and XML creation with Xpath queries problem

Hi
Main job:
tFileList---Iterate-->tRunJob
Add a context variable called context.new1 in child job.
Regards,
Pedro
One Star

Re: XML parsing and XML creation with Xpath queries problem

Hai,
Adding context variable disabled in my talend . i am using Talend open studio big data 5.1.0 .
One Star

Re: XML parsing and XML creation with Xpath queries problem

Hi
Even though you are using TOS for BD, it is allowed to add context variable.
See the following image.
Then you are able to click on "+" button on tRunjob.
Regards,
Pedro
One Star

Re: XML parsing and XML creation with Xpath queries problem

my input/output xml having more inner level nodes. finally i got out put with tMap component and some custom routines functions.
can you tell me how to POST my output XML as a Stream to REST URL services.