Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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) 
like image 640
leo_roar_001 Avatar asked Sep 11 '26 15:09

leo_roar_001


1 Answers

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

like image 166
machaval Avatar answered Sep 15 '26 06:09

machaval



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!