473,796 Members | 2,569 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Error: The node to be inserted is from a different document context

I'm getting an error that I'm very confused about. I'm trying to
generate an XML file completely from scratch in code. Here is the code
fragment that is causing me headaches:

Dim mBOEDOC as xml.xmldocument

dim inode as xml.xmlnode
dim iNode2 as xml.Xmlnode

mboedoc=new xml.xmldocument

inode2=mboedoc. createnode(xml. XmlNodeType.Doc ument, "BOETask", "")

iNode = mBOEDoc.createn ode(xml.xmlnode type.Element, "Program"," ")
inode2.appendch ild(inode)

Inode.innertext =mprogramname

The error is showing up on the appendchild procedure. I'm generating
both nodes from the same document. Why am I getting this error?

Thanks,

Michael Schnell

Nov 12 '05 #1
5 7771


sc*****@rdacorp .com wrote:
I'm getting an error that I'm very confused about. I'm trying to
generate an XML file completely from scratch in code. Here is the code
fragment that is causing me headaches:

Dim mBOEDOC as xml.xmldocument

dim inode as xml.xmlnode
dim iNode2 as xml.Xmlnode

mboedoc=new xml.xmldocument

inode2=mboedoc. createnode(xml. XmlNodeType.Doc ument, "BOETask", "")
Here you seem to try to create a second document.
iNode = mBOEDoc.createn ode(xml.xmlnode type.Element, "Program"," ")
inode2.appendch ild(inode)

Inode.innertext =mprogramname

The error is showing up on the appendchild procedure. I'm generating
both nodes from the same document. Why am I getting this error?


You need to use ImportNode if you want to copy a node from one owner
document to another:
inode2.AppendCh ild(inode2.Impo rtNode(inode, true))

--

Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/
Nov 12 '05 #2
Is iNode2 considered a different document from mBOEDoc when inode2 is a
node created inside mBOEDOc, the original xmldocument? I guess this is
what is really confusing me.

I create mBOEDoc with no nodes at all.

I then create inode2 (BOETask)

I then want to create a subnode to inode2, but since XMLNode doesn't
have a createNode function, i use the CreateNode function on the
document (mBOEDoc) to create iNode (Program). But iNode2 doesn't want
to accept iNode when I try to append it.

This is what is happening. Is this supposed to be happening?

Thanks,

Michael Schnell

Nov 12 '05 #3


sc*****@rdacorp .com wrote:
Is iNode2 considered a different document from mBOEDoc when inode2 is a
node created inside mBOEDOc, the original xmldocument? I guess this is
what is really confusing me.

I create mBOEDoc with no nodes at all.

I then create inode2 (BOETask)

I then want to create a subnode to inode2, but since XMLNode doesn't
have a createNode function, i use the CreateNode function on the
document (mBOEDoc) to create iNode (Program). But iNode2 doesn't want
to accept iNode when I try to append it.

This is what is happening. Is this supposed to be happening?


I would use
new XmlDocument()
to create a new XML DOM document in .NET and then the factory methods
CreateElement
CreateAttribute
CreateComment
etc. to create new nodes for that document.

As for dealing with two document, yes, in that case you need to use the
ImportNode method of one document passing in a node from the other document.
--

Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/
Nov 12 '05 #4
I'm not trying to be difficult, but I'm still confused.

you say:

I would use
new XmlDocument()
to create a new XML DOM document in .NET and then the factory methods
CreateElement
CreateAttribute
CreateComment
etc. to create new nodes for that document.

Isn't that what I say I'm doing earlier, when I say I create a
XMLDocument, create a base node and then try to create subnodes. I'm
not dealing with 2 documents, I'm only dealing with one (mBOEDoc) but
with several nodes within it.

Thank you,

Michael Schnell

Nov 12 '05 #5


sc*****@rdacorp .com wrote:
Isn't that what I say I'm doing earlier, when I say I create a
XMLDocument, create a base node and then try to create subnodes. I'm
not dealing with 2 documents, I'm only dealing with one (mBOEDoc) but
with several nodes within it.


Why do you use
mboedoc.createn ode(xml.XmlNode Type.Document, "BOETask", "")
^^^^^^^^^^^^^^^ ^^^^^^^^^
then, that looks to me like creating a second document and that is why
you get the error later.
--

Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/
Nov 12 '05 #6

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

Similar topics

1
567
by: Mike | last post by:
When trying to compile (using Visual Web Developer 2005 Express Beta; frameworkv2.0.50215 ) the source code below I get errors (listed below due to the use of ICallBackEventHandler. Ultimately I want to use a callback from the client side to update webcontrols based on user input without using postback. I am seeking a way to stop the compile errors. using System; using System.Data;
2
55637
by: Eirik M. | last post by:
Hi, I've got the following piece of code that's causing me a bit of a problem XmlDocument doc = new XmlDocument (); XmlNode rootNode = doc.CreateNode (XmlNodeType.Element, "usersettings", null); User user = new User (userid); XmlNode rolesNode = user.GetRoles (); rootNode.AppendChild (rolesNode);
8
488
by: chris yoker via DotNetMonster.com | last post by:
hiya, I succesfully return a "nodeList" thru the "xmlDoc.SelectNodes" method. This nodeList is taken from a repetitive, uniform xml doc. I can successfully append a child node at the correct position using the following code: <code> <!--Node successfully inserted into corrrect position in nodeList(0)--> nodeList(0).InsertAfter(additionalNode, nodeList(0).ChildNodes(5))
6
4759
by: Peter Frost | last post by:
Please help I don't know if this is possible but what I would really like to do is to use On Error Goto to capture the code that is being executed when an error occurs. Any help would be much appreciated. Thanks in advance
5
1353
by: Brian | last post by:
Can someone show me how to append an XMLElement from one XMLDocument as a child to an element in another XMLDocument? ( In one line of code please ) I used to be able to say : MyNode.AppendChild(OtherDoc.DocumentElement) No more in Dot Net.
2
3192
by: Shaurya Vardhan | last post by:
Hi, On Appending a child in XML Node, I am having error, "Run-time exception thrown : System.ArgumentException - The node to be inserted is from a different document context." How to resolve this ? I am attaching image of error message. Thanx & Regards, Shaurya Vardhan
1
3178
by: Davidoff | last post by:
Hi How is it possible to copy or clone a node from a given document to an other document . Here is my method : static void test(XmlDocument doc1,XmlDocument doc2) {
6
2015
by: Derek Hart | last post by:
I bring in an xml file into vb.net by using xmlDoc.LoadXml(XMLString) - I run xpath statements against the xml file to grab data from it, so I use, as an example, //Vehicles/Vehicles/@make to get the make of the car. But then I pass a specific node from xmlDoc into another function, not the whole xmlDoc, just a node from it. And if I run an xpath against it, I have to use .// (has a period at the beginning) so it does not grab info from...
7
3358
by: dennis.sprengers | last post by:
I am trying to write an editor object, which adds some functionality and a toolbar to every textarea with a "form-textarea" class. Both FF and IE generate an error in line 20 (container.appendChild(this.toolbar);) saying "Node cannot be inserted at the specified point in the hierarchy" code: "3" I have two questions: - who would help me with this error - please provide other feedback about my code, since I want to write a solid...
0
9528
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
10455
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10006
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...
0
9052
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7547
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
5573
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4116
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3731
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2925
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.