Skip to main content
Solved

Accessing parent node attributes in XML with repeated tags


Forum|alt.badge.img
  • Data Voyager
  • 4 replies

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?

Best answer by AKislyakov

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

 

View original
Did this topic help you find an answer to your question?

2 replies

Forum|alt.badge.img+2
  • Ataccamer
  • 146 replies
  • Answer
  • April 22, 2024

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

 


Forum|alt.badge.img
  • Author
  • Data Voyager
  • 4 replies
  • April 22, 2024

Thank you!  Yes, that worked


Cookie policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie settings