Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: VB9.0 VB.NET
Thanks in advance
i want to Delete a node from XMl file using VB.net
 
Here is my Xml file
 

<?xml version='1.0'?>
<Names>
  <Name>
    <First_Name>FN 1</First_Name>
    <Middle_Name>MN 1</Middle_Name>
    <Last_Name>LN 1</Last_Name>
    <Country_Code>001</Country_Code>
    <Area_Code></Area_Code>
    <Phone_No></Phone_No>
    <Email_Address>mail@email.com</Email_Address>
    <Address>Address 1</Address>
  </Name>
  <Name>
    <First_Name>FN 2</First_Name>
    <Middle_Name>MN 2</Middle_Name>
    <Last_Name>LN 2</Last_Name>
    <Country_Code>002</Country_Code>
    <Area_Code></Area_Code>
    <Phone_No></Phone_No>
    <Email_Address></Email_Address>
    <Address>Address 2</Address>
  </Name>
  </Names>
 
and the code for deleting is
 
 
Dim xd As New XmlDocument()
        xd.Load(App_Path)
        Dim nod As XmlNode = xd.SelectSingleNode("//First_Name[. = 'FN 1']" &        
        "/parent::node()/First_Name")
        If nod IsNot Nothing Then
            'nod.ParentNode.RemoveChild(nod)
            nod.ParentNode.RemoveAll()
            xd.Save(App_Path)
            ctlStatus.Text = "Deleted"
 
        End If
 

Problem i am facing is its deleting all child rows like this
 
<Name>
  </Name>

i want to delete whole node means including Parent node also
any help suggestion
Posted 17-Dec-11 7:52am

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

Perhaps something like:
nod.ParentNode.ParentNode.RemoveChild(nod.ParentNode)
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 OriginalGriff 5,130
1 DamithSL 4,237
2 Maciej Los 3,700
3 Kornfeld Eliyahu Peter 3,470
4 Sergey Alexandrovich Kryukov 2,846


Advertise | Privacy | Mobile
Web03 | 2.8.141216.1 | Last Updated 17 Dec 2011
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100