473,795 Members | 2,974 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Ask for xmlelement copy method

Hello everyone.
I have two instance of xml.xmldocument . One is XA another is XB. XA has a
child node XA1. XA1 has many attributes and child nodes. Now I want to copy
XA1 to XB with all of it's attributes and child nodes. In .NET, the type of
XA1 is xml.xmlelement.
If I use clone method. The copy of XA1 is belong to XA. I can not append it
to XB.
If I careate a new instance from XB.CreateElemen t method. I need to copy
every attribute of XA1 to the new xml.xmlelement instance. The XA1.InnerXML
property just return the child nodes of XA1, and the XA1.OuterXML is
readonly. I can not send it to the new instance.
Who know how can i copy XA1 to XB easily and efficiently. Thanks.

Steven
Nov 12 '05 #1
4 3878
Steven.Xu wrote:
I have two instance of xml.xmldocument . One is XA another is XB. XA has a
child node XA1. XA1 has many attributes and child nodes. Now I want to copy
XA1 to XB with all of it's attributes and child nodes. In .NET, the type of
XA1 is xml.xmlelement.


Take a look at XmlDocument.Imp ortNode() method.

--
Oleg Tkachenko [XML MVP]
http://blog.tkachenko.com
Nov 12 '05 #2
> Take a look at XmlDocument.Imp ortNode() method.

Thanks for your help. but i said that the type of the instance which i want
to copy is xml.xmlelement. Not xml.xmldocument . So it's not have the
ImportNode method. Do you have another way? Thanks again!
Nov 12 '05 #3
"Steven.Xu" <St******@discu ssions.microsof t.com> wrote in message news:70******** *************** ***********@mic rosoft.com...
Take a look at XmlDocument.Imp ortNode() method.


Thanks for your help. but i said that the type of the instance which i want
to copy is xml.xmlelement. Not xml.xmldocument . So it's not have the
ImportNode method. Do you have another way? Thanks again!


The reason AppendChild( ) the deep-cloned XmlElement of 'XA1' to
'XB' is because the cloned node, like the original, is "owned" by
XmlDocument 'XA.' The ImportNode( ) method allows developers
to change the ownership of the node when moving nodes between
two documents.

By calling ImportNode( ) on 'XB' to change the ownership of the cloned
node from 'XA' to 'XB', you will then be able to AppendChild( ) the node
that has been imported to 'XB'. Here's an example,

XmlDocument XA = new XmlDocument( );
XA.Load( "yesterdaysLog. xml");
XmlDocument XB = new XmlDocument( );
XB.Load( "todaysLog.xml" );

XmlElement XA1 = XA.DocumentElem ent.FirstChild;
XmlElement XA1Clone = XA1.CloneNode( true);
XmlElement XB1 = XB.ImportNode( XA1Clone);

// Works as expected after the cloned element has been imported into XB.
XB.DocumentElem ent.AppendChild ( XB1);
Derek Harmon
Nov 12 '05 #4
Thank you very much for your help! Than's GOOD!
Nov 12 '05 #5

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

Similar topics

1
377
by: Parham | last post by:
Hello, I have an inherited class from XmlElement with this name: XmlElementCF I have added a function in XmlElementCF that returns a XmlNode, the node type is Element. I can cast the returned node to XmlElement but can not cast the returned node to XmlElementCF, I am getting an error : Specified cast is not valid. I want to cast the returned node to my inherited class XmlElementCF. Please Help. Thanks Parham
1
2447
by: john diss | last post by:
hello there everyone.. I have created a class called "ProcessLog" inheriting from XmlDocument and two classes ("UploadedItem", "ProcessError") inheriting from XmlElement. I then have two classes ("UploadedTemplate", "UploadedPresentation") which inherit from "UploadedItem")... so far so good. I have overriden the CreateElement method of "ProccessLog" and it creates the correct elements as expected. The problem is I need to override...
2
3307
by: Compic | last post by:
Hi! I have this class: public class StoredItemElement : XmlElement { protected internal StoredItemElement(string prefix, string localName, string namespaceUri, XmlDocument doc) : base(prefix, localName, namespaceUri, doc) { }
0
1546
by: ryanr | last post by:
I've run into a problem with a recursive algorithm. Basically, it grabs a tree, and creates premutations based off it. For example: Suppose you have you sell shoes in two colors (Black, Brown) and two sizes (Large, Small). My algorithm will run through a special XML tree (not a regular tree,
0
1187
by: Casper Bang | last post by:
I set up a Document-Literal(wrapped) WebService on a Oracle container (J2EE 1.4/JAX-RPC) and made a basic method which I can invoke from a browser or Java client. Java prototype: public org.w3c.dom.Element getIsPrime( org.w3c.dom.Element); My goal is then to be able to access it from .NET client as well for true interoperability. I used MS's wsdl tool to generate the C# stub. The stub works for simple method calls where a string is...
1
1599
by: RK | last post by:
What is the difference in performance if using XmlDocument or XmlElement as parameter in C# class method. thanks in advance. --RK
4
4373
by: Varangian | last post by:
Hello something I want to ask...... why on earth you cannot inherit from XmlElement???? .... or you can but XmlElement constructor is protected or private and so you cannot define an empty constructor. Even when I tried building a constructor with the exact parameters like XmlElement it wouldn't work!!!! "Error 1 No overload for method 'XmlElement' takes '0' arguments"
1
1508
by: bullrout | last post by:
Hi There, I have a method which uses some values passed in as xml, at times some of the elements in the document will be null. The document itself has many elements and I wanted to handle the null elements by just using a method wrapped around the element itself rather than using if statements. Could someone helpme out with the syntax so that the method returns back the object please? thanks in advance, sean this.someNode...
2
9043
by: nygiantswin2005 | last post by:
Hi I have wrote a method in my C# class with the following code, to create an XMl file. The root element is suppose to have 3 attibutes. I can not get attributes to appear correctly. XmlDocument document = new XmlDocument();
0
9672
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9519
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10215
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
10001
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7541
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6783
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5437
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5563
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
2920
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.