虾's profileSavor the blue ...PhotosBlogLists Tools Help

Blog


    March 24

    DOM中Node的拷贝和移动问题----ownerDocument issues

    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.

    Comments

    Please wait...
    Sorry, the comment you entered is too long. Please shorten it.
    You didn't enter anything. Please try again.
    Sorry, we can't add your comment right now. Please try again later.
    To add a comment, you need permission from your parent. Ask for permission
    Your parent has turned off comments.
    Sorry, we can't delete your comment right now. Please try again later.
    You've exceeded the maximum number of comments that can be left in one day. Please try again in 24 hours.
    Your account has had the ability to leave comments disabled because our systems indicate that you may be spamming other users. If you believe that your account has been disabled in error please contact Windows Live support.
    Complete the security check below to finish leaving your comment.
    The characters you type in the security check must match the characters in the picture or audio.

    To add a comment, sign in with your Windows Live ID (if you use Hotmail, Messenger, or Xbox LIVE, you have a Windows Live ID). Sign in


    Don't have a Windows Live ID? Sign up

    Trackbacks

    The trackback URL for this entry is:
    http://javainthinking.spaces.live.com/blog/cns!B2988DE9678DF674!113.trak
    Weblogs that reference this entry
    • None