473,322 Members | 1,610 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,322 software developers and data experts.

xml document content to xml element

hi all,

i need to copy the content of a xml document and use it as xml element and
insert into another xml document.

Can someone tell me how?

thank you
Aug 17 '06 #1
2 2227
"dotnetnoob" <do********@discussions.microsoft.comwrote in message
news:C0**********************************@microsof t.com...
hi all,

i need to copy the content of a xml document and use it as xml element and
insert into another xml document.

Can someone tell me how?
This is fairly obvious:

XmlDocument newDocument = new XmlDocument();
XmlDocument documentToCopy = new XmlDocument();
documentToCopy.Load(fromWhereverItComesFrom);
XmlNode imported = newDocument.ImportNode(documentToCopy.DocumentElem ent);
newDocument.AppendChild(imported);

// John
Aug 17 '06 #2


dotnetnoob wrote:

i need to copy the content of a xml document and use it as xml element and
insert into another xml document.

Can someone tell me how?
One way using the DOM/XmlDocument:

XmlDocument xmlDocument1 = new XmlDocument();
xmlDocument1.Load("file1.xml");

XmlDocument xmlDocument2 = new XmlDocument();
xmlDocument2.Load("file2.xml");

xmlDocument1.DocumentElement.AppendChild(xmlDocume nt1.ImportNode(xmlDocument2.DocumentElement,
true));

xmlDocument1.Save("file3.xml");
// of course you can also overwrite the existing document with e.g.
// xmlDocument1.Save("file1.xml");
Should also be possible using XmlReader and XmlWriter but needs more code.
--

Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/
Aug 17 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: lawrence | last post by:
I'm a beginner with Javascript and especially cross-browser Javascript. I got this working in IE, but not in Netscape 7. It seems like, in Netscape, every time I click on a button, the focus shifts...
13
by: Stumped and Confused | last post by:
Hello, I really, really, need some help here - I've spent hours trying to find a solution. In a nutshell, I'm trying to have a user input a value in form's textfield. The value should then be...
10
by: Russell Mangel | last post by:
What would be the best way to parse this XML document? I want to avoid using XMLDocument. I don't know if I should use XMLTextReader, or Xpath classes. There is only one element <MessageStore>...
7
by: Andrea | last post by:
Hi there - I'm hoping someone can help me; I've been struggling with this for a few days! :-) I have a webpage that is comprised of many forms containing questions. As the user answers one...
6
by: john.lum | last post by:
I am using document.write in an external javascript file to display some content, but I've found that I can't rely on that content being displayed in the location I expect. Here's a very simple...
5
by: WilliamRLinden | last post by:
Hi world! we are pretty new to JavaScript and have been struggling for now 2 days on this problem ... We would appreciate mercy if anyone can give us some. Basically we are trying to simulate...
5
by: garfy | last post by:
Hi i get this error in validation Line 22 column 6: document type does not allow element "title" here. <title>Seo Web Design Los Angeles - Web Design And Search Engine Optimization L ...
4
by: smartic | last post by:
Hi everyone. I'm having problem with firefox only but it works when i delete document definition that is my code: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"...
11
Dormilich
by: Dormilich | last post by:
Lately I have seen so much awful HTML, that I like to show what a HTML document should look like, regarding the requirements from the W3C. the absolute minimum is defined as: or expressed in...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.