473,326 Members | 2,124 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,326 software developers and data experts.

Remove Node Complete with XmlNode.RemoveAll

Sam
I am attempting to remove a full node. XML Example:

<Videos>
<Video>
<Name>Crocodile Dundee 2</Name>
<Media>DVD</Media>
</Video>
<Video>
<Name>Terminator 6</Name>
<Media>DVD</Media>
</Video>
</Videos>

Here, seeing Terminator 6 doesn't exist, I want to remove the movie reference.

After loading the XML document and running the following code:
Dim xmlNodeList As System.Xml.XmlNodeList =
xmlDoc.SelectNodes("/Videos/Video")
xmlNodeList.Item(1).RemoveAll

it just removes the name and media data leaving me with:
<Videos>
<Video>
<Name>Crocodile Dundee 2</Name>
<Media>DVD</Media>
</Video>
<Video>
</Video>
</Videos>

For obvious reasons, this won't work--if I do a node count it will report 2
videos. Using node.parentnode.removeall will remove both videos and leave me
with just
<Videos>
</Videos>

I've been spending several hours trying different things but there appears
to be no article explaining this. Please assist!!

Thanks in advance!
Nov 12 '05 #1
2 5367
"Sam" <Sa*@discussions.microsoft.com> wrote in message news:D4**********************************@microsof t.com...
Dim xmlNodeList As System.Xml.XmlNodeList =
xmlDoc.SelectNodes("/Videos/Video")
xmlNodeList.Item(1).RemoveAll
RemoveAll( ) means Remove "All my children" (like the soap). Video has
two children, Name and Media, so both were removed (not the parent itself).
Using node.parentnode.removeall will remove both videos and leave me
Since node is Video, node's ParentNode is Videos. When you ask to Remove
all it's children, that rids you of Terminator 6, Crocodile Dundee 2, and all.

You were on the right track though, try

xmlNodeList.Item(1).ParentNode.RemoveChild( xmlNodeList.Item(1))

This is asking Videos to remove its Video child, the one presumably referring
to T6.
seeing Terminator 6 doesn't exist,


Don't bet on it, remember when he said, "I'll be back." The only question is
whether they call it T6 or "Terminator vs. Freddie: Nightmare on SkyNet." ;-)
Derek Harmon
Nov 12 '05 #2
Sam
Thanks! That works perfectly... yeah, you never know about T6! :)
"Derek Harmon" wrote:
"Sam" <Sa*@discussions.microsoft.com> wrote in message news:D4**********************************@microsof t.com...
Dim xmlNodeList As System.Xml.XmlNodeList =
xmlDoc.SelectNodes("/Videos/Video")
xmlNodeList.Item(1).RemoveAll


RemoveAll( ) means Remove "All my children" (like the soap). Video has
two children, Name and Media, so both were removed (not the parent itself).
Using node.parentnode.removeall will remove both videos and leave me


Since node is Video, node's ParentNode is Videos. When you ask to Remove
all it's children, that rids you of Terminator 6, Crocodile Dundee 2, and all.

You were on the right track though, try

xmlNodeList.Item(1).ParentNode.RemoveChild( xmlNodeList.Item(1))

This is asking Videos to remove its Video child, the one presumably referring
to T6.
seeing Terminator 6 doesn't exist,


Don't bet on it, remember when he said, "I'll be back." The only question is
whether they call it T6 or "Terminator vs. Freddie: Nightmare on SkyNet." ;-)
Derek Harmon

Nov 12 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Nikhil Patel | last post by:
Hi all, Following is a portion of an XML document. I need to remove all nodes that belong to ns0 without deleting their child nodes. So in the following example , I want to delete "ns0:Proposal"...
8
by: Mikey | last post by:
I have an XML document as follows: <Menu> <Group> <Item Text="About Us" AccessRoles="All"> <Group> <Item Text="Option 1" AccessRoles="All" /> <Item Text="Option 2" AccessRoles="All" /> <Item...
2
by: TT (Tom Tempelaere) | last post by:
Hey there, I'm having trouble finding the right XPath expression. The XML file I'm parsing contains an element Heads which contains sereveral Head elements. These Head elements have several Row...
3
by: Markus | last post by:
Hi! I wanted to select a subset of nodes (list = selectNodes("parent/child") from a XmlDocument, then remove all (parentNode.removeAll();) child-nodes and insert the previous selected nodes...
1
by: John Wilhelm | last post by:
I'm having a problem in by VB.net 2005 application. When i try to get a node from my app.config file the node come back with "nothing". The xmldocment loads OK, but I can't retrive a node. The...
15
by: Sharon | last post by:
I have an XML question: I'm have an XML node of type PointF and when it's saved to a file by XmlDocument.Save(...) it saves as I expect it to be saved: <ImageOrigin>{X=1.2,...
2
by: mark | last post by:
Hi, I am having trouble with deleting nodes from an XML file. I use the following code to remove an XML node. xNode = xDoc.SelectSingleNode("//country/city/street") xNode.RemoveAll() <country...
0
by: divya1949 | last post by:
Create a windows c# application which will Read a xml file and populate nodes in the treeview. 1 On selection of treenode display the child nodes of that node in listview control 2. ...
4
by: agda.karlberg | last post by:
Hello, I need to remove the DTD reference from an xml document, the reason for this is that we want to validate against a schema instead (which we have locally). It takes up to a minute to fetch...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.