static zend_function_entry domxml_functions[] = {
PHP_FE(domxml_version, NULL)
PHP_FE(xmldoc, NULL)
+ PHP_FALIAS(domxml_open_mem, xmldoc, NULL)
PHP_FE(xmldocfile, NULL)
+ PHP_FALIAS(domxml_open_file, xmldocfile, NULL)
#if defined(LIBXML_HTML_ENABLED)
PHP_FE(html_doc, NULL)
PHP_FE(html_doc_file, NULL)
#endif
- PHP_FE(xmltree, NULL)
+ PHP_FE(domxml_xmltree, NULL)
+ PHP_FALIAS(xmltree, domxml_xmltree, NULL)
PHP_FE(domxml_substitute_entities_default, NULL)
PHP_FE(domxml_add_root, NULL)
PHP_FE(domxml_dump_mem, NULL)
PHP_FE(domxml_node_set_content, NULL)
PHP_FE(domxml_node_get_content, NULL)
PHP_FE(domxml_new_xmldoc, NULL)
+ PHP_FALIAS(domxml_new_doc, domxml_new_xmldoc, NULL)
PHP_FE(domxml_parser, NULL)
PHP_FE(domxml_parser_add_chunk, NULL)
PHP_FE(domxml_parser_end, NULL)
static function_entry php_domxmldoc_class_functions[] = {
-/* PHP_FALIAS(domdocument, xmldoc, NULL) */
- {"domdocument", PHP_FN(xmldoc), NULL},
-
PHP_FALIAS(doctype, domxml_doc_doctype, NULL)
PHP_FALIAS(implementation, domxml_doc_implementation, NULL)
PHP_FALIAS(root, domxml_doc_document_element, NULL) /* not DOM */
PHP_FALIAS(create_cdata_section, domxml_doc_create_cdata_section, NULL)
PHP_FALIAS(create_entity_reference, domxml_doc_create_entity_reference, NULL)
PHP_FALIAS(create_processing_instruction, domxml_doc_create_processing_instruction, NULL)
- PHP_FALIAS(children, domxml_node_children, NULL)
+ PHP_FALIAS(get_elements_by_tagname, domxml_doc_get_elements_by_tagname, NULL)
+ PHP_FALIAS(get_element_by_id, domxml_doc_get_element_by_id, NULL)
+ /* children is deprecated because it is inherited from DomNode */
+/* PHP_FALIAS(children, domxml_node_children, NULL) */
PHP_FALIAS(add_root, domxml_add_root, NULL)
PHP_FALIAS(imported_node, domxml_doc_imported_node, NULL)
PHP_FALIAS(dtd, domxml_intdtd, NULL)
PHP_FALIAS(dumpmem, domxml_dump_mem, NULL)
PHP_FALIAS(dump_mem, domxml_dump_mem, NULL)
PHP_FALIAS(dump_mem_file, domxml_dump_mem_file, NULL)
+ PHP_FALIAS(dump_file, domxml_dump_mem_file, NULL)
#if defined(LIBXML_HTML_ENABLED)
PHP_FALIAS(html_dump_mem, domxml_html_dump_mem, NULL)
#endif
PHP_FALIAS(xpath_init, xpath_init, NULL)
PHP_FALIAS(xpath_new_context, xpath_new_context, NULL)
PHP_FALIAS(xptr_new_context, xptr_new_context, NULL)
- PHP_FALIAS(get_elements_by_tagname, domxml_doc_get_elements_by_tagname, NULL)
- PHP_FALIAS(get_element_by_id, domxml_doc_get_element_by_id, NULL)
#endif
{NULL, NULL, NULL}
};
static function_entry php_domxmldoctype_class_functions[] = {
PHP_FALIAS(name, domxml_doctype_name, NULL)
-/*
PHP_FALIAS(entities, domxml_doctype_entities, NULL)
PHP_FALIAS(notations, domxml_doctype_notations, NULL)
PHP_FALIAS(system_id, domxml_doctype_system_id, NULL)
PHP_FALIAS(public_id, domxml_doctype_public_id, NULL)
+/*
PHP_FALIAS(internal_subset, domxml_doctype_internal_subset, NULL)
*/
{NULL, NULL, NULL}
static zend_function_entry php_domxmlnode_class_functions[] = {
PHP_FALIAS(domnode, domxml_node, NULL)
+ PHP_FALIAS(node_name, domxml_node_name, NULL)
+ PHP_FALIAS(node_type, domxml_node_type, NULL)
+ PHP_FALIAS(node_value, domxml_node_value, NULL)
PHP_FALIAS(first_child, domxml_node_first_child, NULL)
PHP_FALIAS(last_child, domxml_node_last_child, NULL)
PHP_FALIAS(add_child, domxml_node_add_child, NULL)
PHP_FALIAS(previous_sibling, domxml_node_previous_sibling, NULL)
PHP_FALIAS(next_sibling, domxml_node_next_sibling, NULL)
PHP_FALIAS(has_child_nodes, domxml_node_has_child_nodes, NULL)
- PHP_FALIAS(prefix, domxml_node_prefix, NULL)
PHP_FALIAS(parent, domxml_node_parent, NULL)
PHP_FALIAS(parent_node, domxml_node_parent, NULL)
PHP_FALIAS(insert_before, domxml_node_insert_before, NULL)
PHP_FALIAS(new_child, domxml_node_new_child, NULL)
PHP_FALIAS(attributes, domxml_node_attributes, NULL)
PHP_FALIAS(has_attributes, domxml_node_has_attributes, NULL)
+ PHP_FALIAS(prefix, domxml_node_prefix, NULL)
+ PHP_FALIAS(clone_node, domxml_clone_node, NULL)
+/* Non DOM functions start here */
PHP_FALIAS(node, domxml_node, NULL)
PHP_FALIAS(unlink, domxml_node_unlink_node, NULL)
- PHP_FALIAS(unlink_node, domxml_node_unlink_node, NULL)
+ PHP_FALIAS(unlink_node, domxml_node_unlink_node, NULL)
PHP_FALIAS(replace_node, domxml_node_replace_node, NULL)
PHP_FALIAS(set_content, domxml_node_set_content, NULL)
PHP_FALIAS(get_content, domxml_node_get_content, NULL)
PHP_FALIAS(text_concat, domxml_node_text_concat, NULL)
PHP_FALIAS(set_name, domxml_node_set_name, NULL)
- PHP_FALIAS(node_name, domxml_node_name, NULL)
- PHP_FALIAS(node_type, domxml_node_type, NULL)
- PHP_FALIAS(node_value, domxml_node_value, NULL)
- PHP_FALIAS(clone_node, domxml_clone_node, NULL)
PHP_FALIAS(is_blank_node, domxml_is_blank_node, NULL)
PHP_FALIAS(dump_node, domxml_dump_node, NULL)
{NULL, NULL, NULL}
PHP_FALIAS(get_attribute_node, domxml_elem_get_attribute_node, NULL)
PHP_FALIAS(set_attribute_node, domxml_elem_set_attribute_node, NULL)
PHP_FALIAS(get_elements_by_tagname, domxml_elem_get_elements_by_tagname, NULL)
+ PHP_FALIAS(has_attribute, domxml_elem_has_attribute, NULL)
{NULL, NULL, NULL}
};
{
zval *wrapper;
- // FIXME: type check probably unnecessary here?
+ /* FIXME: type check probably unnecessary here? */
if (!node || Z_TYPE_P(node) == XML_DTD_NODE)
return;
object_init_ex(wrapper, domxmltext_class_entry);
rsrc_type = le_domxmltextp;
content = xmlNodeGetContent(nodep);
- if (content) {
- add_property_long(wrapper, "type", Z_TYPE_P(nodep));
+ add_property_long(wrapper, "type", Z_TYPE_P(nodep));
+ add_property_stringl(wrapper, "name", "#text", sizeof("#text"), 1);
+ if (content)
add_property_stringl(wrapper, "content", (char *) content, strlen(content), 1);
- xmlFree(content);
- }
+ xmlFree(content);
break;
}
content = xmlNodeGetContent(nodep);
if (content) {
add_property_long(wrapper, "type", Z_TYPE_P(nodep));
+ add_property_stringl(wrapper, "name", "#comment", sizeof("#comment"), 1);
add_property_stringl(wrapper, "content", (char *) content, strlen(content), 1);
xmlFree(content);
}
object_init_ex(wrapper, domxmlpi_class_entry);
rsrc_type = le_domxmlpip;
content = xmlNodeGetContent(nodep);
- add_property_stringl(wrapper, "target", (char *) nodep->name, strlen(nodep->name), 1);
+ add_property_stringl(wrapper, "name", (char *) nodep->name, strlen(nodep->name), 1);
if (content) {
- add_property_stringl(wrapper, "data", (char *) content, strlen(content), 1);
+ add_property_stringl(wrapper, "value", (char *) content, strlen(content), 1);
xmlFree(content);
}
break;
xmlAttrPtr attrp = (xmlAttrPtr) obj;
object_init_ex(wrapper, domxmlattr_class_entry);
rsrc_type = le_domxmlattrp;
- add_property_stringl(wrapper, "name", (char *) attrp->name, strlen(attrp->name), 1);
add_property_long(wrapper, "type", Z_TYPE_P(attrp));
+ add_property_stringl(wrapper, "name", (char *) attrp->name, strlen(attrp->name), 1);
content = xmlNodeGetContent((xmlNodePtr) attrp);
if (content) {
add_property_stringl(wrapper, "value", (char *) content, strlen(content), 1);
if (docp->name)
add_property_stringl(wrapper, "name", (char *) docp->name, strlen(docp->name), 1);
else
- add_property_stringl(wrapper, "name", "", 0, 1);
+ add_property_stringl(wrapper, "name", "#document", sizeof("#document"), 1);
if (docp->URL)
add_property_stringl(wrapper, "url", (char *) docp->URL, strlen(docp->URL), 1);
else
break;
}
+ /* FIXME: nodes of type XML_DTD_NODE used to be domxmldtd_class_entry.
+ * but the DOM Standard doesn't have a DomDtd class. The DocumentType
+ * class seems to be want we need and the libxml dtd functions are
+ * very much like the methods of DocumentType. I wonder what exactly
+ * is the difference between XML_DTD_NODE and XML_DOCUMENT_TYPE_NODE.
+ * Something like
+ * <!DOCTYPE chapter SYSTEM '/share/sgml/Norman_Walsh/db3xml10/db3xml10.dtd'
+ * [ <!ENTITY sp \"spanish\">
+ * ]>
+ * is considered a DTD by libxml, but from the DOM perspective it
+ * rather is a DocumentType
+ */
case XML_DTD_NODE:
+ case XML_DOCUMENT_TYPE_NODE:
{
xmlDtdPtr dtd = (xmlDtdPtr) obj;
- object_init_ex(wrapper, domxmldtd_class_entry);
- rsrc_type = le_domxmldtdp;
- add_property_long(wrapper, "type", Z_TYPE_P(dtd));
+ object_init_ex(wrapper, domxmldoctype_class_entry);
+/* rsrc_type = le_domxmldtdp; */
+ rsrc_type = le_domxmldoctypep;
+/* add_property_long(wrapper, "type", Z_TYPE_P(dtd)); */
+ add_property_long(wrapper, "type", XML_DOCUMENT_TYPE_NODE);
if (dtd->ExternalID)
add_property_string(wrapper, "publicId", (char *) dtd->ExternalID, 1);
+ else
+ add_property_string(wrapper, "publicId", "", 1);
if (dtd->SystemID)
add_property_string(wrapper, "systemId", (char *) dtd->SystemID, 1);
+ else
+ add_property_string(wrapper, "systemId", "", 1);
if (dtd->name)
add_property_string(wrapper, "name", (char *) dtd->name, 1);
break;
le_domxmlentityrefp = zend_register_list_destructors_ex(php_free_xml_node, NULL, "domentityref", module_number);
le_domxmlpip = zend_register_list_destructors_ex(php_free_xml_node, NULL, "dompi", module_number);
le_domxmlparserp = zend_register_list_destructors_ex(php_free_xml_parser, NULL, "domparser", module_number);
+ le_domxmldoctypep = zend_register_list_destructors_ex(php_free_xml_node, NULL, "domdocumenttype", module_number);
/* Not yet initialized le_*s */
- le_domxmldoctypep = -10000;
le_domxmlnotationp = -10003;
#if defined(LIBXML_XPATH_ENABLED)
RETURN_FALSE;
}
- // FIXME reverted xmlAddChildList; crashes
- child = xmlAddSibling(nodep, new_child);
+ /* FIXME reverted xmlAddChildList; crashes
+ * Uwe: must have been a temporary problem. It works for me with both
+ * xmlAddChildList and xmlAddChild
+ */
+// child = xmlAddSibling(nodep, new_child);
+ child = xmlAddChild(nodep, new_child);
if (NULL == child) {
php_error(E_WARNING, "%s(): couldn't append node", get_active_function_name(TSRMLS_C));
PHP_FUNCTION(domxml_node_insert_before)
{
zval *id, *rv, *node, *ref;
- xmlNodePtr child, nodep, refp;
+ xmlNodePtr child, new_child, nodep, refp;
int ret;
DOMXML_GET_THIS_OBJ(nodep, id, le_domxmlnodep);
DOMXML_GET_OBJ(child, node, le_domxmlnodep);
DOMXML_GET_OBJ(refp, ref, le_domxmlnodep);
- child = xmlAddPrevSibling(refp, child);
+ if (NULL == (new_child = xmlCopyNode(child, 1))) {
+ php_error(E_WARNING, "%s(): unable to clone node", get_active_function_name(TSRMLS_C));
+ RETURN_FALSE;
+ }
+
+ child = xmlAddPrevSibling(refp, new_child);
if (NULL == child) {
php_error(E_WARNING, "%s(): couldn't add newnode as the previous sibling of refnode", get_active_function_name(TSRMLS_C));
DOMXML_PARAM_TWO(nodep, id, le_domxmlnodep, "s", &content, &content_len);
- // FIXME: another gotcha. If node has children, calling
- // xmlNodeSetContent will remove the children -> we loose the zval's
- // To prevent crash, append content if children are set
+ /* FIXME: another gotcha. If node has children, calling
+ * xmlNodeSetContent will remove the children -> we loose the zval's
+ * To prevent crash, append content if children are set
+ */
if (nodep->children) {
xmlNodeAddContentLen(nodep, content, content_len);
} else {
DOMXML_NO_ARGS();
- RETURN_STRING((char *) (nodep->PublicID), 1);
+ if(nodep->PublicID) {
+ RETURN_STRING((char *) (nodep->PublicID), 1);
+ } else {
+ RETURN_EMPTY_STRING();
+ }
}
/* }}} */
DOMXML_NO_ARGS();
- RETURN_STRING((char *) (nodep->SystemID), 1);
+ if(nodep->SystemID) {
+ RETURN_STRING((char *) (nodep->SystemID), 1);
+ } else {
+ RETURN_EMPTY_STRING();
+ }
}
/* }}} */
}
/* }}} */
-/* {{{ proto bool domxml_elem_set_attribute_node(int attr)
+/* {{{ proto bool domxml_elem_set_attribute_node(object attr)
Sets value of given attribute */
PHP_FUNCTION(domxml_elem_set_attribute_node)
{
- zval *id, *arg1;
+ zval *id, *arg1, *rv;
xmlNode *nodep;
- xmlAttr *attrp;
-
- DOMXML_NOT_IMPLEMENTED();
+ xmlAttr *attrp, *newattrp;
+ int ret;
if ((ZEND_NUM_ARGS() == 1) && getParameters(ht, 1, &arg1) == SUCCESS) {
id = getThis();
WRONG_PARAM_COUNT;
}
- /* FIXME: not implemented */
+ /* FIXME: The following line doesn't work */
+ newattrp = xmlCopyProp(nodep, attrp);
+ if (!newattrp) {
+ php_error(E_WARNING, "%s(): no such attribute '%s'", get_active_function_name(TSRMLS_C), attrp->name);
+ RETURN_FALSE;
+ }
- RETURN_TRUE;
+ DOMXML_RET_OBJ(rv, (xmlNodePtr) newattrp, &ret);
+}
+/* }}} */
+
+/* {{{ proto string domxml_elem_has_attribute(string attrname)
+ Checks for existenz given attribute */
+PHP_FUNCTION(domxml_elem_has_attribute)
+{
+ zval *id;
+ xmlNode *nodep;
+ char *name, *value;
+ int name_len;
+
+ DOMXML_PARAM_TWO(nodep, id, le_domxmlelementp, "s", &name, &name_len);
+
+ value = xmlGetProp(nodep, name);
+ if (!value) {
+ RETURN_FALSE;
+ } else {
+ xmlFree(value);
+ RETURN_TRUE;
+ }
}
/* }}} */
PHP_FUNCTION(domxml_doctype_name)
{
zval *id;
- xmlNodePtr attrp;
+ xmlDtdPtr attrp;
DOMXML_NO_ARGS();
}
/* }}} */
+/* {{{ proto array domxml_doctype_system_id(void)
+ Returns system id of DocumentType */
+PHP_FUNCTION(domxml_doctype_system_id)
+{
+ zval *id;
+ xmlDtdPtr attrp;
+
+ DOMXML_NO_ARGS();
+
+ DOMXML_GET_THIS_OBJ(attrp, id, le_domxmldoctypep);
+
+ if(attrp->SystemID) {
+ RETURN_STRING((char *) (attrp->SystemID), 1);
+ } else {
+ RETURN_EMPTY_STRING();
+ }
+}
+/* }}} */
+
+/* {{{ proto array domxml_doctype_public_id(void)
+ Returns public id of DocumentType */
+PHP_FUNCTION(domxml_doctype_public_id)
+{
+ zval *id;
+ xmlDtdPtr attrp;
+
+ DOMXML_NO_ARGS();
+
+ DOMXML_GET_THIS_OBJ(attrp, id, le_domxmldoctypep);
+
+ if(attrp->ExternalID) {
+ RETURN_STRING((char *) (attrp->ExternalID), 1);
+ } else {
+ RETURN_EMPTY_STRING();
+ }
+}
+/* }}} */
+
+/* {{{ proto array domxml_doctype_entities(void)
+ Returns list of entities */
+PHP_FUNCTION(domxml_doctype_entities)
+{
+ zval *id;
+ xmlNode *last;
+ xmlDtdPtr doctypep;
+ int ret;
+
+ DOMXML_NOT_IMPLEMENTED();
+
+ DOMXML_PARAM_NONE(doctypep, id, le_domxmldoctypep);
+
+ last = doctypep->entities;
+ if (!last) {
+ RETURN_FALSE;
+ }
+
+ if (array_init(return_value) == FAILURE) {
+ RETURN_FALSE;
+ }
+
+ while (last) {
+ zval *child;
+ child = php_domobject_new(last, &ret TSRMLS_CC);
+ add_next_index_zval(return_value, child);
+ last = last->next;
+ }
+}
+/* }}} */
+
+/* {{{ proto array domxml_doctype_notations(void)
+ Returns list of notations */
+PHP_FUNCTION(domxml_doctype_notations)
+{
+ zval *id;
+ xmlNode *last;
+ xmlDtdPtr doctypep;
+ int ret;
+
+ DOMXML_NOT_IMPLEMENTED();
+
+ DOMXML_PARAM_NONE(doctypep, id, le_domxmldoctypep);
+
+ last = doctypep->notations;
+ if (!last) {
+ RETURN_FALSE;
+ }
+
+ if (array_init(return_value) == FAILURE) {
+ RETURN_FALSE;
+ }
+
+ while (last) {
+ zval *child;
+ child = php_domobject_new(last, &ret TSRMLS_CC);
+ add_next_index_zval(return_value, child);
+ last = last->next;
+ }
+}
+/* }}} */
+
/* End of Methods DomElementType }}} */
DOMXML_NO_ARGS();
dtd = xmlGetIntSubset(docp);
+ if (!dtd) {
+ RETURN_FALSE;
+ }
DOMXML_RET_OBJ(rv, (xmlNodePtr) dtd, &ret);
}
}
/* }}} */
-/* {{{ proto object domxml_doc_create_text_node(string name)
+/* {{{ proto object domxml_doc_create_text_node(string content)
Creates new text node */
PHP_FUNCTION(domxml_doc_create_text_node)
{
}
/* }}} */
-/* {{{ proto object domxml_doc_create_comment(string name)
+/* {{{ proto object domxml_doc_create_comment(string content)
Creates new comment node */
PHP_FUNCTION(domxml_doc_create_comment)
{
}
/* }}} */
-/* {{{ proto object domxml_doc_create_attribute(string name)
+/* {{{ proto object domxml_doc_create_attribute(string name, string value)
Creates new attribute node */
PHP_FUNCTION(domxml_doc_create_attribute)
{
}
/* }}} */
-/* {{{ proto object domxml_doc_create_cdata_section(string name)
+/* {{{ proto object domxml_doc_create_cdata_section(string content)
Creates new cdata node */
PHP_FUNCTION(domxml_doc_create_cdata_section)
{
DOMXML_GET_THIS_OBJ(docp, id, le_domxmldocp);
- // FIXME: which object type to expect?
+ /* FIXME: which object type to expect? */
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "o|l", &arg1, &recursive) == FAILURE) {
return;
}
}
/* }}} */
-/* {{{ proto int domxml_dump_mem_file(object doc_handle [, int filename [, int compressmode]])
+/* {{{ proto int domxml_dump_mem_file(string filename [, int compressmode [, int format]])
Dumps document into file and uses compression if specified. Returns false on error, otherwise the length of the xml-document (uncompressed) */
PHP_FUNCTION(domxml_dump_mem_file)
{
int format = 0;
int compressmode = 0;
char *file;
- DOMXML_PARAM_FOUR(docp, id, le_domxmldocp, "s|ll", &file, &file_len, &compressmode,&format);
+
+ DOMXML_PARAM_FOUR(docp, id, le_domxmldocp, "s|ll", &file, &file_len, &compressmode, &format);
xmlSetCompressMode (compressmode);
}
/* }}} */
-/* {{{ proto object xmltree(string xmltree)
+/* {{{ proto object domxml_xmltree(string xmltree)
Creates a tree of PHP objects from an XML document */
-PHP_FUNCTION(xmltree)
+PHP_FUNCTION(domxml_xmltree)
{
zval *children, *rv;
xmlDoc *docp;