469,270 Members | 1,152 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,270 developers. It's quick & easy.

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 13062
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 discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by Steve S | last post: by
6 posts views Thread by Boobie | last post: by
2 posts views Thread by Petrucci2000 | last post: by
6 posts views Thread by Nikhil Patel | last post: by
2 posts views Thread by William | last post: by
1 post views Thread by Que | last post: by
11 posts views Thread by David | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by suresh191 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.