c# - Merge nodes of the same kind to a single node -


i'm trying merge 2 nodes of same kind single node

so having both nodes this

<clubs>   <spe>accepted</community>   <scu>accepted</scu> </clubs> 

and this

<clubs>   <bus>declined</bus> </clubs> 

it become this

<clubs>   <spe>accepted</spe>   <scu>accepted</scu>   <bus>declined</bus> </clubs> 

how achieve such thing?

this might you

           xmldocument mydocument = new xmldocument();            mydocument.load(xmlfile);            var nodetoadd = mydocument.childnodes.oftype<xmlelement>().where(nodevariant => nodevariant.name == "clubs").selectmany(o => o.childnodes.oftype<xmlelement>()).tolist();            var nodetodelete = mydocument.childnodes.oftype<xmlelement>().where(nodevariant => nodevariant.name == "clubs");            foreach (var m in nodetodelete)            {                mydocument.removechild(m);            }              xmlnode newnode = mydocument.createelement("clubs");             foreach(var m in nodetoadd)             {             newnode.appendchild(m);             }             mydocument.appendchild(newnode);             mydocument.save(xmlfile); 

Comments

Popular posts from this blog

php - regexp cyrillic filename not matches -

c# - OpenXML hanging while writing elements -

sql - Select Query has unexpected multiple records (MS Access) -