Remove a node from an XML File using VB.NET

vb.net , xml Toronto, Canada
  • 12 years ago
    Hai

    i ve an xml file in the format

    <Root>

           <ID>A</ID>

           <ID>B</ID>

           <ID>C</ID>

    </Root>

    I want to delete the node whose ID is "B" ... how can i do this ??

    The code that i wrote is

               Dim xpathquery as String

               Dim doc as new XmlDocument

               Dim selectedNode,main_node as XmlNode

               doc.Load(filnam)

               xpathquery = "/Root[ID='" & txtID.Text & "']"

               selectedNode = doc.SelectSingleNode(xpathquery)

               main_node = doc.SelectSingleNode(xpathquery)

               doc.DocumentElement.RemoveChild(main_node)

              doc.Save(filnam)

    when i tried executing this code i m getting the error "the node to be removed is not a child of this node " ... how can i correct this error ?? Can anybody help me ??

    Any help appreciated ...

    Thanx in Advance

Post a reply

No one has replied yet! Why not be the first?

Sign in or Join us (it's free).

Contribute

Why not write for us? Or you could submit an event or a user group in your area. Alternatively just tell us what you think!

Our tools

We've got automatic conversion tools to convert C# to VB.NET, VB.NET to C#. Also you can compress javascript and compress css and generate sql connection strings.

“Always code as if the guy who ends up maintaining your code will be a violent psychopath who knows where you live.” - Rick Osborne