Link to home
Create AccountLog in
Avatar of Midwest
MidwestFlag for United States of America

asked on

IE 9 Type Mismatch with importNode

I am receiving a 'type mismatch' error in Internet Explorer 9 when working with XML  trying to append child after using importNode.  I realize the problem is that the ownerDocuments of parent and node are not the same and importNode is complaining. How can I get around this?  It works in all other browsers including previous versions of IE.

parent.appendChild(parent.ownerDocument.importNode(node, children));

Open in new window


Here are some resources I found:
http://www.w3.org/DOM/faq.html#ownerdoc

ownerDocument issues
Must a Node always be owned by a specific Document?
Yes. DOM Level 1 decided that ownerDocument is set at the time the node is created, and never reset thereafter.
Why?
Different DOMs may implement Nodes in completely different ways, and the implementation details may not be compatable even though both support the same public APIs. This can be true even within a single DOM implementation, since it may decide to use different kinds of Node in order to provide special behaviors for particular kinds of documents (perhaps guided by DTD/Schema or Namespace information). Thus, attempting to move a Node from one Document to another would be non-portable at best, and the DOM throws a DOMException (WRONG_DOCUMENT_ERR) when you attempt to do so. Exposing ownerDocument introduced no additional constraints... and added significant value, e.g. by allowing you to write myNode.appendChild(myNode.getOwnerDocument().createTextNode("new child")); even when myNode is not currently part of the Document's main tree.
What is the ownerDocument of a newly cloned node?
The clone will be owned by the same Document as the node it was cloned from.
What should parent.appendChild(newchild.clonenode(true)) do if parent and newchild have different ownerDocument values?
The DOM Recommendation specifies that appendChild Mustthrow DOMException (WRONG_DOCUMENT_ERR) if an attempt is made to insert a node from one ownerDocument into a tree with a different ownerDocument. Some DOM implementations may allow this code fragment to work in specific circumstances, when they know that the underlying representation of the nodes is compatable, but that is considered non-compliant behavior.
How can I copy a node or subtree from one document to another?
DOM Level 2 defines an importNode() method that performs this operation. It is up to the implementation to do this in a standard way that works across implementations or in a more efficient way that uses knowledge of that implementation's data structures. If you're working with a Level 1 DOM, you have to copy the content manually.
How can I move a node from one document to another?
DOM Level 3 defines an adoptNode() method that performs this operation.

http://social.msdn.microsoft.com/Forums/en/xmlandnetfx/thread/98e9d45a-d46f-4ed1-9875-4752d936c04c
The latest MSXML versions have importNode but only to import nodes from one MSXML document to another.
ASKER CERTIFIED SOLUTION
Avatar of imantas
imantas
Flag of Lithuania image

Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
See answer
Avatar of Midwest

ASKER

thanks