我的 XML 代码是这样的:
<?xml version="1.0" encoding="utf-8"?>
<Tabel>
<Member>
<Naam>Cruciatum</Naam>
<Kills>1000</Kills>
<Deaths>10</Deaths>
<KD>100</KD>
</Member>
<Member>
<Naam>Ghostbullet93</Naam>
<Kills>10</Kills>
<Deaths>1</Deaths>
<KD>10</KD>
</Member>
<Member>
<Naam>test</Naam>
<Kills>123</Kills>
<Deaths>11</Deaths>
<KD>11</KD>
</Member>
</Tabel>
处理后,XML 最终应如下所示:
<?xml version="1.0" encoding="utf-8"?>
<Tabel>
<Member>
<Naam>Cruciatum</Naam>
<Kills>1000</Kills>
<Deaths>10</Deaths>
<KD>100</KD>
</Member>
<Member>
<Naam>Ghostbullet93</Naam>
<Kills>10</Kills>
<Deaths>1</Deaths>
<KD>10</KD>
</Member>
</Tabel>
经过一番搜索,我想出了这段代码。
显然它对其他人有用,但它根本不适合我。
Private Sub btnDel_Click(sender As System.Object, e As System.EventArgs) Handles btnDel.Click
playername = lstmembers.SelectedItem.ToString
If MsgBox("Ben je zeker dat je " & playername & " wil verwijderen?", MsgBoxStyle.YesNo, "Confirmatie") = MsgBoxResult.Yes Then
Dim xmldoc As New XmlDocument()
xmldoc.load("C:\members.xml")
Dim node As XmlNode = xmldoc.SelectSingleNode("Root/Naam[. = '" & playername & "']")
If node IsNot Nothing Then
node.ParentNode.RemoveChild(node)
xmldoc.Save("C:\members.xml")
End If
'reload list
loadfile()
End If
End Sub
我没有得到任何例外,所以代码必须适合某些东西,只是显然不适合我需要的东西......
我希望你能看到我在哪里犯了错误。