M
mark
Hi, I am having trouble with deleting nodes from an XML file. I use the
following code to remove an XML node.
xNode = xDoc.SelectSingleNode("//country/city/street[@name='" &
ListBox1.SelectedItem.ToString & "']")
xNode.RemoveAll()
<country name="France">
<city name="Paris">
<street name="1 France Lane">
<details>
<postcode>9988jj</postcode>
<province></province>
<c>France</c>
</details>
</street>
<street name="2 France Lane">
<details>
<postcode>9988jj</postcode>
<province></province>
<c>France</c>
</details>
</street>
</country>
The code seems to work except it is not removing the full node. I.E it
leaves behind and empty tag.
For example, if I needed to delete the second street address in the XML
above (2 France Lane) it would leave an empty tag of <street></street>
behind as illustrated below.
<country name="France">
<city name="Paris">
<street name="1 France Lane">
<details>
<postcode>9988jj</postcode>
<province></province>
<c>France</c>
</details>
</street>
<street>
</street>
</country>
Can anyone advise how I can clean this up and remove the full Street
element?
Many thanks.
Mark.
following code to remove an XML node.
xNode = xDoc.SelectSingleNode("//country/city/street[@name='" &
ListBox1.SelectedItem.ToString & "']")
xNode.RemoveAll()
<country name="France">
<city name="Paris">
<street name="1 France Lane">
<details>
<postcode>9988jj</postcode>
<province></province>
<c>France</c>
</details>
</street>
<street name="2 France Lane">
<details>
<postcode>9988jj</postcode>
<province></province>
<c>France</c>
</details>
</street>
</country>
The code seems to work except it is not removing the full node. I.E it
leaves behind and empty tag.
For example, if I needed to delete the second street address in the XML
above (2 France Lane) it would leave an empty tag of <street></street>
behind as illustrated below.
<country name="France">
<city name="Paris">
<street name="1 France Lane">
<details>
<postcode>9988jj</postcode>
<province></province>
<c>France</c>
</details>
</street>
<street>
</street>
</country>
Can anyone advise how I can clean this up and remove the full Street
element?
Many thanks.
Mark.