Solved

Accessing parent node attributes in XML with repeated tags

  • 18 April 2024
  • 2 replies
  • 16 views

I have an xml file with a structure like this:

<model xmlns="http://www.ataccama.com">
    <entities>
        <entity name="table1" />
     <columns>
             <column datatype="varchar(100)" name="abc" required="false" />
             <column datatype="int" name="xyz" required="false" />
             <column datatype="datetime" name="123" required="false" />
     </columns>
...

I want to produce a data stream that combines the column name and data_type with the name from the parent entity node.  If I define the columns using xpath nm:model/nm:entitles/nm:entity/nm:columns/nm:column then I cannot access the entity name using ../../@name (or any xpath expression for that matter).  If I define the columns using entity level xpath epxression nm:model/nm:entitles/nm:entity and the columns with xpath nm:columns/nm:column/@name then I only get 1 record per entity with the first column only.   How can I get the entity name, column name, and column data_type on each line?

icon

Best answer by AKislyakov 22 April 2024, 18:39

View original

2 replies

Userlevel 4
Badge +4

Hi @Mr.DQ,

What you need is a child data stream.

Define your top level XPath on the entity level (/nm:model/nm:entitles/nm:entity) and parse out entity name

 

Then create a child stream (columns in my example) with relative XPath from entity level (./nm:columns/nm:column)
 

 

In here you can access columns of the parent Data stream using Shadow Columns section and dot-notation

 

Thank you!  Yes, that worked

Reply