473,392 Members | 1,330 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,392 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 13153
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
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

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.