By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,948 Members | 852 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,948 IT Pros & Developers. It's quick & easy.

framing XML

P: n/a
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?
Nov 19 '05 #1
Share this Question
Share on Google+
4 Replies


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

/Lars

"Venkat" <Ve****@discussions.microsoft.com> skrev i meddelandet
news:EF**********************************@microsof t.com...
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?

Nov 19 '05 #2

P: n/a
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.
"Venkat" <Ve****@discussions.microsoft.com> wrote in message
news:EF**********************************@microsof t.com...
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?

Nov 19 '05 #3

P: n/a
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);


"Jason Brown [MSFT]" wrote:
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.
"Venkat" <Ve****@discussions.microsoft.com> wrote in message
news:EF**********************************@microsof t.com...
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?


Nov 19 '05 #4

P: n/a
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.
"Venkat" <Ve****@discussions.microsoft.com> wrote in message
news:D0**********************************@microsof t.com...
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);


"Jason Brown [MSFT]" wrote:
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.
"Venkat" <Ve****@discussions.microsoft.com> wrote in message
news:EF**********************************@microsof t.com...
> 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?


Nov 19 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.