sneeri_c
asked on
Add to XML File
I am using VB.NET 2005.
I need to be able to add to an XML File. If I have the following:
<?xml version="1.0" encoding="utf-8" ?>
<applicationlist>
<app>
<name>AC</name>
<srcdir>c:\AC</srcdir>
</app>
</applicationlist>
I want to add a new <app> section to this xml. So I then have:
<?xml version="1.0" encoding="utf-8" ?>
<applicationlist>
<app>
<name>AC</name>
<srcdir>c:\AC</srcdir>
</app>
<app>
<name>NewAppInfo</name>
<srcdir>c:\Info</srcdir>
</app>
</applicationlist>
Thanks for the help.
I need to be able to add to an XML File. If I have the following:
<?xml version="1.0" encoding="utf-8" ?>
<applicationlist>
<app>
<name>AC</name>
<srcdir>c:\AC</srcdir>
</app>
</applicationlist>
I want to add a new <app> section to this xml. So I then have:
<?xml version="1.0" encoding="utf-8" ?>
<applicationlist>
<app>
<name>AC</name>
<srcdir>c:\AC</srcdir>
</app>
<app>
<name>NewAppInfo</name>
<srcdir>c:\Info</srcdir>
</app>
</applicationlist>
Thanks for the help.
Dim doc As New XmlDocument()
doc.LoadXml("<book genre='novel' ISBN='1-861001-57-5'>" & _
"<title>Pride And Prejudice</title>" & _
"</book>")
Dim root As XmlNode = doc.DocumentElement
'Create a new node.
Dim elem As XmlElement = doc.CreateElement("price")
elem.InnerText = "19.95"
'Add the node to the document.
root.InsertAfter(elem, root.FirstChild)
Console.WriteLine("Display the modified XML...")
doc.Save(Console.Out)
doc.LoadXml("<book genre='novel' ISBN='1-861001-57-5'>" & _
"<title>Pride And Prejudice</title>" & _
"</book>")
Dim root As XmlNode = doc.DocumentElement
'Create a new node.
Dim elem As XmlElement = doc.CreateElement("price")
elem.InnerText = "19.95"
'Add the node to the document.
root.InsertAfter(elem, root.FirstChild)
Console.WriteLine("Display
doc.Save(Console.Out)
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
doc.LoadXml("<book ISBN='1-861001-57-5'>" & _
"<title>Pride And Prejudice</title>" & _
"</book>")
'Create a new attribute.
Dim newAttr as XmlAttribute = doc.CreateAttribute("genre
newAttr.Value = "novel"
'Create an attribute collection and add the new attribute
'to the collection.
Dim attrColl as XmlAttributeCollection = doc.DocumentElement.Attrib
attrColl.InsertAfter(newAt
Console.WriteLine("Display
Console.WriteLine(doc.Oute