leo_roar_001
leo_roar_001

Reputation: 181

xml elements with same attribute names getting overriden

My XML Structure looks like below:-   
<element>
 <note nom="Rock" >Roll</note>
 <note nom="Bands" >
   <note nom="Unit" >jayz<note>
   <note nom="Unit" >eminem<note>
   <note nom="Unit" >drake<note>
 </note>
</element>

After transformation I am only able to retain the last unit value Drake. The first two unit values are overridden during transformation.

Need help with the dataweave transformation (XML to JAVA) 

Upvotes: 3

Views: 101

Answers (1)

machaval
machaval

Reputation: 5059

Yes currently the attributes are being lost, though you can map them by hand.

payload.notes.*note map ((note, index) -> {
    (note: note) if note != null,
    (note.@)
})

Taking this xml as input

<notes>
  <note nom="Rock" >Roll</note>
  <note nom="Bands"/>
  <note nom="Unit" >jayz</note>
  <note nom="Unit" >eminem</note>
  <note nom="Unit" >drake</note>
</notes>

Having said this there is going to be a new writer flag on next release to make json writer and java writer persist the attributes

Upvotes: 1

Related Questions