maw wrote:
> I am having problems adding a node without overwriting existing data.
> For example I can determine if a Country already exists in the XML file
> but when I add the City and the Street items to it using the following
> code, it replaces existing city and street data in the xml file rather
> than appending new elements.
>
> Sub InsertAddress(ByVal doc As XmlDocument)
> Dim addresses As XmlNode = doc.DocumentElement
> Dim country As XmlElement
>
> If country_exists() Then
> 'append
> country = doc.SelectSingleNode("//country[@name='Country']")
> Else
> country = doc.CreateElement("country")
> country.SetAttribute("name", "Spain")
> End If
>
> Dim city As XmlElement = doc.CreateElement("city")
> city.SetAttribute("name", "City3")
>
> Dim street As XmlElement = doc.CreateElement("street")
> street.SetAttribute("name", "20 Street Address")
>
> Dim details As XmlElement = doc.CreateElement("details")
> Dim postcode As XmlElement = doc.CreateElement("postcode")
> postcode.InnerText = "POS COD"
>
> Dim province As XmlElement = doc.CreateElement("province")
> province.InnerText = "County3"
>
> Dim c As XmlElement = doc.CreateElement("c")
> c.InnerText = "UK"
>
> country.AppendChild(city)
> city.AppendChild(street)
> street.AppendChild(details)
> details.AppendChild(postcode)
> details.AppendChild(province)
> details.AppendChild(c)
> addresses.AppendChild(country)
> End Sub
With that code that does a lot of AppendChild calls you are only adding
new nodes but you are certainly not able to overwrite stuff that way.
So that code should work fine.
--
Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/