problem editing xml document  
Author Message
Spoofer





PostPosted: XML and the .NET Framework, problem editing xml document Top

Hello

I want to add more info to a xml file, but my code isn't working

my xml file looks like this :

<images>
<pic>
<image>\img\Keukens\1.jpg</image>
<naam>foto1</naam>
</pic>
</images>


Now i want to add another <pic></pic> with fields image and name , in the <images> section

What i tried myself and didn't work :(

// Create xml dom
XmlDocument XMLDom = new XmlDocument();
//load your xml file

//Select main node
XmlNode newXMLNode = XMLDom.SelectSingleNode("Pics");
//get the node where you want to insert the data
XmlNode childNode = XMLDom.CreateNode(XmlNodeType.Element, "Pic", "");
//In the below step "name" is your node name and "sree" is your data to insert
XmlAttribute newAttribute = XMLDom.CreateAttribute("image", "blabla", "");
childNode.Attributes.Append(newAttribute);
newXMLNode.AppendChild(childNode);

Can anyone please help
thanx


.NET Development2  
 
 
Martin Honnen





PostPosted: XML and the .NET Framework, problem editing xml document Top

After the Load call use the following

XmlElement pic = XMLDom.CreateElement("pic");

XmlElement image = XMLDom.CreateElement("image");

pic.AppendChild(image);

XmlElement naam = XMLDOM.CreateElement("naam");

pic.AppendChild(naam);

XMLDom.DocumentElement.AppendChild(pic);

// now save changes e.g.



 
 
Spoofer





PostPosted: XML and the .NET Framework, problem editing xml document Top

thanx a lot
this worked