* xmlDOMWrapAdoptAttr: * @ctxt: the optional context for custom processing * @sourceDoc: the optional source document of attr * @attr: the attribute-node to be adopted * @destDoc: the destination doc for adoption * @destParent: the optional new parent of @attr in @destDoc * @options: option flags * * @attr is adopted by @destDoc. * Ensures that ns-references point to @destDoc: either to * elements
| 9768 | * Returns 0 if succeeded, -1 otherwise and on API/internal errors. |
| 9769 | */ |
| 9770 | static int |
| 9771 | xmlDOMWrapAdoptAttr(xmlDOMWrapCtxtPtr ctxt, |
| 9772 | xmlDocPtr sourceDoc ATTRIBUTE_UNUSED, |
| 9773 | xmlAttrPtr attr, |
| 9774 | xmlDocPtr destDoc, |
| 9775 | xmlNodePtr destParent, |
| 9776 | int options ATTRIBUTE_UNUSED) |
| 9777 | { |
| 9778 | int ret = 0; |
| 9779 | |
| 9780 | if ((attr == NULL) || (destDoc == NULL)) |
| 9781 | return (-1); |
| 9782 | |
| 9783 | if (attr->doc != destDoc) { |
| 9784 | if (xmlSetTreeDoc((xmlNodePtr) attr, destDoc) < 0) |
| 9785 | ret = -1; |
| 9786 | } |
| 9787 | |
| 9788 | if (attr->ns != NULL) { |
| 9789 | xmlNsPtr ns = NULL; |
| 9790 | |
| 9791 | if (ctxt != NULL) { |
| 9792 | /* TODO: User defined. */ |
| 9793 | } |
| 9794 | /* XML Namespace. */ |
| 9795 | if (IS_STR_XML(attr->ns->prefix)) { |
| 9796 | ns = xmlTreeEnsureXMLDecl(destDoc); |
| 9797 | } else if (destParent == NULL) { |
| 9798 | /* |
| 9799 | * Store in @destDoc->oldNs. |
| 9800 | */ |
| 9801 | ns = xmlDOMWrapStoreNs(destDoc, attr->ns->href, attr->ns->prefix); |
| 9802 | } else { |
| 9803 | /* |
| 9804 | * Declare on @destParent. |
| 9805 | */ |
| 9806 | if (xmlSearchNsByNamespaceStrict(destDoc, destParent, attr->ns->href, |
| 9807 | &ns, 1) == -1) |
| 9808 | ret = -1; |
| 9809 | if (ns == NULL) { |
| 9810 | ns = xmlDOMWrapNSNormDeclareNsForced(destDoc, destParent, |
| 9811 | attr->ns->href, attr->ns->prefix, 1); |
| 9812 | } |
| 9813 | } |
| 9814 | if (ns == NULL) |
| 9815 | ret = -1; |
| 9816 | attr->ns = ns; |
| 9817 | } |
| 9818 | |
| 9819 | return (ret); |
| 9820 | } |
| 9821 | |
| 9822 | /* |
| 9823 | * xmlDOMWrapAdoptNode: |
no test coverage detected