# Add parent tag based on child attribute XML

**URL:** <https://forum.kirupa.com/t/add-parent-tag-based-on-child-attribute-xml/264927>\
**Category:** flash\
**Created:** [July 2, 2008, 6:04am UTC](https://forum.kirupa.com/t/add-parent-tag-based-on-child-attribute-xml/264927 "2008-07-02T06:04:41Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![mfsiddiq](https://avatars.discourse-cdn.com/v4/letter/m/ea5d25/32.png) [@mfsiddiq](https://forum.kirupa.com/u/mfsiddiq)\
**Post date:** [July 2, 2008, 6:04am UTC](https://forum.kirupa.com/t/add-parent-tag-based-on-child-attribute-xml/264927/1 "2008-07-02T06:04:41Z")

</div>

Hello everyone

May i know how i can add a parent tag to my xml based on child node attributes.For eg if this is my xml

\<data\>  
\<mango attr=‘sweet’\>mangoCategory\</mango\>  
\<orange attr=‘sour’\>orangeCategory\</orange\>  
\<chilly attr=‘spicy’\>chillyCategory\</chilly\>  
\<banana attr=‘sweet’\>bananaCategory\</banana\>  
\</data\>

The o/p should look like this  
\<data\>  
\<attr=‘sweet’\>  
\<mango attr=‘sweet’\>mangoCategory\</mango\>  
\<banana attr=‘sweet’\>bananaCategory\</banana\>  
\</attr\>  
\<attr=‘sour’\>  
\<orange attr=‘sour’\>orangeCategory\</orange\>  
\</attr\>  
\<attr=‘spicy’\>  
\<chilly attr=‘spicy’\>chillyCategory\</chilly\>  
\</attr\>

\</data\>
