Results 1 to 6 of 6

Thread: Enrich Structure Data from XML file with filename

  1. #1

    Default Enrich Structure Data from XML file with filename

    Hi guys,

    Another question, is there a way which to enrich the structure output of an XML Data node ( lal1 library) with the filename it was extracted from?
    I need to read multiple XML files and some of them may have erroneous structures ( missing some nodes or different node definition or etc... ), the problem is that when I read 2 or more files I obtain an unified structure on the output of the XML Data Node and I need it separated per filename.

    Also, can I include the filename in the Metadata of the ouput pin Data? I mean if I have a file test.xml containing <Country><City></City></Country> I would like to have the output like this:
    filename.Country filename.Country.City ?

    Thanks,

    Cristi.

  2. #2
    Lavastorm Employee
    Join Date
    Apr 2014
    Location
    Boston, MA
    Posts
    279

    Default

    The following might be a bit overkill, but it does the job. The most complex part is using the looping example from Ernest.

    In short, we read in all files with *.xml extension from a folder. We then use the XML Data node to read in the data per file. Because the filename isn't an optional output, we need to merge that back in with the data from the XML Data node. And last step is to create a new field containing all the fields.
    Attached Files Attached Files

  3. #3
    Lavastorm Employee
    Join Date
    Aug 2009
    Location
    Cologne
    Posts
    513

    Default

    Because the filename isn't an optional output, we need to merge that back in with the data from the XML Data node.
    For that you can use the PassThroughFields parameter on the node in the Optional tab.

    Tim.

  4. #4
    Lavastorm Employee
    Join Date
    Apr 2014
    Location
    Boston, MA
    Posts
    279

    Default

    Shaking my head at myself. Thanks, Tim. Totally missed that. I've posted an updated (much simpler) version.
    Attached Files Attached Files

  5. #5

    Default

    Thanks guys, I initially solved this using shell script and adding a new tag on the lowest level with the file name.

    Since you seem to know you way well with parsing XML files with the BRE , I would ask you 2 more questions:

    1. When I have a tag which contains only null values in all the file e.g <Country><Country> , the XML data node doesn't recognize this tag in the structure output of it . Any way around this ( this is also currently solved by me adding by shell script in a temp file "@NULL" where tags contain empty data, but I would like to do it using the functionality of the BRE application)?
    2. The XML files I have to work can have null values for some tags represented like this <Country />, again the XML Data node does not recognize this null value. Any solution for this?

    Thanks .

    Cristi.

  6. #6
    Lavastorm Employee
    Join Date
    Apr 2014
    Location
    Boston, MA
    Posts
    279

    Default

    Could you provide a sample? I just ran a quick test with null fields and it worked fine. Using <fieldName/> notation also worked.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •