I have some working code that can add an elememnt to an xml file:
Sub add_element_single(xmlfile, element_name, to_add, parentelement)
'Add a single element to a parent.
Dim xmlDoc As New XmlDocument
xmlDoc.Load(xmlfile)
Dim xmlRoot As XmlElement = xmlDoc.SelectSingleNode(parentelement)
Dim xmlChild As XmlElement = xmlDoc.CreateElement(element_name)
xmlChild.InnerText = to_add
xmlRoot.AppendChild(xmlChild)
Try
xmlDoc.Save(xmlfile)
Catch ex As Exception
MsgBox("Exception: " & ex.Message, MsgBoxStyle.Critical)
End Try
End Sub
That works great but Id like to use it to add a new element with attribute (if thats the correct terminology). For example, add a new house to this:
<houses>
<this ID="house1">
<windows>set1</windows>
<windows>set4</windows>
</this >
<this ID="house2">
<windows>set14</windows>
<windows>set15</windows>
</this >
</houses>
to create something like this:
<houses>
<this ID="house1">
<windows>set1</windows>
<windows>set4</windows>
</this >
<this ID="house2">
<windows>set14</windows>
<windows>set15</windows>
</this >
<this ID="house3">
<windows>set7</windows>
<windows>set22</windows>
</this >
</houses>