473,387 Members | 1,891 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,387 software developers and data experts.

Error in Appending XML Element

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

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

Nov 20 '05 #1
2 3174
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 mcXNodeListsAppend(ByVal xL1 As
XmlNodeList, ByVal xL2 As XmlNodeList) As System.Xml.XmlNodeList
' -----------------------------------------------
' 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 XmlDocumentFragment =
tempDoc.CreateDocumentFragment()

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.ImportNode(xL1.Item(i - 1), True)
tempDoc.DocumentElement.AppendChild(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.ImportNode(xL2.Item(i - 1), True)
tempDoc.DocumentElement.AppendChild(tempNode)
Next i
End If
End If

'-- Return the root ChildNodes.
Return tempDoc.FirstChild.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
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...
2
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...
1
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...
3
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...
1
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:- ...
5
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()...
7
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...
2
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...
1
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...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
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,...
0
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...
0
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,...
0
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...

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.