473,804 Members | 2,271 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Error in Appending XML Element

Hi,
On Appending a child in XML Node,
I am having error, "Run-time exception thrown : System.Argument Exception -
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

--------------------------------------------------------------------------------

Nov 20 '05 #1
2 3192
Cor
Hi Shaurya,

Maybe if you send some code someone can help you.
(Only the part of the error and then first pasted in a notebook copied and
than in the mail, otherwise it is mostly unreadable)

Cor
Nov 20 '05 #2


each xmlDocument has its own 'context'. you cannot add a node from
xmlDoc1 to xmlDoc2.

I needed it for small documents, so I created a xmlDoc3 and added to it
the nodes I needed from xmlDoc1 and xmlDoc2:

' --------------------------------------------
Public Shared Function mcXNodeListsApp end(ByVal xL1 As
XmlNodeList, ByVal xL2 As XmlNodeList) As System.Xml.XmlN odeList
' -----------------------------------------------
' Description: Append two XmlNodeLists into one list.
' I cannot simply append nodes, because of exception - "The node
to be inserted
' is from a different document context", So, I create a 3rd
list, and import
' each node from both original nodeLists to the 3rd one.
' ----------------------------------------------

'-- Create a new xmlDocument with one root node.
Dim tempDoc As New XmlDocument()
tempDoc.LoadXml (("<xxRoot></xxRoot>"))

Dim tempNode As XmlNode
Dim tempFragment As XmlDocumentFrag ment =
tempDoc.CreateD ocumentFragment ()

Dim maxI As Integer
Dim i As Integer

'-- Add childs to the root from both lists.
'-- Get xL1 elements:
If Not (xL1 Is Nothing) Then
maxI = xL1.Count
If (maxI > 0) Then
For i = 1 To maxI
tempNode = tempDoc.ImportN ode(xL1.Item(i - 1), True)
tempDoc.Documen tElement.Append Child(tempNode)
Next i
End If
End If

'-- Get xL2 elements:
If Not (xL2 Is Nothing) Then
maxI = xL2.Count
If (maxI > 0) Then
For i = 1 To maxI
tempNode = tempDoc.ImportN ode(xL2.Item(i - 1), True)
tempDoc.Documen tElement.Append Child(tempNode)
Next i
End If
End If

'-- Return the root ChildNodes.
Return tempDoc.FirstCh ild.ChildNodes

End Function
*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 20 '05 #3

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

Similar topics

4
18189
by: Jesper Stocholm | last post by:
I have a database class that maintains data about customers i my system. The basic XML for this looks like: <Chunk> <Vendor> <Database/> </Vendor> </Chunk> When a user is to be registrered in the system, XML like this is created
2
2849
by: kbperry | last post by:
Hi all, I am getting an error message when trying to use the P4 print command via the python api for perforce. Anytime that I run p4c.run("print","-q", eachFile), I keep getting an error message: "AttributeError: OutputBinary." Here is my code below: Please Help.
1
2304
by: Ron Adam | last post by:
In my program I have a lot of statements that append elements, but sometimes I don't want to append the element so it requres an if statement to check it, and that requires assigning the returned element from a function to a name or calling the funtion twice. e = ET.Element('name') e.append(get_subelement(obj)) # but raises an exception on None
3
565
by: Jim | last post by:
Could anyone please point me towards some code that allows me to add to an existing XML file using the output of an HTML form. I want to add a form on my website so users can input their email address in a text field and feedback in a text area and then submit it. I can output the data no probs but appending it first to the XML file is proving tricky. Any ideas?
1
9485
by: kamleshsharmadts | last post by:
I am using Ajax with struts in web application. from jsp i am calling a function of ajax.js onclick of a button. code of that call function which calling from jsp given as below:- onclick="retrieveURL('/application/home_page.do?processAction=ItinerarySearch','AfoHomeForm')" after clicking on button i am getting following error:- object does not support this property or method at statement (Which i have made it bold in js file)
5
5562
by: toton | last post by:
Hi, I want to append one vector after another. so like, vector<intv1; ///put some elements to v2. I have a second vector vector<intv2; ///it has some elements. Now I do v1.reserve(v1.size() + v2.size()) ; and then
7
9510
by: Daz | last post by:
Hi everyone! Is it possible to take a line of text like so: <tr><td>title1</td><td>title2</td><td>title3</td><td>title4</td></tr> And append it to a DOM node such as this: var nodeToAppendTo = document.getElementById('tbody');
2
17400
by: pbd22 | last post by:
Hi. I have an event handler in VB.NET that gets called several times. The output of the event handler is XML that is being called by an xmlhttp request from the client. I am using a stringbuilder to create the XML document by appending the various parts: sbhtml.Append("<Some XML Tag>")
1
3793
by: ofuuzo1 | last post by:
Hi, Is there anyway I can append a new element to an existing xml without first loading the existing file into a variable, adding the new element into the variable and saving it by overwriting the existing file name? Thanks Ofuuzo
0
9714
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
9594
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
10599
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
10346
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...
1
10347
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10090
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
7635
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...
1
4308
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
3832
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.