Posted By: CodeGuru123 | Nov 5th @ 3:40 PM
page 1 of 1
Comments: 4 | Views: 123

I'm stumped on this one, been googling for hours...

 

I have a central xmldoc that I use to store all of my app settings, etc..


What I'm trying to do is simply pull an entire node from that file into one of my child forms where I can parse it out.

In the child form I also want to build a new node from new settings and pass it back into my central xmldoc config.

 

I need to do this without holding a reference to the parent xmlDoc.

 

I simply want to build an xmlNode from scratch, but I cannot figure out how without using XmlDoc to .CreateElement();

 

Certainly there has to be a way to XmlNode.CreateElemenet or XmlNode.AppendChild(new xmlElement())...

 

Any pointers would be much apperciated.

 

Thanks a bunch!

ScanIAm
ScanIAm
On a scale of 1 to 10, people are stupid.

Use Linq to XML.

 

 

XDocument originalXDoc = XDocument.Load("config.file");

XElement originalXElement = originalXDoc.Descendants(XName.Get("name of element","namespace of element")).First();

XElement copyOfOriginalXElement = new XElement(originalXElement);

...do some manipulation of the copy...

originalXElement.ReplaceWith(copyOfOriginalXElement);

originalXDoc.Save("config.file");

 

I wrote this from memory, so the  syntax may be a bit off, but it should work.

Sven Groot
Sven Groot
My name has 9 letters. Coincidence? I think not...

Simply use the XmlNode.OwnerDocument property to get a reference to the document that a particular node belongs to.

page 1 of 1
Comments: 4 | Views: 123
Microsoft Communities