Talend tExtractXMLField

13,748

Solution 1

If you want to loop on <nome> nodes your Loop XPath Query has to be

"/empresas/empresa/imoveis/imovel/fotos/nome"

and foto_nome XPath Query something like

"text()"

Take care: I also corrected an error in your XML that could bring issues (</imoveis> missing the "s").

Solution 2

There are two ways to go about it. One way is to use directly XMLinput and the instructions that bluish mentioned.

The other way is to continue on the path that you chose. In the XMLinput, make sure that your Loop XPath query is set to "/empresas/empresa/imoveis/imovel/fotos" and that you pass through the fotos element with the Get Nodes option checked. The XPath Query of your fotos element should be "../fotos" or ".".

Your extractXMLField component looks to be well configured. Also, I don't know what tSetGlobalVar does in your design, but make sure it doesn't affect the fotos element that you're trying to pass through.

Solution 3

sample talend job
I have made a test job, this will help you definitely. If I'm not wrong you want to get all the "nome" under the "fotos" tag.

Share:
13,748
AntonioCS
Author by

AntonioCS

PHP/JS Programmer. Also dabble in Java, C/C++ and c#.

Updated on June 14, 2022

Comments

  • AntonioCS
    AntonioCS about 2 years

    I have this job in Talend that is supposed to retrieve a field and loop through it.

    My big problem is that the code is looping through the XML fields but it's returning null. Here is a sample of the XML:

    <?xml version="1.0" encoding="ISO-8859-1"?>
    <empresas>
        <empresa>
            <imoveis>
                <imovel>
                    [-- some fields --  ]
    
                    <fotos>
                        <nome id="" order="">photo1</nome>
                        <nome id="" order=""></nome>
                        <nome id="" order=""></nome>
                        <nome id="" order=""></nome>
                    </fotos>
                </imovel>
                [ -- other entries here -- ]
            </imoveis>
        </empresa>
    </empresas>
    

    Now using the tExtractXMLField component I am trying to get the "fotos" element. Here is what I have in the component: enter image description here

    I have tried to change the XPath query and the XPath loop query but the result is either I don't loop through the field or I get the null in the value field in the tMap.

    Here is an image of the job:

    enter image description here

    You can see that I have retrieved 4 items from the XML but what I get is null in the "nome" field. There must be something wrong with the XPath but I can't seem to find the problem :(

    Hope someone can help me out. Thanks Notes: I am using talendv4.1.2 on ubuntu 10.10 64bit