Appending an XML File from VB.net

awardle

Member
Joined
Apr 21, 2003
Messages
9
Im having some problems appending data to my XML file the structure I wish to achieve is
<Domains>
<Name>
<ID>3674</ID>
<Text>zzzopt.net</Text>
<Required>1</Required>
</Name>
</Domains>

I have been using the following code:

Dim xmldoc As System.Xml.XmlDocument = New System.Xml.XmlDocument()

xmldoc.Load("c:\xml\Domains.xml")

Dim xmlroot As System.Xml.XmlElement = xmldoc.DocumentElement
Dim xmlElement As System.Xml.XmlElement = xmlroot.AppendChild(xmldoc.CreateElement("Name"))

Create an element and append it to its parent
xmlElement = xmlElement.AppendChild(xmldoc.CreateElement("ID"))
xmlElement.InnerText = "2"

xmldoc.Save("c:\xml\dom1.xml")

This works fine but the problem is I can not work out how to append the rest and reatin the nested format.

Aaron
 
Back
Top