By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
444,065 Members | 1,560 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 444,065 IT Pros & Developers. It's quick & easy.

Deleting Values from an XML node?

P: n/a
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
Nov 3 '06 #1
Share this Question
Share on Google+
1 Reply


P: n/a

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

Nov 3 '06 #2

This discussion thread is closed

Replies have been disabled for this discussion.