Deleting Values from an XML node?

M

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
 
N

Norman Chong

Major said:
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()
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top