Home All Groups Group Topic Archive Search About

Deleting Values from an XML node?

Author
3 Nov 2006 11:41 AM
Major Aardvark
Hi

Why is it that when I attempt to delete all values from a node in an XML
file using the code below, I end up with the values being deleted, but not
the tags?

The code i have is:

Dim CountryCodeValueNodes As XmlNodeList
Dim CountryCodeValue As XmlNode
CountryCodeValueNodes =
configurationFile.SelectNodes("//type[@name='lstCountry']/values/value")
For Each CountryCodeValue In CountryCodeValueNodes
Dim CountryCode = CountryCodeValue.Attributes("key")
'Remove all values
CountryCodeValue.Attributes.RemoveAll()
Next

The original values in the file I am trying to write are as follows:

<type name="lstCountry" default="" inherits="combo" regex="" regexsample="">
<values>
  <value key="US">
  </value>
  <value key="AD">
  </value>
  <value key="AE">
  </value>
  <value key="AF">
  </value>
  <value key="AG">
  </value>
  <value key="AI">
  </value>
</values>
</type>

What I actually get as the result is:

<type name="lstCountry" default="" inherits="combo" regex="" regexsample="">
<values>
  <value>
  </value>
  <value>
  </value>
  <value>
  </value>
  <value>
  </value>
  <value>
  </value>
  <value>
  </value>
</values>
</type>

Thanks

MA

Author
3 Nov 2006 12:14 PM
Norman Chong
Major Aardvark schrieb:

Show quoteHide quote
> Hi
>
> Why is it that when I attempt to delete all values from a node in an XML
> file using the code below, I end up with the values being deleted, but not
> the tags?
>
> The code i have is:
>
> Dim CountryCodeValueNodes As XmlNodeList
> Dim CountryCodeValue As XmlNode
> CountryCodeValueNodes =
> configurationFile.SelectNodes("//type[@name='lstCountry']/values/value")
> For Each CountryCodeValue In CountryCodeValueNodes
> Dim CountryCode = CountryCodeValue.Attributes("key")
> 'Remove all values
> CountryCodeValue.Attributes.RemoveAll()
> Next
>

Hiddeldiho,
With this line "CountryCodeValue.Attributes.RemoveAll()" you are
removing all *Attributes*, not the nodes. Try
CountryCodeValue.RemoveAll()