23#if defined(HAVE_LIBXML) && defined(HAVE_DOM)
40 zend_string *str = zend_string_safe_alloc(1, name_len, prefix_len + 1,
false);
50 size_t name_len =
strlen((
const char *) nodep->name);
51 if (nodep->ns !=
NULL && nodep->ns->prefix !=
NULL) {
54 ret = zend_string_init((
const char *) nodep->name, name_len,
false);
70 }
while (node !=
NULL);
84 bool uppercase =
false;
86 switch (nodep->type) {
93 case XML_NAMESPACE_DECL: {
94 xmlNsPtr ns = nodep->ns;
95 if (ns !=
NULL && ns->prefix) {
112 case XML_ENTITY_DECL:
151 switch (nodep->type) {
153 if (php_dom_follow_spec_intern(obj)) {
166 case XML_NAMESPACE_DECL: {
167 char *str = (
char *) xmlNodeGetContent(nodep->children);
192 switch (nodep->type) {
195 if (php_dom_follow_spec_intern(obj)) {
214 php_libxml_invalidate_node_list_cache(obj->
document);
247 xmlNodePtr nodeparent = nodep->parent;
248 if (!nodeparent || (only_element && nodeparent->type !=
XML_ELEMENT_NODE)) {
264 return dom_node_parent_get(obj,
retval,
false);
276 return dom_node_parent_get(obj,
retval,
true);
307 xmlNodePtr first =
NULL;
309 first = nodep->children;
347 xmlNodePtr prevsib = nodep->prev;
364 xmlNodePtr nextsib = nodep->next;
381 xmlNodePtr prevsib = nodep->prev;
384 prevsib = prevsib->prev;
402 xmlNodePtr nextsib = nodep->next;
405 nextsib = nextsib->next;
463 xmlDocPtr docp = nodep->doc;
483 const char *str =
NULL;
484 switch (nodep->type) {
487 case XML_NAMESPACE_DECL:
488 if (nodep->ns !=
NULL) {
489 str = (
const char *) nodep->ns->href;
518 const char *str =
NULL;
519 switch (nodep->type) {
522 case XML_NAMESPACE_DECL: {
523 xmlNsPtr ns = nodep->ns;
524 if (ns !=
NULL && ns->prefix) {
525 str = (
char *) ns->prefix;
546 xmlNsPtr ns = nodep->ns;
547 if (ns !=
NULL && ns->prefix !=
NULL) {
558 xmlNode *nsnode =
NULL;
559 xmlNsPtr ns =
NULL, curns;
565 switch (nodep->type) {
570 if (nsnode ==
NULL) {
571 nsnode = nodep->parent;
572 if (nsnode ==
NULL) {
573 nsnode = xmlDocGetRootElement(nodep->doc);
586 if (nsnode && nodep->ns !=
NULL && !xmlStrEqual(nodep->ns->prefix, BAD_CAST
prefix)) {
587 strURI = (
char *) nodep->ns->href;
589 if (strURI ==
NULL ||
597 curns = nsnode->nsDef;
598 while (curns !=
NULL) {
599 if (xmlStrEqual(BAD_CAST
prefix, curns->prefix) && xmlStrEqual(nodep->ns->href, curns->href)) {
606 ns = xmlNewNs(nsnode, nodep->ns->href, BAD_CAST
prefix);
657 xmlChar *baseuri = xmlNodeGetBase(nodep->doc, nodep);
662 if (php_dom_follow_spec_intern(obj)) {
663 if (nodep->doc->URL) {
684static bool dom_skip_text_content(
dom_object *obj, xmlNodePtr nodep)
686 if (php_dom_follow_spec_intern(obj)) {
687 int type = nodep->type;
701 if (dom_skip_text_content(obj, nodep)) {
714 php_libxml_invalidate_node_list_cache(obj->
document);
718 const xmlChar *xmlChars;
721 xmlChars = (
const xmlChar *)
"";
724 xmlChars = (
const xmlChar *)
Z_STRVAL_P(newval);
728 int type = nodep->type;
738 xmlNode *textNode = xmlNewDocTextLen(nodep->doc, xmlChars,
len);
739 xmlAddChild(nodep, textNode);
741 xmlNodeSetContent(nodep, xmlChars);
750static bool dom_set_document_ref_obj_single(xmlNodePtr node, php_libxml_ref_obj *document)
758 document->refcount++;
768 dom_set_document_ref_obj_single((xmlNodePtr)
attr, document);
769 for (xmlNodePtr attr_child =
attr->children; attr_child; attr_child = attr_child->next) {
770 dom_set_document_ref_obj_single(attr_child, document);
774static bool dom_set_document_ref_pointers_node(xmlNodePtr node, php_libxml_ref_obj *document)
778 if (!dom_set_document_ref_obj_single(node, document)) {
797 if (!dom_set_document_ref_pointers_node(node, document)) {
801 xmlNodePtr base = node;
802 node = node->children;
803 while (node !=
NULL && dom_set_document_ref_pointers_node(node, document)) {
804 node = php_dom_next_in_tree_order(node, base);
808static xmlNodePtr dom_insert_fragment(xmlNodePtr nodep, xmlNodePtr prevsib, xmlNodePtr nextsib, xmlNodePtr fragment,
dom_object *intern)
810 xmlNodePtr newchild = fragment->children;
813 if (prevsib ==
NULL) {
814 nodep->children = newchild;
816 prevsib->next = newchild;
818 newchild->prev = prevsib;
819 if (nextsib ==
NULL) {
820 nodep->last = fragment->last;
822 fragment->last->next = nextsib;
823 nextsib->prev = fragment->last;
827 xmlNodePtr node = newchild;
828 while (node !=
NULL) {
829 node->parent = nodep;
830 if (node == fragment->last) {
836 fragment->children =
NULL;
837 fragment->last =
NULL;
844static bool dom_node_check_legacy_insertion_validity(xmlNodePtr parentp, xmlNodePtr child,
bool stricterror,
bool warn_empty_fragment)
857 if (child->doc != parentp->doc && child->doc !=
NULL) {
897 xmlNodePtr new_child =
NULL;
900 if (!dom_node_check_legacy_insertion_validity(parentp, child, stricterror,
true)) {
904 xmlNodePtr refp =
NULL;
908 if (refp->parent != parentp) {
914 if (child->doc ==
NULL && parentp->doc !=
NULL) {
915 xmlSetTreeDoc(child, parentp->doc);
919 php_libxml_invalidate_node_list_cache(intern->
document);
922 if (child->parent !=
NULL) {
923 xmlUnlinkNode(child);
929 new_child->parent = refp->parent;
930 new_child->next = refp;
931 new_child->prev = refp->prev;
932 refp->prev = new_child;
933 if (new_child->prev !=
NULL) {
934 new_child->prev->next = new_child;
936 if (new_child->parent !=
NULL) {
937 if (new_child->parent->children == refp) {
938 new_child->parent->children = new_child;
945 if (child->ns ==
NULL)
946 lastattr = xmlHasProp(refp->parent, child->name);
948 lastattr = xmlHasNsProp(refp->parent, child->name, child->ns->href);
949 if (lastattr !=
NULL && lastattr->type != XML_ATTRIBUTE_DECL) {
950 if (lastattr != (xmlAttrPtr) child) {
951 xmlUnlinkNode((xmlNodePtr) lastattr);
952 php_libxml_node_free_resource((xmlNodePtr) lastattr);
958 new_child = xmlAddPrevSibling(refp, child);
963 xmlNodePtr
last = child->last;
964 new_child = dom_insert_fragment(parentp, refp->prev, refp, child, intern);
967 new_child = xmlAddPrevSibling(refp, child);
974 if (child->parent !=
NULL){
975 xmlUnlinkNode(child);
978 child->parent = parentp;
980 if (parentp->children ==
NULL) {
981 parentp->children = child;
982 parentp->last = child;
984 child = parentp->last;
985 child->next = new_child;
986 new_child->prev = child;
987 parentp->last = new_child;
992 if (child->ns ==
NULL)
993 lastattr = xmlHasProp(parentp, child->name);
995 lastattr = xmlHasNsProp(parentp, child->name, child->ns->href);
996 if (lastattr !=
NULL && lastattr->type != XML_ATTRIBUTE_DECL) {
997 if (lastattr != (xmlAttrPtr) child) {
998 xmlUnlinkNode((xmlNodePtr) lastattr);
999 php_libxml_node_free_resource((xmlNodePtr) lastattr);
1005 new_child = xmlAddChild(parentp, child);
1010 xmlNodePtr
last = child->last;
1011 new_child = dom_insert_fragment(parentp, parentp->last,
NULL, child, intern);
1014 new_child = xmlAddChild(parentp, child);
1033 xmlNodePtr refp =
NULL;
1042 php_libxml_invalidate_node_list_cache(intern->
document);
1050 xmlNodePtr child, parentp;
1063 dom_node_insert_before_modern(
return_value, ref, intern, parentp, child);
1065 dom_node_insert_before_legacy(
return_value, ref, intern, childobj, parentp, child);
1080static zend_result dom_replace_node_validity_checks(xmlNodePtr parent, xmlNodePtr node, xmlNodePtr child)
1095 if (child->parent != parent) {
1119 if (!parent_is_document && node->type ==
XML_DTD_NODE) {
1127 if (parent_is_document) {
1137 if (xmlDocGetRootElement((xmlDocPtr) parent) != child) {
1150 xmlDocPtr doc = (xmlDocPtr) parent;
1170 zval *id, *newnode, *oldnode;
1171 xmlNodePtr newchild, oldchild, nodep;
1172 dom_object *intern, *newchildobj, *oldchildobj;
1181 DOM_GET_OBJ(newchild, newnode, xmlNodePtr, newchildobj);
1182 DOM_GET_OBJ(oldchild, oldnode, xmlNodePtr, oldchildobj);
1186 if (newchild->doc != nodep->doc && newchild->doc !=
NULL) {
1192 if (dom_replace_node_validity_checks(nodep, newchild, oldchild) !=
SUCCESS) {
1200 if (!nodep->children) {
1204 if (!dom_node_check_legacy_insertion_validity(nodep, newchild, stricterror,
false)) {
1215 if (oldchild->parent != nodep) {
1221 if (newchild->doc ==
NULL && nodep->doc !=
NULL) {
1222 xmlSetTreeDoc(newchild, nodep->doc);
1227 xmlNodePtr prevsib, nextsib;
1228 prevsib = oldchild->prev;
1229 nextsib = oldchild->next;
1231 xmlUnlinkNode(oldchild);
1233 xmlNodePtr
last = newchild->last;
1234 newchild = dom_insert_fragment(nodep, prevsib, nextsib, newchild, intern);
1235 if (newchild && !modern) {
1238 }
else if (oldchild != newchild) {
1239 xmlDtdPtr intSubset = xmlGetIntSubset(nodep->doc);
1240 bool replacedoctype = (intSubset == (xmlDtd *) oldchild);
1242 xmlReplaceNode(oldchild, newchild);
1247 if (replacedoctype) {
1248 nodep->doc->intSubset = (xmlDtd *) newchild;
1251 php_libxml_invalidate_node_list_cache(intern->
document);
1272 xmlNodePtr child, nodep;
1285 if (!nodep->children || child->parent != nodep) {
1296 xmlUnlinkNode(child);
1297 php_libxml_invalidate_node_list_cache(intern->
document);
1318 xmlNodePtr new_child =
NULL;
1326 if (!dom_node_check_legacy_insertion_validity(nodep, child, stricterror,
true)) {
1330 if (child->doc ==
NULL && nodep->doc !=
NULL) {
1331 xmlSetTreeDoc(child, nodep->doc);
1335 if (child->parent !=
NULL){
1336 xmlUnlinkNode(child);
1340 child->parent = nodep;
1342 if (nodep->children ==
NULL) {
1343 nodep->children = child;
1344 nodep->last = child;
1346 child = nodep->last;
1347 child->next = new_child;
1348 new_child->prev = child;
1349 nodep->last = new_child;
1352 xmlAttrPtr lastattr;
1354 if (child->ns ==
NULL)
1355 lastattr = xmlHasProp(nodep, child->name);
1357 lastattr = xmlHasNsProp(nodep, child->name, child->ns->href);
1358 if (lastattr !=
NULL && lastattr->type != XML_ATTRIBUTE_DECL) {
1359 if (lastattr != (xmlAttrPtr) child) {
1360 xmlUnlinkNode((xmlNodePtr) lastattr);
1361 php_libxml_node_free_resource((xmlNodePtr) lastattr);
1364 new_child = xmlAddChild(nodep, child);
1370 xmlNodePtr
last = child->last;
1371 new_child = dom_insert_fragment(nodep, nodep->last,
NULL, child, intern);
1374 if (nodep->doc->intSubset !=
NULL) {
1378 new_child = xmlAddChild(nodep, child);
1382 nodep->doc->intSubset = (xmlDtdPtr) new_child;
1384 new_child = xmlAddChild(nodep, child);
1391 php_libxml_invalidate_node_list_cache(intern->
document);
1404 xmlNodePtr nodep, child;
1414 dom_node_append_child_legacy(
return_value, intern, childobj, nodep, child);
1420 xmlNodePtr nodep, child;
1437 php_libxml_invalidate_node_list_cache(intern->document);
1477 if (php_dom_follow_spec_intern(intern)) {
1478 if (clone_document) {
1481 private_data = php_dom_get_private_data(intern);
1488 if (clone_document && private_data !=
NULL) {
1495 if (clone_document) {
1537 if (php_dom_follow_spec_intern(intern)) {
1582 xmlNodePtr nodeotherp, nodep;
1587 DOM_GET_OBJ(nodeotherp, node, xmlNodePtr, nodeotherobj);
1589 if (nodep == nodeotherp) {
1621static bool php_dom_node_is_content_equal(
const xmlNode *
this,
const xmlNode *other)
1623 xmlChar *this_content = xmlNodeGetContent(
this);
1624 xmlChar *other_content = xmlNodeGetContent(other);
1625 bool result = xmlStrEqual(this_content, other_content);
1626 xmlFree(this_content);
1627 xmlFree(other_content);
1631static bool php_dom_node_is_ns_uri_equal(
const xmlNode *
this,
const xmlNode *other)
1633 const xmlChar *this_ns = this->ns ? this->ns->href :
NULL;
1634 const xmlChar *other_ns = other->ns ? other->ns->href :
NULL;
1635 return xmlStrEqual(this_ns, other_ns);
1638static bool php_dom_node_is_ns_prefix_equal(
const xmlNode *
this,
const xmlNode *other)
1640 const xmlChar *this_ns = this->ns ? this->ns->prefix :
NULL;
1641 const xmlChar *other_ns = other->ns ? other->ns->prefix :
NULL;
1642 return xmlStrEqual(this_ns, other_ns);
1645static bool php_dom_node_is_equal_node(
const xmlNode *
this,
const xmlNode *other,
bool spec_compliant);
1647#define PHP_DOM_FUNC_CAT(prefix, suffix) prefix##_##suffix
1649#define PHP_DOM_DEFINE_LIST_COUNTER_HELPER(type) \
1650 static size_t PHP_DOM_FUNC_CAT(php_dom_node_count_list_size, type)(const type *node) \
1652 size_t counter = 0; \
1655 node = node->next; \
1659#define PHP_DOM_DEFINE_LIST_EQUALITY_ORDERED_HELPER(type) \
1660 static bool PHP_DOM_FUNC_CAT(php_dom_node_list_equality_check_ordered, type)(const type *list1, const type *list2, bool spec_compliant) \
1662 size_t count = PHP_DOM_FUNC_CAT(php_dom_node_count_list_size, type)(list1); \
1663 if (count != PHP_DOM_FUNC_CAT(php_dom_node_count_list_size, type)(list2)) { \
1666 for (size_t i = 0; i < count; i++) { \
1667 if (!php_dom_node_is_equal_node((const xmlNode *) list1, (const xmlNode *) list2, spec_compliant)) { \
1670 list1 = list1->next; \
1671 list2 = list2->next; \
1675#define PHP_DOM_DEFINE_LIST_EQUALITY_UNORDERED_HELPER(type) \
1676 static bool PHP_DOM_FUNC_CAT(php_dom_node_list_equality_check_unordered, type)(const type *list1, const type *list2, bool spec_compliant)\
1678 size_t count = PHP_DOM_FUNC_CAT(php_dom_node_count_list_size, type)(list1); \
1679 if (count != PHP_DOM_FUNC_CAT(php_dom_node_count_list_size, type)(list2)) { \
1682 for (const type *n1 = list1; n1 != NULL; n1 = n1->next) { \
1683 bool found = false; \
1684 for (const type *n2 = list2; n2 != NULL && !found; n2 = n2->next) { \
1685 if (php_dom_node_is_equal_node((const xmlNode *) n1, (const xmlNode *) n2, spec_compliant)) { \
1696PHP_DOM_DEFINE_LIST_COUNTER_HELPER(xmlNode)
1697PHP_DOM_DEFINE_LIST_COUNTER_HELPER(xmlNs)
1698PHP_DOM_DEFINE_LIST_EQUALITY_ORDERED_HELPER(xmlNode)
1699PHP_DOM_DEFINE_LIST_EQUALITY_UNORDERED_HELPER(xmlNode)
1700PHP_DOM_DEFINE_LIST_EQUALITY_UNORDERED_HELPER(xmlNs)
1702static bool php_dom_is_equal_attr(
const xmlAttr *this_attr,
const xmlAttr *other_attr)
1706 return xmlStrEqual(this_attr->name, other_attr->name)
1707 && php_dom_node_is_ns_uri_equal((
const xmlNode *) this_attr, (
const xmlNode *) other_attr)
1708 && php_dom_node_is_content_equal((
const xmlNode *) this_attr, (
const xmlNode *) other_attr);
1711static bool php_dom_node_is_equal_node(
const xmlNode *
this,
const xmlNode *other,
bool spec_compliant)
1716 if (this->type != other->type) {
1724 return xmlStrEqual(this->name, other->name)
1725 && php_dom_node_is_ns_prefix_equal(
this, other)
1726 && php_dom_node_is_ns_uri_equal(
this, other)
1728 && php_dom_node_list_equality_check_unordered_xmlNode((
const xmlNode *) this->properties, (
const xmlNode *) other->properties, spec_compliant)
1729 && (spec_compliant || php_dom_node_list_equality_check_unordered_xmlNs(this->nsDef, other->nsDef,
false))
1730 && php_dom_node_list_equality_check_ordered_xmlNode(this->children, other->children, spec_compliant);
1733 const xmlDtd *this_dtd = (
const xmlDtd *)
this;
1734 const xmlDtd *other_dtd = (
const xmlDtd *) other;
1735 return xmlStrEqual(this_dtd->name, other_dtd->name)
1736 && xmlStrEqual(this_dtd->ExternalID, other_dtd->ExternalID)
1737 && xmlStrEqual(this_dtd->SystemID, other_dtd->SystemID);
1739 return xmlStrEqual(this->name, other->name) && xmlStrEqual(this->content, other->content);
1741 return xmlStrEqual(this->content, other->content);
1743 const xmlAttr *this_attr = (
const xmlAttr *)
this;
1744 const xmlAttr *other_attr = (
const xmlAttr *) other;
1745 return php_dom_is_equal_attr(this_attr, other_attr);
1747 return xmlStrEqual(this->name, other->name);
1749 const xmlEntity *this_entity = (
const xmlEntity *)
this;
1750 const xmlEntity *other_entity = (
const xmlEntity *) other;
1751 return this_entity->etype == other_entity->etype
1752 && xmlStrEqual(this_entity->name, other_entity->name)
1753 && xmlStrEqual(this_entity->ExternalID, other_entity->ExternalID)
1754 && xmlStrEqual(this_entity->SystemID, other_entity->SystemID)
1755 && php_dom_node_is_content_equal(
this, other);
1756 }
else if (this->type == XML_NAMESPACE_DECL) {
1757 const xmlNs *this_ns = (
const xmlNs *)
this;
1758 const xmlNs *other_ns = (
const xmlNs *) other;
1759 return xmlStrEqual(this_ns->prefix, other_ns->prefix) && xmlStrEqual(this_ns->href, other_ns->href);
1761 return php_dom_node_list_equality_check_ordered_xmlNode(this->children, other->children, spec_compliant);
1774 xmlNodePtr otherp, nodep;
1789 if (nodep == otherp) {
1794 if (nodep ==
NULL || otherp ==
NULL) {
1798 RETURN_BOOL(php_dom_node_is_equal_node(nodep, otherp, modern));
1813static const xmlChar *dom_locate_a_namespace_prefix(xmlNodePtr elem,
const char *uri)
1817 if (elem->ns !=
NULL && elem->ns->prefix !=
NULL && xmlStrEqual(elem->ns->href, BAD_CAST uri)) {
1818 return elem->ns->prefix;
1825 && xmlStrEqual(
attr->ns->prefix, BAD_CAST
"xmlns") && xmlStrEqual(
attr->children->content, BAD_CAST uri)) {
1831 elem = elem->parent;
1845 xmlNodePtr nodep, lookupp =
NULL;
1861 switch (nodep->type) {
1867 lookupp = xmlDocGetRootElement((xmlDocPtr) nodep);
1877 lookupp = nodep->parent;
1880 if (lookupp !=
NULL) {
1882 const char *
result = (
const char *) dom_locate_a_namespace_prefix(lookupp, uri);
1887 nsptr = xmlSearchNsByHref(lookupp->doc, lookupp, BAD_CAST uri);
1888 if (nsptr && nsptr->prefix !=
NULL) {
1929 return (
const char *) node->ns->href;
1941 if (
attr->children !=
NULL &&
attr->children->content[0] !=
'\0') {
1942 return (
const char *)
attr->children->content;
1955 node = node->parent;
1959 node = xmlDocGetRootElement((xmlDocPtr) node);
2000 nodep = xmlDocGetRootElement((xmlDocPtr) nodep);
2001 if (nodep == NULL) {
2006 nsptr = xmlSearchNs(nodep->doc, nodep,
NULL);
2007 if (nsptr && xmlStrEqual(nsptr->href, BAD_CAST uri)) {
2033 RETURN_BOOL(xmlStrEqual(BAD_CAST uri, BAD_CAST ns_uri));
2056 if (php_dom_follow_spec_intern(intern)) {
2061 if (ns_uri ==
NULL) {
2068 nodep = xmlDocGetRootElement((xmlDocPtr) nodep);
2069 if (nodep ==
NULL) {
2075 if (nsptr && nsptr->href !=
NULL) {
2084static int dom_canonicalize_node_parent_lookup_cb(
void *user_data, xmlNodePtr node, xmlNodePtr parent)
2086 xmlNodePtr root = user_data;
2093 while (node !=
NULL) {
2097 node = node->parent;
2109 xmlNodeSetPtr nodeset =
NULL;
2111 bool exclusive=0, with_comments=0;
2112 xmlChar **inclusive_ns_prefixes =
NULL;
2115 size_t file_len = 0;
2116 xmlOutputBufferPtr
buf;
2117 xmlXPathContextPtr ctxp=
NULL;
2118 xmlXPathObjectPtr xpathobjp=
NULL;
2123 "|bba!a!", &exclusive, &with_comments,
2124 &xpath_array, &ns_prefixes) ==
FAILURE) {
2129 "s|bba!a!", &
file, &file_len, &exclusive,
2130 &with_comments, &xpath_array, &ns_prefixes) ==
FAILURE) {
2144 bool simple_node_parent_lookup_callback =
false;
2145 if (xpath_array ==
NULL) {
2148 simple_node_parent_lookup_callback =
true;
2157 tmp = zend_hash_find_deref(
ht,
ZSTR_KNOWN(ZEND_STR_QUERY));
2170 ctxp = xmlXPathNewContext(docp);
2173 tmp = zend_hash_str_find_deref(
ht,
"namespaces",
sizeof(
"namespaces")-1);
2188 xpathobjp = xmlXPathEvalExpression(BAD_CAST xquery, ctxp);
2190 if (xpathobjp && xpathobjp->type == XPATH_NODESET) {
2191 nodeset = xpathobjp->nodesetval;
2194 xmlXPathFreeObject(xpathobjp);
2196 xmlXPathFreeContext(ctxp);
2202 if (ns_prefixes !=
NULL) {
2208 sizeof(xmlChar *), 0);
2212 inclusive_ns_prefixes[nscount++] = BAD_CAST
Z_STRVAL_P(tmpns);
2215 inclusive_ns_prefixes[nscount] =
NULL;
2218 "Inclusive namespace prefixes only allowed in exclusive mode.");
2223 buf = xmlOutputBufferCreateFilename(
file,
NULL, 0);
2225 buf = xmlAllocOutputBuffer(
NULL);
2229 if (simple_node_parent_lookup_callback) {
2230 ret = xmlC14NExecute(docp, dom_canonicalize_node_parent_lookup_cb, nodep, exclusive, inclusive_ns_prefixes, with_comments,
buf);
2232 ret = xmlC14NDocSaveTo(docp, nodeset, exclusive, inclusive_ns_prefixes, with_comments,
buf);
2236 if (inclusive_ns_prefixes !=
NULL) {
2237 efree(inclusive_ns_prefixes);
2239 if (xpathobjp !=
NULL) {
2240 xmlXPathFreeObject(xpathobjp);
2243 xmlXPathFreeContext(ctxp);
2250 size_t size = xmlOutputBufferGetSize(
buf);
2262 bytes = xmlOutputBufferClose(
buf);
2263 if (
mode == 1 && (
ret >= 0)) {
2296 value = (
char *) xmlGetNodePath(nodep);
2340static bool dom_node_contains(xmlNodePtr thisp, xmlNodePtr otherp)
2343 if (otherp == thisp) {
2346 otherp = otherp->parent;
2355 xmlNodePtr otherp, thisp;
2371 DOM_GET_OBJ(otherp, other, xmlNodePtr, unused_intern);
2380 xmlNodePtr otherp, thisp;
2391 DOM_GET_OBJ(otherp, other, xmlNodePtr, unused_intern);
2416 while (thisp->parent) {
2417 thisp = thisp->parent;
2428#define DOCUMENT_POSITION_DISCONNECTED 0x01
2429#define DOCUMENT_POSITION_PRECEDING 0x02
2430#define DOCUMENT_POSITION_FOLLOWING 0x04
2431#define DOCUMENT_POSITION_CONTAINS 0x08
2432#define DOCUMENT_POSITION_CONTAINED_BY 0x10
2433#define DOCUMENT_POSITION_IMPLEMENTATION_SPECIFIC 0x20
2437 zval *id, *node_zval;
2438 xmlNodePtr other,
this;
2446 DOM_GET_OBJ(other, node_zval, xmlNodePtr, other_intern);
2449 if (this == other) {
2454 xmlNodePtr node1 = other;
2455 xmlNodePtr node2 =
this;
2458 xmlNodePtr attr1 =
NULL;
2459 xmlNodePtr attr2 =
NULL;
2464 node1 = attr1->parent;
2471 node2 = attr2->parent;
2474 if (attr1 !=
NULL && node1 !=
NULL && node2 == node1) {
2476 if (php_dom_is_equal_attr(
attr, (
const xmlAttr *) attr1)) {
2477 RETURN_LONG(DOCUMENT_POSITION_IMPLEMENTATION_SPECIFIC | DOCUMENT_POSITION_PRECEDING);
2478 }
else if (php_dom_is_equal_attr(
attr, (
const xmlAttr *) attr2)) {
2479 RETURN_LONG(DOCUMENT_POSITION_IMPLEMENTATION_SPECIFIC | DOCUMENT_POSITION_FOLLOWING);
2488 if (node1 ==
NULL || node2 ==
NULL) {
2491 bool node2_is_ancestor_of_node1 =
false;
2492 size_t node1_depth = 0;
2493 xmlNodePtr node1_root = node1;
2494 while (node1_root->parent) {
2495 node1_root = node1_root->parent;
2496 if (node1_root == node2) {
2497 node2_is_ancestor_of_node1 =
true;
2501 bool node1_is_ancestor_of_node2 =
false;
2502 size_t node2_depth = 0;
2503 xmlNodePtr node2_root = node2;
2504 while (node2_root->parent) {
2505 node2_root = node2_root->parent;
2506 if (node2_root == node1) {
2507 node1_is_ancestor_of_node2 =
true;
2512 if (node1_root != node2_root) {
2517 if ((node1_is_ancestor_of_node2 && attr1 ==
NULL) || (node1 == node2 && attr2 !=
NULL)) {
2518 RETURN_LONG(DOCUMENT_POSITION_CONTAINS | DOCUMENT_POSITION_PRECEDING);
2522 if ((node2_is_ancestor_of_node1 && attr2 ==
NULL) || (node1 == node2 && attr1 !=
NULL)) {
2523 RETURN_LONG(DOCUMENT_POSITION_CONTAINED_BY | DOCUMENT_POSITION_FOLLOWING);
2531 if (node1_is_ancestor_of_node2) {
2534 }
else if (node2_is_ancestor_of_node1) {
2547 if (node1_depth > node2_depth) {
2549 node1 = node1->parent;
2551 }
while (node1_depth > node2_depth);
2552 }
else if (node2_depth > node1_depth) {
2554 node2 = node2->parent;
2556 }
while (node2_depth > node1_depth);
2559 while (node1->parent != node2->parent) {
2560 node1 = node1->parent;
2561 node2 = node2->parent;
2568 node1 = node1->next;
2569 if (node1 == node2) {
2572 }
while (node1 !=
NULL);
2579 if (node1 == node2) {
2582 ordering = other_intern < this_intern ? DOCUMENT_POSITION_PRECEDING : DOCUMENT_POSITION_FOLLOWING;
2584 ordering = node1 < node2 ? DOCUMENT_POSITION_PRECEDING : DOCUMENT_POSITION_FOLLOWING;
2586 RETURN_LONG(DOCUMENT_POSITION_DISCONNECTED | DOCUMENT_POSITION_IMPLEMENTATION_SPECIFIC | ordering);
file(string $filename, int $flags=0, $context=null)
PHP_DOM_EXPORT zend_class_entry * dom_modern_node_class_entry
PHP_DOM_EXPORT zend_class_entry * dom_html_document_class_entry
PHP_DOM_EXPORT zend_class_entry * dom_node_class_entry
PHP_DOM_EXPORT zend_class_entry * dom_namespace_node_class_entry
PHP_DOM_EXPORT zend_class_entry * dom_xml_document_class_entry
zend_result dom_node_first_child_read(dom_object *obj, zval *retval)
zend_result dom_node_last_child_read(dom_object *obj, zval *retval)
zend_result dom_node_owner_document_read(dom_object *obj, zval *retval)
zend_result dom_node_local_name_read(dom_object *obj, zval *retval)
zend_result dom_node_text_content_write(dom_object *obj, zval *newval)
zend_result dom_node_attributes_read(dom_object *obj, zval *retval)
zend_result dom_node_next_element_sibling_read(dom_object *obj, zval *retval)
zend_result dom_node_previous_sibling_read(dom_object *obj, zval *retval)
zend_result dom_node_previous_element_sibling_read(dom_object *obj, zval *retval)
zend_result dom_node_parent_node_read(dom_object *obj, zval *retval)
zend_result dom_node_child_nodes_read(dom_object *obj, zval *retval)
zend_result dom_node_parent_element_read(dom_object *obj, zval *retval)
zend_result dom_node_node_value_read(dom_object *obj, zval *retval)
zend_result dom_node_node_value_write(dom_object *obj, zval *newval)
zend_result dom_node_prefix_read(dom_object *obj, zval *retval)
zend_result dom_node_prefix_write(dom_object *obj, zval *newval)
#define DOM_PROP_NODE(type, name, obj)
zend_result dom_node_next_sibling_read(dom_object *obj, zval *retval)
zend_result dom_node_namespace_uri_read(dom_object *obj, zval *retval)
zend_result dom_node_base_uri_read(dom_object *obj, zval *retval)
zend_result dom_node_is_connected_read(dom_object *obj, zval *retval)
zend_result dom_modern_node_prefix_read(dom_object *obj, zval *retval)
zend_result dom_node_text_content_read(dom_object *obj, zval *retval)
zend_result dom_node_node_type_read(dom_object *obj, zval *retval)
zend_result dom_node_node_name_read(dom_object *obj, zval *retval)
void php_dom_throw_error_with_message(dom_exception_code error_code, const char *error_message, bool strict_error)
void php_dom_throw_error(dom_exception_code error_code, bool strict_error)
@ NO_MODIFICATION_ALLOWED_ERR
zend_ffi_ctype_name_buf buf
foreach($dp as $el) foreach( $dp as $el) if( $pass2< 2) echo ""
PHPAPI ZEND_COLD void php_error_docref(const char *docref, int type, const char *format,...)
PHP_DOM_EXPORT const php_dom_ns_magic_token * php_dom_ns_is_xmlns_magic_token
PHP_DOM_EXPORT bool php_dom_ns_is_fast_ex(xmlNsPtr ns, const php_dom_ns_magic_token *magic_token)
PHP_DOM_EXPORT bool php_dom_ns_is_html_and_document_is_html(const xmlNode *nodep)
PHP_DOM_EXPORT void php_dom_reconcile_attribute_namespace_after_insertion(xmlAttrPtr attrp)
void dom_attr_value_will_change(dom_object *obj, xmlAttrPtr attrp)
void php_dom_normalize_modern(xmlNodePtr nodep)
dom_object * php_dom_instantiate_object_helper(zval *return_value, zend_class_entry *ce, xmlNodePtr obj, dom_object *parent)
bool dom_node_children_valid(const xmlNode *node)
bool php_dom_pre_insert_is_parent_invalid(xmlNodePtr parent)
int dom_hierarchy(xmlNodePtr parent, xmlNodePtr child)
bool dom_has_feature(zend_string *feature, zend_string *version)
void dom_set_document_ref_pointers(xmlNodePtr node, php_libxml_ref_obj *document)
void php_dom_node_append(php_libxml_ref_obj *document, xmlNodePtr node, xmlNodePtr parent)
void dom_reconcile_ns(xmlDocPtr doc, xmlNodePtr nodep)
xmlNodePtr dom_clone_node(php_dom_libxml_ns_mapper *ns_mapper, xmlNodePtr node, xmlDocPtr doc, bool recursive)
bool dom_get_strict_error(php_libxml_ref_obj *document)
#define DOM_GET_OBJ(__ptr, __id, __prtype, __intern)
bool php_dom_pre_insert(php_libxml_ref_obj *document, xmlNodePtr node, xmlNodePtr parent, xmlNodePtr insertion_point)
void php_dom_update_document_after_clone(dom_object *original, xmlNodePtr original_node, dom_object *clone, xmlNodePtr cloned_node)
bool php_dom_create_nullable_object(xmlNodePtr obj, zval *return_value, dom_object *domobj)
void php_dom_normalize_legacy(xmlNodePtr nodep)
void dom_set_document_ref_pointers_attr(xmlAttrPtr attr, php_libxml_ref_obj *document)
bool php_dom_has_sibling_following_node(xmlNodePtr node, xmlElementType type)
void php_dom_get_content_into_zval(const xmlNode *nodep, zval *target, bool default_is_null)
bool php_dom_has_sibling_preceding_node(xmlNodePtr node, xmlElementType type)
void dom_namednode_iter(dom_object *basenode, int ntype, dom_object *intern, xmlHashTablePtr ht, const char *local, size_t local_len, const char *ns, size_t ns_len)
zend_string * dom_node_concatenated_name_helper(size_t name_len, const char *name, size_t prefix_len, const char *prefix)
void php_dom_create_iterator(zval *return_value, dom_iterator_type iterator_type, bool modern)
const char * dom_locate_a_namespace(const xmlNode *node, const zend_string *prefix)
int dom_node_is_read_only(const xmlNode *node)
zend_string * dom_node_get_node_name_attribute_or_element(const xmlNode *nodep, bool uppercase)
void dom_reconcile_ns_list(xmlDocPtr doc, xmlNodePtr nodep, xmlNodePtr last)
bool php_dom_is_node_connected(const xmlNode *node)
void dom_remove_all_children(xmlNodePtr nodep)
bool php_dom_fragment_insertion_hierarchy_check_replace(xmlNodePtr parent, xmlNodePtr node, xmlNodePtr child)
const XML_DOCUMENT_TYPE_NODE
const XML_HTML_DOCUMENT_NODE
const XML_CDATA_SECTION_NODE
const XML_DOCUMENT_FRAG_NODE
const XML_ENTITY_REF_NODE
PHP_JSON_API size_t int options
void php_dom_private_data_destroy(php_dom_private_data *data)
php_dom_private_data * php_dom_private_data_create(void)
php_dom_libxml_ns_mapper * php_dom_ns_mapper_from_private(php_dom_private_data *private_data)
php_libxml_private_data_header * php_dom_libxml_private_data_header(php_dom_private_data *private_data)
php_libxml_ref_obj * document
#define DOM_GET_THIS_OBJ(__ptr, __id, __prtype, __intern)
struct _dom_object dom_object
#define DOM_RET_OBJ(obj, domobject)
PHP_DOM_EXPORT dom_object * php_dom_object_get_data(xmlNodePtr obj)
PHP_DOM_EXPORT bool php_dom_create_object(xmlNodePtr obj, zval *return_value, dom_object *domobj)
ZEND_API ZEND_COLD void zend_throw_error(zend_class_entry *exception_ce, const char *format,...)
#define INTERNAL_FUNCTION_PARAMETERS
#define INTERNAL_FUNCTION_PARAM_PASSTHRU
ZEND_API const char * zend_zval_value_name(const zval *arg)
ZEND_API zend_result zend_parse_parameters(uint32_t num_args, const char *type_spec,...)
ZEND_API ZEND_COLD void zend_argument_value_error(uint32_t arg_num, const char *format,...)
ZEND_API ZEND_COLD void zend_argument_type_error(uint32_t arg_num, const char *format,...)
#define Z_PARAM_ARRAY_OR_NULL(dest)
#define ZEND_PARSE_PARAMETERS_END()
#define Z_PARAM_STR_OR_NULL(dest)
#define ZEND_PARSE_PARAMETERS_NONE()
#define ZVAL_STRING(z, s)
#define Z_PARAM_STRING(dest, dest_len)
#define Z_PARAM_STRING_OR_NULL(dest, dest_len)
#define ZEND_PARSE_PARAMETERS_START(min_num_args, max_num_args)
#define RETVAL_EMPTY_STRING()
#define Z_PARAM_OBJECT_OF_CLASS_OR_NULL(dest, _ce)
#define Z_PARAM_OBJECT_OF_CLASS(dest, _ce)
#define Z_PARAM_OBJECT_OR_NULL(dest)
#define RETVAL_STRINGL(s, l)
#define ZVAL_EMPTY_STRING(z)
#define safe_emalloc(nmemb, size, offset)
strcmp(string $string1, string $string2)
zend_string_release_ex(func->internal_function.function_name, 0)
ZEND_API ZEND_COLD zend_object * zend_throw_exception_ex(zend_class_entry *exception_ce, zend_long code, const char *format,...)
#define ZEND_HASH_FOREACH_END()
#define ZEND_HASH_MAP_FOREACH_STR_KEY_VAL(ht, _key, _val)
#define ZEND_HASH_FOREACH_VAL(ht, _val)
struct _zend_string zend_string
ZEND_API void ZEND_FASTCALL zend_str_toupper(char *str, size_t length)
#define EMPTY_SWITCH_DEFAULT_CASE()
#define UNEXPECTED(condition)
struct _zend_class_entry zend_class_entry
#define zend_string_equals_literal(str, literal)
#define zend_string_equals_literal_ci(str, c)
#define Z_STRVAL_P(zval_p)
#define Z_ARRVAL_P(zval_p)
struct _zend_array HashTable
#define Z_STRLEN_P(zval_p)
#define Z_OBJCE_P(zval_p)
#define ZVAL_NEW_STR(z, s)
ZEND_RESULT_CODE zend_result