framing XML

G

Guest

HI,
I have a XML document like this,
<colore>
<Red>1</Red1>
<blue>2</blue>
<colore>
What I wanted to do is, add an root element to this so that it will look like
<sample>
<colore>
<Red>1</Red1>
<blue>2</blue>
<colore>
<sample>

How do I do this. I am new to this XML stuff. How do I make the sample, the
root node of the colore node?
 
L

Lars Netzel

We need a little more to go on than that. What are you producing the XML
with?

/Lars
 
J

Jason Brown [MSFT]

Think the opposite way around. create a new node of <sample></sample>, then
append the existing node structure as a child node of that.


--
Jason Brown
Microsoft GTSC, IIS

This posting is provided "AS IS" with no warranties, and confers no
rights.
 
G

Guest

I think This will work, is there any other way.

XmlDocument xmldoc = new XmlDocument();
xmldoc.Load("d:\\test\\test.xml");
XmlDocument doc1 = new XmlDocument();

XmlElement elem = doc1.CreateElement("Sample"); // XmlElement
elem.InnerXml = xmldoc.InnerXml;
doc1.AppendChild(elem);
 
J

Jason Brown [MSFT]

There's always more than way of doing things, but as you say, that looks
like it should work OK, at first glance anyway - my brain is in a more COM
than .NET mode at the moment so forgive me if I've got crossed-eyes

I'd be tempted to replace elem.InnerXml = xmldoc.InnerXml; with a call to
appendChild() myself, but it more or less covers it. Try it and see.


--
Jason Brown
Microsoft GTSC, IIS

This posting is provided "AS IS" with no warranties, and confers no
rights.
 

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

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top