Do not input private or sensitive data. View Qlik Privacy & Cookie Policy.
Skip to main content

Announcements
Join us in Toronto Sept 9th for Qlik's AI Reality Tour! Register Now
cancel
Showing results for 
Search instead for 
Did you mean: 
Anonymous
Not applicable

Extract entire XML element (with subelements)

Hello,
I'm new to Talend (just a week) and I have a situation that I cannot solve. I'm working with XML files, trying to read and write stuff.
Description of the problem:
I have and XML that can have 3 types of elements (not at the same time) at the same location in the tree.
For example:
<bill>
<product>
<price>22</price>
<book>Bla bla1</book>
</product>
<product>
<price>23</price>
<wine>Bla bla2<wine>
</product>
<product>
<price>2</price>
<cheese>Bla bla3<cheese>
</product>
</bill>

What I want to do is to cycle through the <product>, filter the results and output the entire XML without the products that are <book>, for example.
The idea is that I cannot output the info normally using a schema because at the same location in <product> I can have <book> or <wine> or <cheese>.
The output XML would look like this:
<bill>
<product>
<price>23</price>
<wine>Bla bla2<wine>
</product>
<product>
<price>2</price>
<cheese>Bla bla3<cheese>
</product>
</bill>

I already cycle through products and I've already put in the condition.
I've also already tried to extract the node <product> as a 'Document' and output it to the other XML, but it doesn't work and throws this exception:
Error on line 2 of document  : Content is not allowed in prolog. Nested exception: Content is not allowed in prolog.

Can I extract the <product> element with all its subelements and output it to another XML?
I'm kinda out of ideas. The only thing I can think of is to copy the entire XML file and somehow delete the nodes that I don't want, but that would only be a temporary solution. I still want to "compose" the output XML.
So, do you have any suggestions?
P.S.: Any idea is appreciated.
Labels (3)
12 Replies
Anonymous
Not applicable
Author

Yes, that helps me to eliminate the filterRow element and use a tMap instead.
But, any ideas regarding the xmlWriteField?
Anonymous
Not applicable
Author

Hi,
Yeah the 'product' variable is of type String. This gets treated by the tExtractXMLField as XML document.
As seen in the screenshots I added an output XML component, to create the file. Note the fact, as Brandon said, that you should uncheck the "Create empty element if needed" on the Advanced settings tab of the tAdvancedFileOutputXML component.
Regards,
Arno
Anonymous
Not applicable
Author

I get it now!
Thank you!