Click here to Skip to main content
15,881,882 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
This a piece of my XML file

<Player>
<Name>John Rooks</Name>
<TeleNo>
</TeleNo>
</Player>

</Players>
I am trying to remove the bit in bold, using this code when curComboItem = " John Rooks"
VB
nsmgr = New XmlNamespaceManager(myPlayersDOM.NameTable)
Dim PlayerNameList As System.Xml.XmlNodeList =          myPlayersDOM.GetElementsByTagName("Player")
For Each node As Xml.XmlNode In PlayerNameList
    xmlName = node.SelectSingleNode("Name", nsmgr)
    nodeName = xmlName.InnerText
    If nodeName = curComboItem Then
        node.RemoveAll()
        myPlayersDOM.Save("D:\My Documents on D\Visual Studio Projects\Match Management Application\Players.xml")
        Exit For
    End If
Next node

What I get is this

<Player>
</Player>

</Players>
Which ultimately results in a null exception.

Any ideas what I am doing wrong??
Posted
Updated 27-Jul-15 5:53am
v3
Comments
Sergey Alexandrovich Kryukov 27-Jul-15 13:15pm    
You are not even trying to remove one node. Use the debugger.
—SA
Dave the Golfer 27-Jul-15 17:26pm    
Thanks for your help.
Using the debugger I realised the line node.RemoveAll() was not working correctly.
I found a solution on StackOverFlow web site.
I replaced node.RemoveAll() with node.ParentNode.RemoveChild(node).
Code now works.

1 solution

Soluion is to replace node.RemoveAll() with node.ParentNode.RemoveChild(node)
 
Share this answer
 

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900