all groups > dotnet xml > august 2005 >
You're in the

dotnet xml

group:

Remove XML Node


Re: Remove XML Node Martin Honnen
8/31/2005 12:00:00 AM
dotnet xml:


[quoted text, click to view]

If you have an XmlDocument and nodes in that document then to remove a
single node all you need to do is
node.ParentNode.RemoveChild(node);
With node lists you need to be careful as DOM nodes lists are live
collections thus if you have one and remove a node from the document
then it is removed from the node list as well.
So code alike
while (nodeList.Count > 0) {
nodeList[0].ParentNode.RemoveChild(nodeList[0]);
}
should do.

--

Martin Honnen --- MVP XML
Remove XML Node William
8/31/2005 6:57:19 AM
Have somebody a brilliant idea how to remove a nodelist in a XML
document? (With C#)

I have this xml file,I want delete the stock nodelist when an user
don't have permissions to see stocklist of that location.

<Respo1>
<From>Test</From>
<To>Test</To>
<MsgType>RESPO1</MsgType>
<MsgVer>001</MsgVer>
<MsgID>1712435695</MsgID>
<MsgDtTm>2005-08-18-17.01.47.634000</MsgDtTm>
<CustID>132300</CustID>
<QueryID>I1023932000030</QueryID>
<Cux>EUR</Cux>
<Articles>
<A>
<Lin>
</Lin>
<S>FVR1039</S>
<Stock>
<LocID>01</LocID>
<Qty>135,00</Qty>
<NetPr>50,00</NetPr>
</Stock>
<Stock>
<LocID>05</LocID>
<Qty>1,00</Qty>
<NetPr>50,00</NetPr>
</Stock>
</A>
</Articles>
</Respo1>

example: The user is not authorize to see the information where LocID
is 01. How can I delete the stock nodelist where LocID is 01.

Thanks for your advice
Regards,

William Mayvis
RE: Remove XML Node Rami Farhat
8/31/2005 8:08:06 AM
Hi,

[quoted text, click to view]

Inaddition to Martin's reply , you can use 'an xpath query to get to the
node or nodelists with LocID=01 or whatever id you want and then delete them
as follows

//for node list//
System.Xml.XmlNodeList nodeList =
doc.SelectNodes("/Respo1/Articles/A/Stock[LocID=01]");

//for single node//
System.Xml.XmlNode node =
doc.SelectSingleNode("/Respo1/Articles/A/Stock[LocID=01]");
node.ParentNode.RemoveChild(node);

Regards,
Rami Farhat

[quoted text, click to view]
AddThis Social Bookmark Button