subnode = php_sxe_object_new(sxe->zo.ce TSRMLS_CC);
subnode->document = sxe->document;
subnode->document->refcount++;
- subnode->nsmapptr = sxe->nsmapptr;
- subnode->nsmapptr->refcount++;
subnode->iter.type = itertype;
if (name) {
subnode->iter.name = xmlStrdup(name);
static inline int
match_ns(php_sxe_object *sxe, xmlNodePtr node, xmlChar *name)
{
- xmlChar *prefix = NULL;
-
- if (name == NULL && (node->ns == NULL || node->ns->prefix == NULL)) {
+ if (name == NULL && (node->ns == NULL || node->ns->href == NULL)) {
return 1;
}
-
- if (node->ns) {
- if (sxe->nsmapptr) {
- prefix = xmlHashLookup(sxe->nsmapptr->nsmap, node->ns->href);
- }
-
- if (prefix == NULL) {
- prefix = (xmlChar*)node->ns->prefix;
- }
-
- if (prefix == NULL) {
- return 0;
- }
-
- if (!xmlStrcmp(prefix, name)) {
- return 1;
- }
+
+ if (!xmlStrcmp(node->ns->href, name)) {
+ return 1;
}
return 0;
subnode = php_sxe_object_new(sxe_ref->zo.ce TSRMLS_CC);
subnode->document = sxe_ref->document;
subnode->document->refcount++;
- subnode->nsmapptr = sxe_ref->nsmapptr;
- subnode->nsmapptr->refcount++;
php_libxml_increment_node_ptr((php_libxml_node_object *)subnode, node, NULL TSRMLS_CC);
(*value)->type = IS_OBJECT;
}
/* }}} */
-/* {{{ simplexml_ce_xpath_register_ns()
- */
-static void
-simplexml_ce_xpath_register_ns(char *prefix, xmlXPathContext *xpath, char *href)
-{
- xmlXPathRegisterNs(xpath, prefix, href);
-}
-/* }}} */
-
-
/* {{{ xpath()
*/
SXE_METHOD(xpath)
sxe->xpath->node = sxe->node->node;
ns = xmlGetNsList((xmlDocPtr) sxe->document->ptr, (xmlNodePtr) sxe->node->node);
-
if (ns != NULL) {
while (ns[nsnbr] != NULL) {
nsnbr++;
sxe->xpath->namespaces = ns;
sxe->xpath->nsNr = nsnbr;
- /* Register namespaces added in simplexml_cs_register_ns() */
- xmlHashScan((xmlHashTablePtr) sxe->nsmapptr->nsmap, (xmlHashScanner) simplexml_ce_xpath_register_ns, sxe->xpath);
-
retval = xmlXPathEval(query, sxe->xpath);
-
- /* Cleanup registered namespaces added in simplexml_cs_register_ns() */
- xmlXPathRegisteredNsCleanup(sxe->xpath);
-
if (ns != NULL) {
xmlFree(ns);
sxe->xpath->namespaces = NULL;
}
/* }}} */
-/* {{{ simplexml_ce_register_ns()
- */
-SXE_METHOD(register_ns)
-{
- php_sxe_object *sxe;
- char *nsname;
- char *nsvalue;
- int nsname_len;
- int nsvalue_len;
-
- if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ss", &nsname, &nsname_len, &nsvalue, &nsvalue_len) == FAILURE) {
- return;
- }
-
- sxe = php_sxe_fetch_object(getThis() TSRMLS_CC);
-
- xmlHashAddEntry(sxe->nsmapptr->nsmap, nsvalue, xmlStrdup(nsname));
-}
-/* }}} */
-
/* {{{ proto asXML([string filename])
*/
SXE_METHOD(asXML)
if (sxe->node) {
nodep = xmlDocCopyNode(sxe->node->node, docp, 1);
}
- clone->nsmapptr = emalloc(sizeof(simplexml_nsmap));
- clone->nsmapptr->nsmap = xmlHashCreate(10);
- clone->nsmapptr->refcount = 1;
php_libxml_increment_node_ptr((php_libxml_node_object *)clone, nodep, NULL TSRMLS_CC);
}
/* }}} */
-/* {{{ _free_ns_entry()
- */
-static void
-_free_ns_entry(void *p, xmlChar *data)
-{
- xmlFree(p);
-}
-/* }}} */
-
/* {{{ sxe_object_dtor()
*/
static void sxe_object_dtor(void *object, zend_object_handle handle TSRMLS_DC)
php_libxml_node_decrement_resource((php_libxml_node_object *)sxe TSRMLS_CC);
- if (sxe->nsmapptr && --sxe->nsmapptr->refcount == 0) {
- xmlHashFree(sxe->nsmapptr->nsmap, _free_ns_entry);
- efree(sxe->nsmapptr);
- }
-
if (sxe->xpath) {
xmlXPathFreeContext(sxe->xpath);
}
sxe = php_sxe_object_new(ce TSRMLS_CC);
php_libxml_increment_doc_ref((php_libxml_node_object *)sxe, docp TSRMLS_CC);
- sxe->nsmapptr = emalloc(sizeof(simplexml_nsmap));
- sxe->nsmapptr->nsmap = xmlHashCreate(10);
- sxe->nsmapptr->refcount = 1;
php_libxml_increment_node_ptr((php_libxml_node_object *)sxe, xmlDocGetRootElement(docp), NULL TSRMLS_CC);
return_value->type = IS_OBJECT;
sxe = php_sxe_object_new(ce TSRMLS_CC);
php_libxml_increment_doc_ref((php_libxml_node_object *)sxe, docp TSRMLS_CC);
- sxe->nsmapptr = emalloc(sizeof(simplexml_nsmap));
- sxe->nsmapptr->nsmap = xmlHashCreate(10);
- sxe->nsmapptr->refcount = 1;
sxe->iter.type = SXE_ITER_NONE;
php_libxml_increment_node_ptr((php_libxml_node_object *)sxe, xmlDocGetRootElement(docp), NULL TSRMLS_CC);
}
php_libxml_increment_doc_ref((php_libxml_node_object *)sxe, docp TSRMLS_CC);
- sxe->nsmapptr = emalloc(sizeof(simplexml_nsmap));
- sxe->nsmapptr->nsmap = xmlHashCreate(10);
- sxe->nsmapptr->refcount = 1;
php_libxml_increment_node_ptr((php_libxml_node_object *)sxe, xmlDocGetRootElement(docp), NULL TSRMLS_CC);
}
sxe = php_sxe_object_new(ce TSRMLS_CC);
sxe->document = object->document;
php_libxml_increment_doc_ref((php_libxml_node_object *)sxe, nodep->doc TSRMLS_CC);
- sxe->nsmapptr = emalloc(sizeof(simplexml_nsmap));
- sxe->nsmapptr->nsmap = xmlHashCreate(10);
- sxe->nsmapptr->refcount = 1;
php_libxml_increment_node_ptr((php_libxml_node_object *)sxe, nodep, NULL TSRMLS_CC);
return_value->type = IS_OBJECT;
/* each method can have its own parameters and visibility */
static zend_function_entry sxe_functions[] = {
SXE_ME(__construct, NULL, ZEND_ACC_PUBLIC|ZEND_ACC_FINAL) /* must be called */
- SXE_ME(register_ns, NULL, ZEND_ACC_PUBLIC)
SXE_ME(asXML, NULL, ZEND_ACC_PUBLIC)
SXE_ME(xpath, NULL, ZEND_ACC_PUBLIC)
SXE_ME(attributes, NULL, ZEND_ACC_PUBLIC)