XML - Add a new node

D

Dave

Greetings,

Thanks for all the help on my previous XML question. Can you help me with
this one?

Say I have an XML file (myXMLFile.xml):

<configuration>
<Section Name="Settings">
<Key Name="Setting1" Value="101"></Key>
<Key Name="Setting2" Value="202"></Key>
<Key Name="Setting3" Value="303"></Key>
<Key Name="Setting4" Value="404"></Key>
</Section>
</configuration>

and I want to add an item:

<Key Name="Setting5" Value="505"></Key>

How can I do this via code?

Thanks,

-Dave
 
A

Alex Feinman [MVP]

Using the previous code var names:
Dim newElem as XmlElement = xd.CreateElement("Key")
newElem.SetAttribute("Name", "Setting5");
newElem.SetAttribute("Value", "505");
xd("configuration")("Section").AppendChild(newElem)
 
D

Dave

Alex,

It worked. Thanks for the help.

-Dave

Alex Feinman said:
Using the previous code var names:
Dim newElem as XmlElement = xd.CreateElement("Key")
newElem.SetAttribute("Name", "Setting5");
newElem.SetAttribute("Value", "505");
xd("configuration")("Section").AppendChild(newElem)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top