* xmlDOMWrapAdoptNode: * @ctxt: the optional context for custom processing * @sourceDoc: the optional sourceDoc * @node: the node to start with * @destDoc: the destination doc * @destParent: the optional new parent of @node in @destDoc * @options: option flags * * References of out-of scope ns-decls are remapped to point to @destDoc: * 1) If @destParent is given, then nsDef entries on element-node
| 9847 | * -1 on API/internal errors. |
| 9848 | */ |
| 9849 | int |
| 9850 | xmlDOMWrapAdoptNode(xmlDOMWrapCtxtPtr ctxt, |
| 9851 | xmlDocPtr sourceDoc, |
| 9852 | xmlNodePtr node, |
| 9853 | xmlDocPtr destDoc, |
| 9854 | xmlNodePtr destParent, |
| 9855 | int options) |
| 9856 | { |
| 9857 | int ret = 0; |
| 9858 | |
| 9859 | if ((node == NULL) || (node->type == XML_NAMESPACE_DECL) || |
| 9860 | (destDoc == NULL) || |
| 9861 | ((destParent != NULL) && (destParent->doc != destDoc))) |
| 9862 | return(-1); |
| 9863 | /* |
| 9864 | * Check node->doc sanity. |
| 9865 | */ |
| 9866 | if (sourceDoc == NULL) { |
| 9867 | sourceDoc = node->doc; |
| 9868 | } else if (node->doc != sourceDoc) { |
| 9869 | return (-1); |
| 9870 | } |
| 9871 | |
| 9872 | /* |
| 9873 | * TODO: Shouldn't this be allowed? |
| 9874 | */ |
| 9875 | if (sourceDoc == destDoc) |
| 9876 | return (-1); |
| 9877 | |
| 9878 | switch (node->type) { |
| 9879 | case XML_ELEMENT_NODE: |
| 9880 | case XML_ATTRIBUTE_NODE: |
| 9881 | case XML_TEXT_NODE: |
| 9882 | case XML_CDATA_SECTION_NODE: |
| 9883 | case XML_ENTITY_REF_NODE: |
| 9884 | case XML_PI_NODE: |
| 9885 | case XML_COMMENT_NODE: |
| 9886 | break; |
| 9887 | case XML_DOCUMENT_FRAG_NODE: |
| 9888 | /* TODO: Support document-fragment-nodes. */ |
| 9889 | return (2); |
| 9890 | default: |
| 9891 | return (1); |
| 9892 | } |
| 9893 | /* |
| 9894 | * Unlink only if @node was not already added to @destParent. |
| 9895 | */ |
| 9896 | if ((node->parent != NULL) && (destParent != node->parent)) |
| 9897 | xmlUnlinkNodeInternal(node); |
| 9898 | |
| 9899 | if (node->type == XML_ELEMENT_NODE) { |
| 9900 | return (xmlDOMWrapAdoptBranch(ctxt, sourceDoc, node, |
| 9901 | destDoc, destParent, options)); |
| 9902 | } else if (node->type == XML_ATTRIBUTE_NODE) { |
| 9903 | return (xmlDOMWrapAdoptAttr(ctxt, sourceDoc, |
| 9904 | (xmlAttrPtr) node, destDoc, destParent, options)); |
| 9905 | } else { |
| 9906 | if (node->doc != destDoc) { |
nothing calls this directly
no test coverage detected