A random collection of epiphanies, thoughts and problem solutions pertaining to .NET and BizTalk.

Wednesday, October 27, 2004

The node to be inserted is from a different document context


Inside your message assignment shape, if you try to do :


Construct MsgB
{
theXmlDoc.DocumentElement.AppendChild
(
xpath
(
MsgA,
"//*[local-name()='someElement']"
)
);
MsgB = theXmlDoc;
}

You will run into this error:

Event Type: Error
Event Source: XLANG/s
Event Category: None
Event ID: 10034
Date: 10/27/2004
Time: 4:13:29 PM
User: N/A
Computer: B00D059B675E2
Description:
Uncaught exception terminated service A, instance B

The node to be inserted is from a different document context.

Exception type: ArgumentException
Source: System.Xml
Target Site: System.Xml.XmlNode AppendChild(System.Xml.XmlNode)
Help Link:
Additional error information:

SOLUTION: This is because the node to be copied belongs to another Xml document and is not recognized by the destination xml document. In order to make it work, you will need to import it first. If you read MSDN's documentation for the XmlNode.AppendChild() method, you will notice the following description:

...
If the node being inserted was created from another document, you can use XmlDocument.ImportNode to import the node to the current document. The imported node can then be inserted into the current document. ...

Therefore, all you need to do is to add XmlDocument.ImportNode() method in the message assignment expression editor:



Construct MsgB
{
theXmlDoc.DocumentElement.AppendChild
(
theXmlDoc.ImportNode
(
xpath
(
MsgA,
"//*[local-name()='someElement']"
)
)
);
MsgB = theXmlDoc;
}


No comments:

Followers