How to delete the specific node from the xml file ?? keeping child node as it is


hi ,

this xml , need delete specific node form following xml file. wants delete node <aniruddha> following xml.

<?xml version="1.0" standalone="yes"?> <dataset> <customer> <id>0</id> <item>item0</item> <aniruddha xmlns:xsi="http://www.w3.org/2001/xmlschema-instance" xmlns:xsd="http://www.w3.org/2001/xmlschema"> <aniruddha> <id>1</id> <name>aniruddha</name> </aniruddha> </aniruddha> </customer>

my output sholud looks

<?xml version="1.0" standalone="yes"?> <dataset>     <customer>     <id>0</id>   <item>item0</item>     <aniruddha>   <id>1</id>   <name>aniruddha</name>   </aniruddha>     </customer> 

can me ?

thnx in adnavce

move child nodes parent node, remove aniruddha node.

here 2 ways, using xmldocument or xdocument:

   xmldocument doc = new xmldocument();     doc.load(filename);     var node = doc.selectsinglenode("//aniruddha");     foreach (xmlnode child in node.childnodes)     {             node.parentnode.appendchild(child);     }     node.parentnode.removechild(node);     doc.save(filename);
    xdocument doc = xdocument.load(filename);     var node = doc.descendants("aniruddha").first();     foreach (xnode child in node.elements())     {             node.parent.add(child);     }     node.remove();     doc.save(filename);



Visual Studio Languages  ,  .NET Framework  >  Visual C#



Comments

Popular posts from this blog

BizTalk Server 2013 Azure VM Log Shipping and HA for hosts

wcf-sql adapter bug for operation on same table

Error connecting to Azure Blob using Shared Access signature