471,570 Members | 966 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,570 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 13105
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
reply views Thread by leo001 | last post: by
reply views Thread by lumer26 | last post: by
reply views Thread by Vinnie | last post: by

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.