473,324 Members | 2,511 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,324 software developers and data experts.

Remove node

Can somebody tell me how to remove a node in an XML document?
(with VB .NET)

for example:
if I have this XML file:

<?xml version="1.0" ?>
<EMPLOYEES>
<PERSON>
<NAME>Geert</NAME>
</PERSON>
<PERSON>
<NAME>Dirk</NAME>
</PERSON>
</EMPLOYEE>
And I want to remove the person with NAME="Dirk"
Posted Via Usenet.com Premium Usenet Newsgroup Services
----------------------------------------------------------
** SPEED ** RETENTION ** COMPLETION ** ANONYMITY **
----------------------------------------------------------
http://www.usenet.com
Nov 12 '05 #1
3 13152
Something like this will do the trick...

Imports System
Imports System.IO
Imports System.Xml

public class Sample

public shared sub Main()

Dim doc as XmlDocument = new XmlDocument()
doc.Load("doc.xml")
doc.DocumentElement.RemoveChild(root.DocumentEleme nt.SelectSingleNode("desce
ndant::NAME[text()='Dirk']").ParentNode);

end sub
end class
Steven Livingstone, XmlInsider
http://venturetogether.com

"Henk" <kl*******@hotmail-dot-com.no-spam.invalid> wrote in message
news:40**********@Usenet.com...
Can somebody tell me how to remove a node in an XML document?
(with VB .NET)

for example:
if I have this XML file:

<?xml version="1.0" ?>
<EMPLOYEES>
<PERSON>
<NAME>Geert</NAME>
</PERSON>
<PERSON>
<NAME>Dirk</NAME>
</PERSON>
</EMPLOYEE>
And I want to remove the person with NAME="Dirk"
Posted Via Usenet.com Premium Usenet Newsgroup Services
----------------------------------------------------------
** SPEED ** RETENTION ** COMPLETION ** ANONYMITY **
----------------------------------------------------------
http://www.usenet.com

Nov 12 '05 #2
What other functions can I use between the brackets?
NAME[text()='Dirk']").

For example if I have a textbox where I enter a number and I want to
remove the person with that number.

I tried this but it didn't work:

Dim nr As String = TextBoxNr.Text

doc.DocumentElement.RemoveChild(doc.DocumentElemen t.SelectSingleNode("descendant::PER[text()=nr]").ParentNode)
Posted Via Usenet.com Premium Usenet Newsgroup Services
----------------------------------------------------------
** SPEED ** RETENTION ** COMPLETION ** ANONYMITY **
----------------------------------------------------------
http://www.usenet.com
Nov 12 '05 #3
You need to concatenate the NR value: text()='" + nr + "']"

"Henk" <kl*******@hotmail-dot-com.no-spam.invalid> wrote in message
news:40********@Usenet.com...
What other functions can I use between the brackets?
NAME[text()='Dirk']").

For example if I have a textbox where I enter a number and I want to
remove the person with that number.

I tried this but it didn't work:

Dim nr As String = TextBoxNr.Text

doc.DocumentElement.RemoveChild(doc.DocumentElemen t.SelectSingleNode("descen
dant::PER[text()=nr]").ParentNode)

Posted Via Usenet.com Premium Usenet Newsgroup Services
----------------------------------------------------------
** SPEED ** RETENTION ** COMPLETION ** ANONYMITY **
----------------------------------------------------------
http://www.usenet.com

Nov 12 '05 #4

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

Similar topics

3
by: Girish | last post by:
I have this XML FILE where I am reading data from and it has this node doctype "< ! D O C T Y P E a d f S Y S T E M " h t t p : / / w h o s c a l l i n g . c o m / d t d / a d f d t d . d t d...
1
by: Steve S | last post by:
I need some help modifying this code. The code was orginally setup to add/remove a single table row. I modified it to add 2 (two) rows with one column that spans both rows. That part works. I...
6
by: Boobie | last post by:
Is there any other way to remove a node/element other than going into the Parent and do "removeChild" ? thanks (need to remove a div of id "foobar")
2
by: Petrucci2000 | last post by:
Input Xml: <foo> <bar id="1"> <child1> <innerChild /> ............... </child1> <child2> <innerChild />
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"...
2
by: Sam | last post by:
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>
2
by: William | last post by:
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...
0
by: aredo3604gif | last post by:
I have coded a serie of singly linked lists in ANSI C which I have to use. The lists are then stored in a serie of buckets with chained hash table technique. In the various lists there are nodes...
1
by: Que | last post by:
hi i have the following xml document <root> <item> <key> <scode></scode> </key> <scode></scode> <desc></desc> <pc></pc>
11
by: David | last post by:
Hi All, I am working on a script that is theoreticaly simple but I can not get it to work completely. I am dealing with a page spit out by .NET that leaves empty tags in the markup. I need a...
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...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
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)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
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

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.