diff options
Diffstat (limited to 'ext/xmlreader')
43 files changed, 2666 insertions, 0 deletions
diff --git a/ext/xmlreader/CREDITS b/ext/xmlreader/CREDITS new file mode 100644 index 0000000..35f3af1 --- /dev/null +++ b/ext/xmlreader/CREDITS @@ -0,0 +1,2 @@ +XMLReader +Rob Richards diff --git a/ext/xmlreader/README b/ext/xmlreader/README new file mode 100644 index 0000000..0d946f6 --- /dev/null +++ b/ext/xmlreader/README @@ -0,0 +1,5 @@ +XMLReader represents a reader that provides non-cached, +forward-only access to XML data. It is based upon the +xmlTextReader api from libxml + +This extension is designed to only work under PHP 5. diff --git a/ext/xmlreader/TODO b/ext/xmlreader/TODO new file mode 100644 index 0000000..744c561 --- /dev/null +++ b/ext/xmlreader/TODO @@ -0,0 +1,8 @@ +- Implement functions to support PHP 4 + +- Refactor internals once libxml 2.6.x is minimum requirement for PHP 5 + use new api for creating the xmlTextReaderPtr + +- Add Custom Error Handling + + diff --git a/ext/xmlreader/config.m4 b/ext/xmlreader/config.m4 new file mode 100644 index 0000000..3614996 --- /dev/null +++ b/ext/xmlreader/config.m4 @@ -0,0 +1,27 @@ +dnl +dnl $Id$ +dnl + +PHP_ARG_ENABLE(xmlreader, whether to enable XMLReader support, +[ --disable-xmlreader Disable XMLReader support], yes) + +if test -z "$PHP_LIBXML_DIR"; then + PHP_ARG_WITH(libxml-dir, libxml2 install dir, + [ --with-libxml-dir=DIR XMLReader: libxml2 install prefix], no, no) +fi + +if test "$PHP_XMLREADER" != "no"; then + + if test "$PHP_LIBXML" = "no"; then + AC_MSG_ERROR([XMLReader extension requires LIBXML extension, add --enable-libxml]) + fi + + PHP_SETUP_LIBXML(XMLREADER_SHARED_LIBADD, [ + AC_DEFINE(HAVE_XMLREADER,1,[ ]) + PHP_NEW_EXTENSION(xmlreader, php_xmlreader.c, $ext_shared) + PHP_ADD_EXTENSION_DEP(xmlreader, dom, true) + PHP_SUBST(XMLREADER_SHARED_LIBADD) + ], [ + AC_MSG_ERROR([xml2-config not found. Please check your libxml2 installation.]) + ]) +fi diff --git a/ext/xmlreader/config.w32 b/ext/xmlreader/config.w32 new file mode 100644 index 0000000..703f2bc --- /dev/null +++ b/ext/xmlreader/config.w32 @@ -0,0 +1,14 @@ +// $Id$ +// vim:ft=javascript + +ARG_ENABLE("xmlreader", "XMLReader support", "yes"); + +if (PHP_XMLREADER == "yes" && PHP_LIBXML == "yes") { + EXTENSION("xmlreader", "php_xmlreader.c"); + AC_DEFINE("HAVE_XMLREADER", 1, "XMLReader support"); + if (!PHP_XMLREADER_SHARED) { + ADD_FLAG("CFLAGS_XMLREADER", "/D LIBXML_STATIC"); + } + ADD_EXTENSION_DEP('xmlreader', 'libxml'); +} + diff --git a/ext/xmlreader/examples/dtdexample.dtd b/ext/xmlreader/examples/dtdexample.dtd new file mode 100644 index 0000000..ce53f0b --- /dev/null +++ b/ext/xmlreader/examples/dtdexample.dtd @@ -0,0 +1,8 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!ELEMENT LIST (MOVIE+)> +<!ELEMENT MOVIE (TITLE, ORGTITLE, LOC, INFO)> +<!ATTLIST MOVIE ID ID #REQUIRED> +<!ELEMENT TITLE (#PCDATA)> +<!ELEMENT ORGTITLE (#PCDATA)> +<!ELEMENT LOC (#PCDATA)> +<!ELEMENT INFO (#PCDATA)> diff --git a/ext/xmlreader/examples/dtdexample.xml b/ext/xmlreader/examples/dtdexample.xml new file mode 100644 index 0000000..052889c --- /dev/null +++ b/ext/xmlreader/examples/dtdexample.xml @@ -0,0 +1,15 @@ +<?xml version="1.0" encoding="UTF-8" standalone="no"?> +<!DOCTYPE LIST SYSTEM "dtdexample.dtd"> +<LIST> +<MOVIE ID="x200338360"> +<TITLE>Move Title 1</TITLE> +<ORGTITLE/><LOC>Location 1</LOC> +<INFO/> +</MOVIE> +<MOVIE ID="m200338361"> +<TITLE>Move Title 2</TITLE> +<ORGTITLE/> +<LOC>Location 2</LOC> +<INFO/> +</MOVIE> +</LIST> diff --git a/ext/xmlreader/examples/relaxNG.rng b/ext/xmlreader/examples/relaxNG.rng new file mode 100644 index 0000000..f4357e0 --- /dev/null +++ b/ext/xmlreader/examples/relaxNG.rng @@ -0,0 +1,11 @@ +<?xml version="1.0" encoding="iso-8859-1"?> +<grammar xmlns="http://relaxng.org/ns/structure/1.0" + datatypeLibrary="http://www.w3.org/2001/XMLSchema-datatypes"> + +<include href="relaxNG2.rng"> +<define name="TEI.prose"><ref name="INCLUDE"/></define> +</include> +</grammar> + + + diff --git a/ext/xmlreader/examples/relaxNG.xml b/ext/xmlreader/examples/relaxNG.xml new file mode 100644 index 0000000..6b0cac1 --- /dev/null +++ b/ext/xmlreader/examples/relaxNG.xml @@ -0,0 +1 @@ +<TEI.2>hello</TEI.2>
\ No newline at end of file diff --git a/ext/xmlreader/examples/relaxNG2.rng b/ext/xmlreader/examples/relaxNG2.rng new file mode 100644 index 0000000..4adae7b --- /dev/null +++ b/ext/xmlreader/examples/relaxNG2.rng @@ -0,0 +1,23 @@ +<?xml version="1.0" encoding="utf-8"?> +<grammar xmlns="http://relaxng.org/ns/structure/1.0" xmlns:t="http://www.thaiopensource.com/ns/annotations" xmlns:a="http://relaxng.org/ns/compatibility/annotations/1.0" datatypeLibrary="http://www.w3.org/2001/XMLSchema-datatypes"> + + <start> + <ref name="TEI.2"/> + </start> + <define name="IGNORE"> + <notAllowed/> + </define> + <define name="INCLUDE"> + <empty/> + </define> + + + <include href="relaxNG3.rng"/> + + <define name="TEI.2"> + <element name="TEI.2"> + <text/> + </element> + </define> + +</grammar>
\ No newline at end of file diff --git a/ext/xmlreader/examples/relaxNG3.rng b/ext/xmlreader/examples/relaxNG3.rng new file mode 100644 index 0000000..73e1eb6 --- /dev/null +++ b/ext/xmlreader/examples/relaxNG3.rng @@ -0,0 +1,8 @@ +<?xml version="1.0" encoding="utf-8"?> +<grammar xmlns="http://relaxng.org/ns/structure/1.0" xmlns:t="http://www.thaiopensource.com/ns/annotations" xmlns:a="http://relaxng.org/ns/compatibility/annotations/1.0" datatypeLibrary="http://www.w3.org/2001/XMLSchema-datatypes"> + + <define name="TEI.prose" combine="interleave"> + <ref name="IGNORE"/> + </define> + +</grammar>
\ No newline at end of file diff --git a/ext/xmlreader/examples/xmlreader.xml b/ext/xmlreader/examples/xmlreader.xml new file mode 100644 index 0000000..4c53743 --- /dev/null +++ b/ext/xmlreader/examples/xmlreader.xml @@ -0,0 +1,10 @@ +<books> + <book num="1"> + <title>The Grapes of Wrath</title> + <author>John Steinbeck</author> + </book> + <book num="2"> + <title>The Pearl</title> + <author>John Steinbeck</author> + </book> +</books> diff --git a/ext/xmlreader/examples/xmlreader_file.php b/ext/xmlreader/examples/xmlreader_file.php new file mode 100644 index 0000000..531e20b --- /dev/null +++ b/ext/xmlreader/examples/xmlreader_file.php @@ -0,0 +1,20 @@ +<?php +$reader = new XMLReader(); +$reader->open('xmlreader.xml'); +while ($reader->read()) { + if ($reader->nodeType != XMLREADER::END_ELEMENT) { + print "Node Name: ".$reader->name."\n"; + print "Node Value: ".$reader->value."\n"; + print "Node Depth: ".$reader->depth."\n"; + if ($reader->nodeType==XMLREADER::ELEMENT && $reader->hasAttributes) { + $attr = $reader->moveToFirstAttribute(); + while ($attr) { + print " Attribute Name: ".$reader->name."\n"; + print " Attribute Value: ".$reader->value."\n"; + $attr = $reader->moveToNextAttribute(); + } + } + print "\n"; + } +} +?> diff --git a/ext/xmlreader/examples/xmlreader_relaxNG.php b/ext/xmlreader/examples/xmlreader_relaxNG.php new file mode 100644 index 0000000..e56739a --- /dev/null +++ b/ext/xmlreader/examples/xmlreader_relaxNG.php @@ -0,0 +1,25 @@ +<?php +$indent = 5; /* Number of spaces to indent per level */ + +$reader = new XMLReader(); +$reader->open('relaxNG.xml'); +/* +Example setting relaxNG using string: +$reader->setRelaxNGSchemaSource(file_get_contents('relaxNG.rng')); +*/ +if ($reader->setRelaxNGSchema('relaxNG.rng')) { + while ($reader->read()) { + /* Print node name indenting it based on depth and $indent var */ + print str_repeat(" ", $reader->depth * $indent).$reader->name."\n"; + } +} + +print "\n"; + +if (! $reader->isValid()) { + print "Document is not valid\n"; +} else { + print "Document is valid\n"; +} + +?>
\ No newline at end of file diff --git a/ext/xmlreader/examples/xmlreader_string.php b/ext/xmlreader/examples/xmlreader_string.php new file mode 100644 index 0000000..f267245 --- /dev/null +++ b/ext/xmlreader/examples/xmlreader_string.php @@ -0,0 +1,31 @@ +<?php +$xmlstring = '<books> + <book num="1"> + <title>The Grapes of Wrath</title> + <author>John Steinbeck</author> + </book> + <book num="2"> + <title>The Pearl</title> + <author>John Steinbeck</author> + </book> +</books>'; + +$reader = new XMLReader(); +$reader->XML($xmlstring); +while ($reader->read()) { + if ($reader->nodeType != XMLREADER::END_ELEMENT) { + print "Node Name: ".$reader->name."\n"; + print "Node Value: ".$reader->value."\n"; + print "Node Depth: ".$reader->depth."\n"; + if ($reader->nodeType==XMLREADER::ELEMENT && $reader->hasAttributes) { + $attr = $reader->moveToFirstAttribute(); + while ($attr) { + print " Attribute Name: ".$reader->name."\n"; + print " Attribute Value: ".$reader->value."\n"; + $attr = $reader->moveToNextAttribute(); + } + } + print "\n"; + } +} +?> diff --git a/ext/xmlreader/examples/xmlreader_validatedtd.php b/ext/xmlreader/examples/xmlreader_validatedtd.php new file mode 100644 index 0000000..520a61e --- /dev/null +++ b/ext/xmlreader/examples/xmlreader_validatedtd.php @@ -0,0 +1,18 @@ +<?php +$indent = 5; /* Number of spaces to indent per level */ + +$xml = new XMLReader(); +$xml->open("dtdexample.xml"); +$xml->setParserProperty(XMLREADER::LOADDTD, TRUE); +$xml->setParserProperty(XMLREADER::VALIDATE, TRUE); +while($xml->read()) { + /* Print node name indenting it based on depth and $indent var */ + print str_repeat(" ", $xml->depth * $indent).$xml->name."\n"; + if ($xml->hasAttributes) { + $attCount = $xml->attributeCount; + print str_repeat(" ", $xml->depth * $indent)." Number of Attributes: ".$xml->attributeCount."\n"; + } +} +print "\n\nValid:\n"; +var_dump($xml->isValid()); +?>
\ No newline at end of file diff --git a/ext/xmlreader/package.xml b/ext/xmlreader/package.xml new file mode 100644 index 0000000..6536b78 --- /dev/null +++ b/ext/xmlreader/package.xml @@ -0,0 +1,75 @@ +<?xml version="1.0" encoding="ISO-8859-1" ?> +<!DOCTYPE package SYSTEM "../package.dtd"> +<package> + <name>xmlreader</name> + <summary>Provides fast, non-cached, forward-only access to XML data under PHP 5.</summary> + <description> + This extension wraps the libxml xmlReader API. The reader acts as a cursor + going forward on the document stream and stopping at each node in the way. + xmlReader is similar to SAX though uses a much simpler API. + </description> + <license>PHP License</license> + <maintainers> + <maintainer> + <user>rrichards</user> + <name>Rob Richards</name> + <email>rrichards@php.net</email> + <role>lead</role> + </maintainer> + <maintainer> + <user>chregu</user> + <role>lead</role> + <name>Christian Stocker</name> + <email>chregu@php.net</email> + </maintainer> + </maintainers> + + <release> + <version>1.0.1</version> + <date>2005-04-30</date> + <state>stable</state> + <notes> + Add workaround for next() bug when using libxml 2.6.17 and lower. + </notes> + </release> + + <changelog> + <release> + <version>1.0</version> + <date>2004-07-27</date> + <state>stable</state> + <notes> + Add name parameter to next() to skip to next named sibling node. + </notes> + </release> + </changelog> + + <configureoptions> + <configureoption name="with-xmlreader" default="autodetect" prompt="Include XMLReader support?"/> + </configureoptions> + <filelist> + <file role="src" name="config.m4"/> + <file role="src" name="config.w32"/> + <file role="src" name="php_xmlreader.c"/> + <file role="src" name="php_xmlreader.h"/> + + <file role="doc" name="CREDITS"/> + <file role="doc" name="TODO"/> + <file role="doc" name="README"/> + <file role="doc" name="examples/xmlreader_file.php"/> + <file role="doc" name="examples/xmlreader_string.php"/> + <file role="doc" name="examples/xmlreader.xml"/> + <file role="doc" name="examples/xmlreader_validatedtd.php"/> + <file role="doc" name="examples/dtdexample.xml"/> + <file role="doc" name="examples/dtdexample.dtd"/> + <file role="doc" name="examples/xmlreader_relaxNG.php"/> + <file role="doc" name="examples/relaxNG.xml"/> + <file role="doc" name="examples/relaxNG.rng"/> + <file role="doc" name="examples/relaxNG2.rng"/> + <file role="doc" name="examples/relaxNG3.rng"/> + </filelist> + <deps> + <dep type="php" rel="ge" version="5" /> + <dep type="ext" rel="has">libxml</dep> + </deps> +</package> diff --git a/ext/xmlreader/php_xmlreader.c b/ext/xmlreader/php_xmlreader.c new file mode 100644 index 0000000..314be45 --- /dev/null +++ b/ext/xmlreader/php_xmlreader.c @@ -0,0 +1,1410 @@ +/* + +----------------------------------------------------------------------+ + | PHP Version 5 | + +----------------------------------------------------------------------+ + | Copyright (c) 1997-2013 The PHP Group | + +----------------------------------------------------------------------+ + | This source file is subject to version 3.01 of the PHP license, | + | that is bundled with this package in the file LICENSE, and is | + | available through the world-wide-web at the following url: | + | http://www.php.net/license/3_01.txt | + | If you did not receive a copy of the PHP license and are unable to | + | obtain it through the world-wide-web, please send a note to | + | license@php.net so we can mail you a copy immediately. | + +----------------------------------------------------------------------+ + | Author: Rob Richards <rrichards@php.net> | + +----------------------------------------------------------------------+ +*/ + +/* $Id$ */ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + + +#include "php.h" +#include "php_ini.h" +#include "ext/standard/info.h" +#include "php_xmlreader.h" +#ifdef HAVE_DOM +#include "ext/dom/xml_common.h" +#endif +#include <libxml/xmlreader.h> +#include <libxml/uri.h> + +zend_class_entry *xmlreader_class_entry; + +static zend_object_handlers xmlreader_object_handlers; + +static HashTable xmlreader_prop_handlers; + +typedef int (*xmlreader_read_int_t)(xmlTextReaderPtr reader); +typedef unsigned char *(*xmlreader_read_char_t)(xmlTextReaderPtr reader); +typedef const unsigned char *(*xmlreader_read_const_char_t)(xmlTextReaderPtr reader); +typedef int (*xmlreader_write_t)(xmlreader_object *obj, zval *newval TSRMLS_DC); + +typedef unsigned char *(*xmlreader_read_one_char_t)(xmlTextReaderPtr reader, const unsigned char *); + +typedef struct _xmlreader_prop_handler { + xmlreader_read_int_t read_int_func; + xmlreader_read_const_char_t read_char_func; + xmlreader_write_t write_func; + int type; +} xmlreader_prop_handler; + +#define XMLREADER_LOAD_STRING 0 +#define XMLREADER_LOAD_FILE 1 + +/* {{{ xmlreader_register_prop_handler */ +static void xmlreader_register_prop_handler(HashTable *prop_handler, char *name, xmlreader_read_int_t read_int_func, xmlreader_read_const_char_t read_char_func, int rettype TSRMLS_DC) +{ + xmlreader_prop_handler hnd; + + hnd.read_char_func = read_char_func; + hnd.read_int_func = read_int_func; + hnd.type = rettype; + zend_hash_add(prop_handler, name, strlen(name)+1, &hnd, sizeof(xmlreader_prop_handler), NULL); +} +/* }}} */ + +/* {{{ xmlreader_property_reader */ +static int xmlreader_property_reader(xmlreader_object *obj, xmlreader_prop_handler *hnd, zval **retval TSRMLS_DC) +{ + const xmlChar *retchar = NULL; + int retint = 0; + + if (obj->ptr != NULL) { + if (hnd->read_char_func) { + retchar = hnd->read_char_func(obj->ptr); + } else { + if (hnd->read_int_func) { + retint = hnd->read_int_func(obj->ptr); + if (retint == -1) { + php_error_docref(NULL TSRMLS_CC, E_WARNING, "Internal libxml error returned"); + return FAILURE; + } + } + } + } + + ALLOC_ZVAL(*retval); + + switch (hnd->type) { + case IS_STRING: + if (retchar) { + ZVAL_STRING(*retval, (char *) retchar, 1); + } else { + ZVAL_EMPTY_STRING(*retval); + } + break; + case IS_BOOL: + ZVAL_BOOL(*retval, retint); + break; + case IS_LONG: + ZVAL_LONG(*retval, retint); + break; + default: + ZVAL_NULL(*retval); + } + + return SUCCESS; +} +/* }}} */ + +/* {{{ xmlreader_get_property_ptr_ptr */ +zval **xmlreader_get_property_ptr_ptr(zval *object, zval *member, const zend_literal *key TSRMLS_DC) +{ + xmlreader_object *obj; + zval tmp_member; + zval **retval = NULL; + xmlreader_prop_handler *hnd; + zend_object_handlers *std_hnd; + int ret = FAILURE; + + if (member->type != IS_STRING) { + tmp_member = *member; + zval_copy_ctor(&tmp_member); + convert_to_string(&tmp_member); + member = &tmp_member; + } + + obj = (xmlreader_object *)zend_objects_get_address(object TSRMLS_CC); + + if (obj->prop_handler != NULL) { + ret = zend_hash_find(obj->prop_handler, Z_STRVAL_P(member), Z_STRLEN_P(member)+1, (void **) &hnd); + } + if (ret == FAILURE) { + std_hnd = zend_get_std_object_handlers(); + retval = std_hnd->get_property_ptr_ptr(object, member, key TSRMLS_CC); + } + + if (member == &tmp_member) { + zval_dtor(member); + } + return retval; +} +/* }}} */ + +/* {{{ xmlreader_read_property */ +zval *xmlreader_read_property(zval *object, zval *member, int type, const zend_literal *key TSRMLS_DC) +{ + xmlreader_object *obj; + zval tmp_member; + zval *retval; + xmlreader_prop_handler *hnd; + zend_object_handlers *std_hnd; + int ret; + + if (member->type != IS_STRING) { + tmp_member = *member; + zval_copy_ctor(&tmp_member); + convert_to_string(&tmp_member); + member = &tmp_member; + } + + ret = FAILURE; + obj = (xmlreader_object *)zend_objects_get_address(object TSRMLS_CC); + + if (obj->prop_handler != NULL) { + ret = zend_hash_find(obj->prop_handler, Z_STRVAL_P(member), Z_STRLEN_P(member)+1, (void **) &hnd); + } + if (ret == SUCCESS) { + ret = xmlreader_property_reader(obj, hnd, &retval TSRMLS_CC); + if (ret == SUCCESS) { + /* ensure we're creating a temporary variable */ + Z_SET_REFCOUNT_P(retval, 0); + } else { + retval = EG(uninitialized_zval_ptr); + } + } else { + std_hnd = zend_get_std_object_handlers(); + retval = std_hnd->read_property(object, member, type, key TSRMLS_CC); + } + + if (member == &tmp_member) { + zval_dtor(member); + } + return retval; +} +/* }}} */ + +/* {{{ xmlreader_write_property */ +void xmlreader_write_property(zval *object, zval *member, zval *value, const zend_literal *key TSRMLS_DC) +{ + xmlreader_object *obj; + zval tmp_member; + xmlreader_prop_handler *hnd; + zend_object_handlers *std_hnd; + int ret; + + if (member->type != IS_STRING) { + tmp_member = *member; + zval_copy_ctor(&tmp_member); + convert_to_string(&tmp_member); + member = &tmp_member; + } + + ret = FAILURE; + obj = (xmlreader_object *)zend_objects_get_address(object TSRMLS_CC); + + if (obj->prop_handler != NULL) { + ret = zend_hash_find((HashTable *)obj->prop_handler, Z_STRVAL_P(member), Z_STRLEN_P(member)+1, (void **) &hnd); + } + if (ret == SUCCESS) { + php_error_docref(NULL TSRMLS_CC, E_WARNING, "Cannot write to read-only property"); + } else { + std_hnd = zend_get_std_object_handlers(); + std_hnd->write_property(object, member, value, key TSRMLS_CC); + } + + if (member == &tmp_member) { + zval_dtor(member); + } +} +/* }}} */ + +/* {{{ _xmlreader_get_valid_file_path */ +/* _xmlreader_get_valid_file_path and _xmlreader_get_relaxNG should be made a + common function in libxml extension as code is common to a few xml extensions */ +char *_xmlreader_get_valid_file_path(char *source, char *resolved_path, int resolved_path_len TSRMLS_DC) { + xmlURI *uri; + xmlChar *escsource; + char *file_dest; + int isFileUri = 0; + + uri = xmlCreateURI(); + escsource = xmlURIEscapeStr((xmlChar *)source, (xmlChar *)":"); + xmlParseURIReference(uri, (const char *)escsource); + xmlFree(escsource); + + if (uri->scheme != NULL) { + /* absolute file uris - libxml only supports localhost or empty host */ + if (strncasecmp(source, "file:///",8) == 0) { + isFileUri = 1; +#ifdef PHP_WIN32 + source += 8; +#else + source += 7; +#endif + } else if (strncasecmp(source, "file://localhost/",17) == 0) { + isFileUri = 1; +#ifdef PHP_WIN32 + source += 17; +#else + source += 16; +#endif + } + } + + file_dest = source; + + if ((uri->scheme == NULL || isFileUri)) { + if (!VCWD_REALPATH(source, resolved_path) && !expand_filepath(source, resolved_path TSRMLS_CC)) { + xmlFreeURI(uri); + return NULL; + } + file_dest = resolved_path; + } + + xmlFreeURI(uri); + + return file_dest; +} +/* }}} */ + +#ifdef LIBXML_SCHEMAS_ENABLED +/* {{{ _xmlreader_get_relaxNG */ +static xmlRelaxNGPtr _xmlreader_get_relaxNG(char *source, int source_len, int type, + xmlRelaxNGValidityErrorFunc error_func, + xmlRelaxNGValidityWarningFunc warn_func TSRMLS_DC) +{ + char *valid_file = NULL; + xmlRelaxNGParserCtxtPtr parser = NULL; + xmlRelaxNGPtr sptr; + char resolved_path[MAXPATHLEN + 1]; + + switch (type) { + case XMLREADER_LOAD_FILE: + valid_file = _xmlreader_get_valid_file_path(source, resolved_path, MAXPATHLEN TSRMLS_CC); + if (!valid_file) { + return NULL; + } + parser = xmlRelaxNGNewParserCtxt(valid_file); + break; + case XMLREADER_LOAD_STRING: + parser = xmlRelaxNGNewMemParserCtxt(source, source_len); + /* If loading from memory, we need to set the base directory for the document + but it is not apparent how to do that for schema's */ + break; + default: + return NULL; + } + + if (parser == NULL) { + return NULL; + } + + if (error_func || warn_func) { + xmlRelaxNGSetParserErrors(parser, + (xmlRelaxNGValidityErrorFunc) error_func, + (xmlRelaxNGValidityWarningFunc) warn_func, + parser); + } + sptr = xmlRelaxNGParse(parser); + xmlRelaxNGFreeParserCtxt(parser); + + return sptr; +} +/* }}} */ +#endif + +static const zend_module_dep xmlreader_deps[] = { + ZEND_MOD_REQUIRED("libxml") + ZEND_MOD_END +}; + +/* {{{ xmlreader_module_entry + */ +zend_module_entry xmlreader_module_entry = { + STANDARD_MODULE_HEADER_EX, NULL, + xmlreader_deps, + "xmlreader", + NULL, + PHP_MINIT(xmlreader), + PHP_MSHUTDOWN(xmlreader), + NULL, + NULL, + PHP_MINFO(xmlreader), + "0.1", /* Replace with version number for your extension */ + STANDARD_MODULE_PROPERTIES +}; +/* }}} */ + +#ifdef COMPILE_DL_XMLREADER +ZEND_GET_MODULE(xmlreader) +#endif + +/* {{{ xmlreader_objects_clone */ +void xmlreader_objects_clone(void *object, void **object_clone TSRMLS_DC) +{ + /* TODO */ +} +/* }}} */ + +/* {{{ xmlreader_free_resources */ +static void xmlreader_free_resources(xmlreader_object *intern) { + if (intern) { + if (intern->input) { + xmlFreeParserInputBuffer(intern->input); + intern->input = NULL; + } + + if (intern->ptr) { + xmlFreeTextReader(intern->ptr); + intern->ptr = NULL; + } +#ifdef LIBXML_SCHEMAS_ENABLED + if (intern->schema) { + xmlRelaxNGFree((xmlRelaxNGPtr) intern->schema); + intern->schema = NULL; + } +#endif + } +} +/* }}} */ + +/* {{{ xmlreader_objects_free_storage */ +void xmlreader_objects_free_storage(void *object TSRMLS_DC) +{ + xmlreader_object *intern = (xmlreader_object *)object; + + zend_object_std_dtor(&intern->std TSRMLS_CC); + + xmlreader_free_resources(intern); + + efree(object); +} +/* }}} */ + +/* {{{ xmlreader_objects_new */ +zend_object_value xmlreader_objects_new(zend_class_entry *class_type TSRMLS_DC) +{ + zend_object_value retval; + xmlreader_object *intern; + + intern = emalloc(sizeof(xmlreader_object)); + memset(&intern->std, 0, sizeof(zend_object)); + intern->ptr = NULL; + intern->input = NULL; + intern->schema = NULL; + intern->prop_handler = &xmlreader_prop_handlers; + + zend_object_std_init(&intern->std, class_type TSRMLS_CC); + object_properties_init(&intern->std, class_type); + retval.handle = zend_objects_store_put(intern, (zend_objects_store_dtor_t)zend_objects_destroy_object, (zend_objects_free_object_storage_t) xmlreader_objects_free_storage, xmlreader_objects_clone TSRMLS_CC); + intern->handle = retval.handle; + retval.handlers = &xmlreader_object_handlers; + return retval; +} +/* }}} */ + +/* {{{ php_xmlreader_string_arg */ +static void php_xmlreader_string_arg(INTERNAL_FUNCTION_PARAMETERS, xmlreader_read_one_char_t internal_function) { + zval *id; + int name_len = 0; + char *retchar = NULL; + xmlreader_object *intern; + char *name; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &name, &name_len) == FAILURE) { + return; + } + + if (!name_len) { + php_error_docref(NULL TSRMLS_CC, E_WARNING, "Argument cannot be an empty string"); + RETURN_FALSE; + } + + id = getThis(); + + intern = (xmlreader_object *)zend_object_store_get_object(id TSRMLS_CC); + if (intern && intern->ptr) { + retchar = (char *)internal_function(intern->ptr, (const unsigned char *)name); + } + if (retchar) { + RETVAL_STRING(retchar, 1); + xmlFree(retchar); + return; + } else { + RETVAL_NULL(); + } +} +/* }}} */ + +/* {{{ php_xmlreader_no_arg */ +static void php_xmlreader_no_arg(INTERNAL_FUNCTION_PARAMETERS, xmlreader_read_int_t internal_function) { + zval *id; + int retval; + xmlreader_object *intern; + + id = getThis(); + + intern = (xmlreader_object *)zend_object_store_get_object(id TSRMLS_CC); + if (intern && intern->ptr) { + retval = internal_function(intern->ptr); + if (retval == 1) { + RETURN_TRUE; + } + } + + RETURN_FALSE; +} +/* }}} */ + +#if LIBXML_VERSION >= 20620 +/* {{{ php_xmlreader_no_arg_string */ +static void php_xmlreader_no_arg_string(INTERNAL_FUNCTION_PARAMETERS, xmlreader_read_char_t internal_function) { + zval *id; + char *retchar = NULL; + xmlreader_object *intern; + + id = getThis(); + + intern = (xmlreader_object *)zend_object_store_get_object(id TSRMLS_CC); + if (intern && intern->ptr) { + retchar = (char *)internal_function(intern->ptr); + } + if (retchar) { + RETVAL_STRING(retchar, 1); + xmlFree(retchar); + return; + } else { + RETVAL_EMPTY_STRING(); + } +} +/* }}} */ +#endif + +/* {{{ php_xmlreader_set_relaxng_schema */ +static void php_xmlreader_set_relaxng_schema(INTERNAL_FUNCTION_PARAMETERS, int type) { +#ifdef LIBXML_SCHEMAS_ENABLED + zval *id; + int source_len = 0, retval = -1; + xmlreader_object *intern; + xmlRelaxNGPtr schema = NULL; + char *source; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "p!", &source, &source_len) == FAILURE) { + return; + } + + if (source != NULL && !source_len) { + php_error_docref(NULL TSRMLS_CC, E_WARNING, "Schema data source is required"); + RETURN_FALSE; + } + + id = getThis(); + + intern = (xmlreader_object *)zend_object_store_get_object(id TSRMLS_CC); + if (intern && intern->ptr) { + if (source) { + schema = _xmlreader_get_relaxNG(source, source_len, type, NULL, NULL TSRMLS_CC); + if (schema) { + retval = xmlTextReaderRelaxNGSetSchema(intern->ptr, schema); + } + } else { + /* unset the associated relaxNG context and schema if one exists */ + retval = xmlTextReaderRelaxNGSetSchema(intern->ptr, NULL); + } + + if (retval == 0) { + if (intern->schema) { + xmlRelaxNGFree((xmlRelaxNGPtr) intern->schema); + } + + intern->schema = schema; + + RETURN_TRUE; + } + } + + php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to set schema. This must be set prior to reading or schema contains errors."); + + RETURN_FALSE; +#else + php_error_docref(NULL TSRMLS_CC, E_WARNING, "No Schema support built into libxml."); + + RETURN_FALSE; +#endif +} +/* }}} */ + +/* {{{ proto boolean XMLReader::close() +Closes xmlreader - current frees resources until xmlTextReaderClose is fixed in libxml */ +PHP_METHOD(xmlreader, close) +{ + zval *id; + xmlreader_object *intern; + + id = getThis(); + intern = (xmlreader_object *)zend_object_store_get_object(id TSRMLS_CC); + /* libxml is segfaulting in versions up to 2.6.8 using xmlTextReaderClose so for + now we will free the whole reader when close is called as it would get rebuilt on + a new load anyways */ + xmlreader_free_resources(intern); + + RETURN_TRUE; +} +/* }}} */ + +/* {{{ proto string XMLReader::getAttribute(string name) +Get value of an attribute from current element */ +PHP_METHOD(xmlreader, getAttribute) +{ + php_xmlreader_string_arg(INTERNAL_FUNCTION_PARAM_PASSTHRU, xmlTextReaderGetAttribute); +} +/* }}} */ + +/* {{{ proto string XMLReader::getAttributeNo(int index) +Get value of an attribute at index from current element */ +PHP_METHOD(xmlreader, getAttributeNo) +{ + zval *id; + long attr_pos; + char *retchar = NULL; + xmlreader_object *intern; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &attr_pos) == FAILURE) { + return; + } + + id = getThis(); + + intern = (xmlreader_object *)zend_object_store_get_object(id TSRMLS_CC); + if (intern && intern->ptr) { + retchar = (char *)xmlTextReaderGetAttributeNo(intern->ptr, attr_pos); + } + if (retchar) { + RETVAL_STRING(retchar, 1); + xmlFree(retchar); + return; + } else { + RETURN_EMPTY_STRING(); + } +} +/* }}} */ + +/* {{{ proto string XMLReader::getAttributeNs(string name, string namespaceURI) +Get value of a attribute via name and namespace from current element */ +PHP_METHOD(xmlreader, getAttributeNs) +{ + zval *id; + int name_len = 0, ns_uri_len = 0; + xmlreader_object *intern; + char *name, *ns_uri, *retchar = NULL; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ss", &name, &name_len, &ns_uri, &ns_uri_len) == FAILURE) { + return; + } + + if (name_len == 0 || ns_uri_len == 0) { + php_error_docref(NULL TSRMLS_CC, E_WARNING, "Attribute Name and Namespace URI cannot be empty"); + RETURN_FALSE; + } + + id = getThis(); + + intern = (xmlreader_object *)zend_object_store_get_object(id TSRMLS_CC); + if (intern && intern->ptr) { + retchar = (char *)xmlTextReaderGetAttributeNs(intern->ptr, (xmlChar *)name, (xmlChar *)ns_uri); + } + if (retchar) { + RETVAL_STRING(retchar, 1); + xmlFree(retchar); + return; + } else { + RETURN_EMPTY_STRING(); + } +} +/* }}} */ + +/* {{{ proto boolean XMLReader::getParserProperty(int property) +Indicates whether given property (one of the parser option constants) is set or not on parser */ +PHP_METHOD(xmlreader, getParserProperty) +{ + zval *id; + long property; + int retval = -1; + xmlreader_object *intern; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &property) == FAILURE) { + return; + } + + id = getThis(); + + intern = (xmlreader_object *)zend_object_store_get_object(id TSRMLS_CC); + if (intern && intern->ptr) { + retval = xmlTextReaderGetParserProp(intern->ptr,property); + } + if (retval == -1) { + php_error_docref(NULL TSRMLS_CC, E_WARNING, "Invalid parser property"); + RETURN_FALSE; + } + + RETURN_BOOL(retval); +} +/* }}} */ + +/* {{{ proto boolean XMLReader::isValid() +Returns boolean indicating if parsed document is valid or not. +Must set XMLREADER_LOADDTD or XMLREADER_VALIDATE parser option prior to the first call to read +or this method will always return FALSE */ +PHP_METHOD(xmlreader, isValid) +{ + php_xmlreader_no_arg(INTERNAL_FUNCTION_PARAM_PASSTHRU, xmlTextReaderIsValid); +} +/* }}} */ + +/* {{{ proto string XMLReader::lookupNamespace(string prefix) +Return namespaceURI for associated prefix on current node */ +PHP_METHOD(xmlreader, lookupNamespace) +{ + php_xmlreader_string_arg(INTERNAL_FUNCTION_PARAM_PASSTHRU, xmlTextReaderLookupNamespace); +} +/* }}} */ + +/* {{{ proto boolean XMLReader::moveToAttribute(string name) +Positions reader at specified attribute - Returns TRUE on success and FALSE on failure */ +PHP_METHOD(xmlreader, moveToAttribute) +{ + zval *id; + int name_len = 0, retval; + xmlreader_object *intern; + char *name; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &name, &name_len) == FAILURE) { + return; + } + + if (name_len == 0) { + php_error_docref(NULL TSRMLS_CC, E_WARNING, "Attribute Name is required"); + RETURN_FALSE; + } + + id = getThis(); + + intern = (xmlreader_object *)zend_object_store_get_object(id TSRMLS_CC); + if (intern && intern->ptr) { + retval = xmlTextReaderMoveToAttribute(intern->ptr, (xmlChar *)name); + if (retval == 1) { + RETURN_TRUE; + } + } + + RETURN_FALSE; +} +/* }}} */ + +/* {{{ proto boolean XMLReader::moveToAttributeNo(int index) +Positions reader at attribute at spcecified index. +Returns TRUE on success and FALSE on failure */ +PHP_METHOD(xmlreader, moveToAttributeNo) +{ + zval *id; + long attr_pos; + int retval; + xmlreader_object *intern; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &attr_pos) == FAILURE) { + return; + } + + id = getThis(); + + intern = (xmlreader_object *)zend_object_store_get_object(id TSRMLS_CC); + if (intern && intern->ptr) { + retval = xmlTextReaderMoveToAttributeNo(intern->ptr, attr_pos); + if (retval == 1) { + RETURN_TRUE; + } + } + + RETURN_FALSE; +} +/* }}} */ + +/* {{{ proto boolean XMLReader::moveToAttributeNs(string name, string namespaceURI) +Positions reader at attribute spcified by name and namespaceURI. +Returns TRUE on success and FALSE on failure */ +PHP_METHOD(xmlreader, moveToAttributeNs) +{ + zval *id; + int name_len=0, ns_uri_len=0, retval; + xmlreader_object *intern; + char *name, *ns_uri; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ss", &name, &name_len, &ns_uri, &ns_uri_len) == FAILURE) { + return; + } + + if (name_len == 0 || ns_uri_len == 0) { + php_error_docref(NULL TSRMLS_CC, E_WARNING, "Attribute Name and Namespace URI cannot be empty"); + RETURN_FALSE; + } + + id = getThis(); + + intern = (xmlreader_object *)zend_object_store_get_object(id TSRMLS_CC); + if (intern && intern->ptr) { + retval = xmlTextReaderMoveToAttributeNs(intern->ptr, (xmlChar *)name, (xmlChar *)ns_uri); + if (retval == 1) { + RETURN_TRUE; + } + } + + RETURN_FALSE; +} +/* }}} */ + +/* {{{ proto boolean XMLReader::moveToElement() +Moves the position of the current instance to the node that contains the current Attribute node. */ +PHP_METHOD(xmlreader, moveToElement) +{ + php_xmlreader_no_arg(INTERNAL_FUNCTION_PARAM_PASSTHRU, xmlTextReaderMoveToElement); +} +/* }}} */ + +/* {{{ proto boolean XMLReader::moveToFirstAttribute() +Moves the position of the current instance to the first attribute associated with the current node. */ +PHP_METHOD(xmlreader, moveToFirstAttribute) +{ + php_xmlreader_no_arg(INTERNAL_FUNCTION_PARAM_PASSTHRU, xmlTextReaderMoveToFirstAttribute); +} +/* }}} */ + +/* {{{ proto boolean XMLReader::moveToNextAttribute() +Moves the position of the current instance to the next attribute associated with the current node. */ +PHP_METHOD(xmlreader, moveToNextAttribute) +{ + php_xmlreader_no_arg(INTERNAL_FUNCTION_PARAM_PASSTHRU, xmlTextReaderMoveToNextAttribute); +} +/* }}} */ + +/* {{{ proto boolean XMLReader::read() +Moves the position of the current instance to the next node in the stream. */ +PHP_METHOD(xmlreader, read) +{ + zval *id; + int retval; + xmlreader_object *intern; + + id = getThis(); + intern = (xmlreader_object *)zend_object_store_get_object(id TSRMLS_CC); + if (intern != NULL && intern->ptr != NULL) { + retval = xmlTextReaderRead(intern->ptr); + if (retval == -1) { + php_error_docref(NULL TSRMLS_CC, E_WARNING, "An Error Occured while reading"); + RETURN_FALSE; + } else { + RETURN_BOOL(retval); + } + } + + php_error_docref(NULL TSRMLS_CC, E_WARNING, "Load Data before trying to read"); + RETURN_FALSE; +} +/* }}} */ + +/* {{{ proto boolean XMLReader::next([string localname]) +Moves the position of the current instance to the next node in the stream. */ +PHP_METHOD(xmlreader, next) +{ + zval *id; + int retval, name_len=0; + xmlreader_object *intern; + char *name = NULL; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|s", &name, &name_len) == FAILURE) { + return; + } + + id = getThis(); + intern = (xmlreader_object *)zend_object_store_get_object(id TSRMLS_CC); + if (intern != NULL && intern->ptr != NULL) { +#if LIBXML_VERSION <= 20617 + /* Bug in libxml prevents a next in certain cases when positioned on end of element */ + if (xmlTextReaderNodeType(intern->ptr) == XML_READER_TYPE_END_ELEMENT) { + retval = xmlTextReaderRead(intern->ptr); + } else +#endif + retval = xmlTextReaderNext(intern->ptr); + while (name != NULL && retval == 1) { + if (xmlStrEqual(xmlTextReaderConstLocalName(intern->ptr), (xmlChar *)name)) { + RETURN_TRUE; + } + retval = xmlTextReaderNext(intern->ptr); + } + if (retval == -1) { + php_error_docref(NULL TSRMLS_CC, E_WARNING, "An Error Occured while reading"); + RETURN_FALSE; + } else { + RETURN_BOOL(retval); + } + } + + php_error_docref(NULL TSRMLS_CC, E_WARNING, "Load Data before trying to read"); + RETURN_FALSE; +} +/* }}} */ + +/* {{{ proto boolean XMLReader::open(string URI [, string encoding [, int options]]) +Sets the URI that the XMLReader will parse. */ +PHP_METHOD(xmlreader, open) +{ + zval *id; + int source_len = 0, encoding_len = 0; + long options = 0; + xmlreader_object *intern = NULL; + char *source, *valid_file = NULL; + char *encoding = NULL; + char resolved_path[MAXPATHLEN + 1]; + xmlTextReaderPtr reader = NULL; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "p|s!l", &source, &source_len, &encoding, &encoding_len, &options) == FAILURE) { + return; + } + + id = getThis(); + if (id != NULL) { + if (! instanceof_function(Z_OBJCE_P(id), xmlreader_class_entry TSRMLS_CC)) { + id = NULL; + } else { + intern = (xmlreader_object *)zend_object_store_get_object(id TSRMLS_CC); + xmlreader_free_resources(intern); + } + } + + if (!source_len) { + php_error_docref(NULL TSRMLS_CC, E_WARNING, "Empty string supplied as input"); + RETURN_FALSE; + } + + valid_file = _xmlreader_get_valid_file_path(source, resolved_path, MAXPATHLEN TSRMLS_CC); + + if (valid_file) { + reader = xmlReaderForFile(valid_file, encoding, options); + } + + if (reader == NULL) { + php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to open source data"); + RETURN_FALSE; + } + + if (id == NULL) { + object_init_ex(return_value, xmlreader_class_entry); + intern = (xmlreader_object *)zend_objects_get_address(return_value TSRMLS_CC); + intern->ptr = reader; + return; + } + + intern->ptr = reader; + + RETURN_TRUE; + +} +/* }}} */ + +/* Not Yet Implemented in libxml - functions exist just not coded +PHP_METHOD(xmlreader, resetState) +{ + +} +*/ + +#if LIBXML_VERSION >= 20620 +/* {{{ proto string XMLReader::readInnerXml() +Reads the contents of the current node, including child nodes and markup. */ +PHP_METHOD(xmlreader, readInnerXml) +{ + php_xmlreader_no_arg_string(INTERNAL_FUNCTION_PARAM_PASSTHRU, xmlTextReaderReadInnerXml); +} +/* }}} */ + +/* {{{ proto boolean XMLReader::readOuterXml() +Reads the contents of the current node, including child nodes and markup. */ +PHP_METHOD(xmlreader, readOuterXml) +{ + php_xmlreader_no_arg_string(INTERNAL_FUNCTION_PARAM_PASSTHRU, xmlTextReaderReadOuterXml); +} +/* }}} */ + +/* {{{ proto boolean XMLReader::readString() +Reads the contents of an element or a text node as a string. */ +PHP_METHOD(xmlreader, readString) +{ + php_xmlreader_no_arg_string(INTERNAL_FUNCTION_PARAM_PASSTHRU, xmlTextReaderReadString); +} +/* }}} */ + +/* {{{ proto boolean XMLReader::setSchema(string filename) +Use W3C XSD schema to validate the document as it is processed. Activation is only possible before the first Read(). */ +PHP_METHOD(xmlreader, setSchema) +{ +#ifdef LIBXML_SCHEMAS_ENABLED + zval *id; + int source_len = 0, retval = -1; + xmlreader_object *intern; + char *source; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "p!", &source, &source_len) == FAILURE) { + return; + } + + if (source != NULL && !source_len) { + php_error_docref(NULL TSRMLS_CC, E_WARNING, "Schema data source is required"); + RETURN_FALSE; + } + + id = getThis(); + + intern = (xmlreader_object *)zend_object_store_get_object(id TSRMLS_CC); + if (intern && intern->ptr) { + retval = xmlTextReaderSchemaValidate(intern->ptr, source); + + if (retval == 0) { + RETURN_TRUE; + } + } + + php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to set schema. This must be set prior to reading or schema contains errors."); + + RETURN_FALSE; +#else + php_error_docref(NULL TSRMLS_CC, E_WARNING, "No Schema support built into libxml."); + + RETURN_FALSE; +#endif +} +/* }}} */ +#endif + +/* {{{ proto boolean XMLReader::setParserProperty(int property, boolean value) +Sets parser property (one of the parser option constants). +Properties must be set after open() or XML() and before the first read() is called */ +PHP_METHOD(xmlreader, setParserProperty) +{ + zval *id; + long property; + int retval = -1; + zend_bool value; + xmlreader_object *intern; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "lb", &property, &value) == FAILURE) { + return; + } + + id = getThis(); + + intern = (xmlreader_object *)zend_object_store_get_object(id TSRMLS_CC); + if (intern && intern->ptr) { + retval = xmlTextReaderSetParserProp(intern->ptr,property, value); + } + if (retval == -1) { + php_error_docref(NULL TSRMLS_CC, E_WARNING, "Invalid parser property"); + RETURN_FALSE; + } + + RETURN_TRUE; +} +/* }}} */ + +/* {{{ proto boolean XMLReader::setRelaxNGSchema(string filename) +Sets the string that the XMLReader will parse. */ +PHP_METHOD(xmlreader, setRelaxNGSchema) +{ + php_xmlreader_set_relaxng_schema(INTERNAL_FUNCTION_PARAM_PASSTHRU, XMLREADER_LOAD_FILE); +} +/* }}} */ + +/* {{{ proto boolean XMLReader::setRelaxNGSchemaSource(string source) +Sets the string that the XMLReader will parse. */ +PHP_METHOD(xmlreader, setRelaxNGSchemaSource) +{ + php_xmlreader_set_relaxng_schema(INTERNAL_FUNCTION_PARAM_PASSTHRU, XMLREADER_LOAD_STRING); +} +/* }}} */ + +/* TODO +XMLPUBFUN int XMLCALL + xmlTextReaderSetSchema (xmlTextReaderPtr reader, + xmlSchemaPtr schema); +*/ + +/* {{{ proto boolean XMLReader::XML(string source [, string encoding [, int options]]) +Sets the string that the XMLReader will parse. */ +PHP_METHOD(xmlreader, XML) +{ + zval *id; + int source_len = 0, encoding_len = 0; + long options = 0; + xmlreader_object *intern = NULL; + char *source, *uri = NULL, *encoding = NULL; + int resolved_path_len, ret = 0; + char *directory=NULL, resolved_path[MAXPATHLEN]; + xmlParserInputBufferPtr inputbfr; + xmlTextReaderPtr reader; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|s!l", &source, &source_len, &encoding, &encoding_len, &options) == FAILURE) { + return; + } + + id = getThis(); + if (id != NULL && ! instanceof_function(Z_OBJCE_P(id), xmlreader_class_entry TSRMLS_CC)) { + id = NULL; + } + if (id != NULL) { + intern = (xmlreader_object *)zend_object_store_get_object(id TSRMLS_CC); + xmlreader_free_resources(intern); + } + + if (!source_len) { + php_error_docref(NULL TSRMLS_CC, E_WARNING, "Empty string supplied as input"); + RETURN_FALSE; + } + + inputbfr = xmlParserInputBufferCreateMem(source, source_len, XML_CHAR_ENCODING_NONE); + + if (inputbfr != NULL) { +/* Get the URI of the current script so that we can set the base directory in libxml */ +#if HAVE_GETCWD + directory = VCWD_GETCWD(resolved_path, MAXPATHLEN); +#elif HAVE_GETWD + directory = VCWD_GETWD(resolved_path); +#endif + if (directory) { + resolved_path_len = strlen(resolved_path); + if (resolved_path[resolved_path_len - 1] != DEFAULT_SLASH) { + resolved_path[resolved_path_len] = DEFAULT_SLASH; + resolved_path[++resolved_path_len] = '\0'; + } + uri = (char *) xmlCanonicPath((const xmlChar *) resolved_path); + } + reader = xmlNewTextReader(inputbfr, uri); + + if (reader != NULL) { +#if LIBXML_VERSION >= 20628 + ret = xmlTextReaderSetup(reader, NULL, uri, encoding, options); +#endif + if (ret == 0) { + if (id == NULL) { + object_init_ex(return_value, xmlreader_class_entry); + intern = (xmlreader_object *)zend_objects_get_address(return_value TSRMLS_CC); + } else { + RETVAL_TRUE; + } + intern->input = inputbfr; + intern->ptr = reader; + + if (uri) { + xmlFree(uri); + } + + return; + } + } + } + + if (uri) { + xmlFree(uri); + } + + if (inputbfr) { + xmlFreeParserInputBuffer(inputbfr); + } + php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to load source data"); + RETURN_FALSE; +} +/* }}} */ + +/* {{{ proto boolean XMLReader::expand() +Moves the position of the current instance to the next node in the stream. */ +PHP_METHOD(xmlreader, expand) +{ +#ifdef HAVE_DOM + zval *id, *basenode = NULL; + int ret; + xmlreader_object *intern; + xmlNode *node, *nodec; + xmlDocPtr docp = NULL; + php_libxml_node_object *domobj = NULL; + + if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "O|O!", &id, xmlreader_class_entry, &basenode, dom_node_class_entry) == FAILURE) { + return; + } + + if (basenode != NULL) { + NODE_GET_OBJ(node, basenode, xmlNodePtr, domobj); + docp = node->doc; + } + + intern = (xmlreader_object *)zend_object_store_get_object(id TSRMLS_CC); + + if (intern && intern->ptr) { + node = xmlTextReaderExpand(intern->ptr); + + if (node == NULL) { + php_error_docref(NULL TSRMLS_CC, E_WARNING, "An Error Occured while expanding "); + RETURN_FALSE; + } else { + nodec = xmlDocCopyNode(node, docp, 1); + if (nodec == NULL) { + php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Cannot expand this node type"); + RETURN_FALSE; + } else { + DOM_RET_OBJ(nodec, &ret, (dom_object *)domobj); + } + } + } else { + php_error_docref(NULL TSRMLS_CC, E_WARNING, "Load Data before trying to expand"); + RETURN_FALSE; + } +#else + php_error(E_WARNING, "DOM support is not enabled"); + return; +#endif +} +/* }}} */ +/* {{{ arginfo */ +ZEND_BEGIN_ARG_INFO(arginfo_xmlreader_close, 0) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO(arginfo_xmlreader_getAttribute, 0) + ZEND_ARG_INFO(0, name) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO(arginfo_xmlreader_getAttributeNo, 0) + ZEND_ARG_INFO(0, index) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO(arginfo_xmlreader_getAttributeNs, 0) + ZEND_ARG_INFO(0, name) + ZEND_ARG_INFO(0, namespaceURI) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO(arginfo_xmlreader_getParserProperty, 0) + ZEND_ARG_INFO(0, property) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO(arginfo_xmlreader_isValid, 0) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO(arginfo_xmlreader_lookupNamespace, 0) +ZEND_ARG_INFO(0, prefix) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO(arginfo_xmlreader_moveToAttribute, 0) + ZEND_ARG_INFO(0, name) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO(arginfo_xmlreader_moveToAttributeNo, 0) + ZEND_ARG_INFO(0, index) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO(arginfo_xmlreader_moveToAttributeNs, 0) + ZEND_ARG_INFO(0, name) + ZEND_ARG_INFO(0, namespaceURI) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO(arginfo_xmlreader_moveToElement, 0) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO(arginfo_xmlreader_moveToFirstAttribute, 0) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO(arginfo_xmlreader_moveToNextAttribute, 0) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO(arginfo_xmlreader_read, 0) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_xmlreader_next, 0, 0, 0) + ZEND_ARG_INFO(0, localname) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_xmlreader_open, 0, 0, 1) + ZEND_ARG_INFO(0, URI) + ZEND_ARG_INFO(0, encoding) + ZEND_ARG_INFO(0, options) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO(arginfo_xmlreader_readInnerXml, 0) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO(arginfo_xmlreader_readOuterXml, 0) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO(arginfo_xmlreader_readString, 0) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO(arginfo_xmlreader_setSchema, 0) + ZEND_ARG_INFO(0, filename) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO(arginfo_xmlreader_setParserProperty, 0) + ZEND_ARG_INFO(0, property) + ZEND_ARG_INFO(0, value) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO(arginfo_xmlreader_setRelaxNGSchema, 0) + ZEND_ARG_INFO(0, filename) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO(arginfo_xmlreader_setRelaxNGSchemaSource, 0) + ZEND_ARG_INFO(0, source) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_xmlreader_XML, 0, 0, 1) + ZEND_ARG_INFO(0, source) + ZEND_ARG_INFO(0, encoding) + ZEND_ARG_INFO(0, options) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO(arginfo_xmlreader_expand, 0) +ZEND_END_ARG_INFO() +/* }}} */ + +static const zend_function_entry xmlreader_functions[] = { + PHP_ME(xmlreader, close, arginfo_xmlreader_close, ZEND_ACC_PUBLIC) + PHP_ME(xmlreader, getAttribute, arginfo_xmlreader_getAttribute, ZEND_ACC_PUBLIC) + PHP_ME(xmlreader, getAttributeNo, arginfo_xmlreader_getAttributeNo, ZEND_ACC_PUBLIC) + PHP_ME(xmlreader, getAttributeNs, arginfo_xmlreader_getAttributeNs, ZEND_ACC_PUBLIC) + PHP_ME(xmlreader, getParserProperty, arginfo_xmlreader_getParserProperty, ZEND_ACC_PUBLIC) + PHP_ME(xmlreader, isValid, arginfo_xmlreader_isValid, ZEND_ACC_PUBLIC) + PHP_ME(xmlreader, lookupNamespace, arginfo_xmlreader_lookupNamespace, ZEND_ACC_PUBLIC) + PHP_ME(xmlreader, moveToAttributeNo, arginfo_xmlreader_moveToAttributeNo, ZEND_ACC_PUBLIC) + PHP_ME(xmlreader, moveToAttribute, arginfo_xmlreader_moveToAttribute, ZEND_ACC_PUBLIC) + PHP_ME(xmlreader, moveToAttributeNs, arginfo_xmlreader_moveToAttributeNs, ZEND_ACC_PUBLIC) + PHP_ME(xmlreader, moveToElement, arginfo_xmlreader_moveToElement, ZEND_ACC_PUBLIC) + PHP_ME(xmlreader, moveToFirstAttribute, arginfo_xmlreader_moveToFirstAttribute, ZEND_ACC_PUBLIC) + PHP_ME(xmlreader, moveToNextAttribute, arginfo_xmlreader_moveToNextAttribute, ZEND_ACC_PUBLIC) + PHP_ME(xmlreader, open, arginfo_xmlreader_open, ZEND_ACC_PUBLIC|ZEND_ACC_ALLOW_STATIC) + PHP_ME(xmlreader, read, arginfo_xmlreader_read, ZEND_ACC_PUBLIC) + PHP_ME(xmlreader, next, arginfo_xmlreader_next, ZEND_ACC_PUBLIC) +#if LIBXML_VERSION >= 20620 + PHP_ME(xmlreader, readInnerXml, arginfo_xmlreader_readInnerXml, ZEND_ACC_PUBLIC) + PHP_ME(xmlreader, readOuterXml, arginfo_xmlreader_readOuterXml, ZEND_ACC_PUBLIC) + PHP_ME(xmlreader, readString, arginfo_xmlreader_readString, ZEND_ACC_PUBLIC) + PHP_ME(xmlreader, setSchema, arginfo_xmlreader_setSchema, ZEND_ACC_PUBLIC) +#endif +/* Not Yet Implemented though defined in libxml as of 2.6.9dev + PHP_ME(xmlreader, resetState, NULL, ZEND_ACC_PUBLIC) +*/ + PHP_ME(xmlreader, setParserProperty, arginfo_xmlreader_setParserProperty, ZEND_ACC_PUBLIC) + PHP_ME(xmlreader, setRelaxNGSchema, arginfo_xmlreader_setRelaxNGSchema, ZEND_ACC_PUBLIC) + PHP_ME(xmlreader, setRelaxNGSchemaSource, arginfo_xmlreader_setRelaxNGSchemaSource, ZEND_ACC_PUBLIC) + PHP_ME(xmlreader, XML, arginfo_xmlreader_XML, ZEND_ACC_PUBLIC|ZEND_ACC_ALLOW_STATIC) + PHP_ME(xmlreader, expand, arginfo_xmlreader_expand, ZEND_ACC_PUBLIC) + PHP_FE_END +}; + +/* {{{ PHP_MINIT_FUNCTION + */ +PHP_MINIT_FUNCTION(xmlreader) +{ + + zend_class_entry ce; + + memcpy(&xmlreader_object_handlers, zend_get_std_object_handlers(), sizeof(zend_object_handlers)); + xmlreader_object_handlers.read_property = xmlreader_read_property; + xmlreader_object_handlers.write_property = xmlreader_write_property; + xmlreader_object_handlers.get_property_ptr_ptr = xmlreader_get_property_ptr_ptr; + + INIT_CLASS_ENTRY(ce, "XMLReader", xmlreader_functions); + ce.create_object = xmlreader_objects_new; + xmlreader_class_entry = zend_register_internal_class(&ce TSRMLS_CC); + + zend_hash_init(&xmlreader_prop_handlers, 0, NULL, NULL, 1); + xmlreader_register_prop_handler(&xmlreader_prop_handlers, "attributeCount", xmlTextReaderAttributeCount, NULL, IS_LONG TSRMLS_CC); + xmlreader_register_prop_handler(&xmlreader_prop_handlers, "baseURI", NULL, xmlTextReaderConstBaseUri, IS_STRING TSRMLS_CC); + xmlreader_register_prop_handler(&xmlreader_prop_handlers, "depth", xmlTextReaderDepth, NULL, IS_LONG TSRMLS_CC); + xmlreader_register_prop_handler(&xmlreader_prop_handlers, "hasAttributes", xmlTextReaderHasAttributes, NULL, IS_BOOL TSRMLS_CC); + xmlreader_register_prop_handler(&xmlreader_prop_handlers, "hasValue", xmlTextReaderHasValue, NULL, IS_BOOL TSRMLS_CC); + xmlreader_register_prop_handler(&xmlreader_prop_handlers, "isDefault", xmlTextReaderIsDefault, NULL, IS_BOOL TSRMLS_CC); + xmlreader_register_prop_handler(&xmlreader_prop_handlers, "isEmptyElement", xmlTextReaderIsEmptyElement, NULL, IS_BOOL TSRMLS_CC); + xmlreader_register_prop_handler(&xmlreader_prop_handlers, "localName", NULL, xmlTextReaderConstLocalName, IS_STRING TSRMLS_CC); + xmlreader_register_prop_handler(&xmlreader_prop_handlers, "name", NULL, xmlTextReaderConstName, IS_STRING TSRMLS_CC); + xmlreader_register_prop_handler(&xmlreader_prop_handlers, "namespaceURI", NULL, xmlTextReaderConstNamespaceUri, IS_STRING TSRMLS_CC); + xmlreader_register_prop_handler(&xmlreader_prop_handlers, "nodeType", xmlTextReaderNodeType, NULL, IS_LONG TSRMLS_CC); + xmlreader_register_prop_handler(&xmlreader_prop_handlers, "prefix", NULL, xmlTextReaderConstPrefix, IS_STRING TSRMLS_CC); + xmlreader_register_prop_handler(&xmlreader_prop_handlers, "value", NULL, xmlTextReaderConstValue, IS_STRING TSRMLS_CC); + xmlreader_register_prop_handler(&xmlreader_prop_handlers, "xmlLang", NULL, xmlTextReaderConstXmlLang, IS_STRING TSRMLS_CC); + + /* Constants for NodeType - cannot define common types to share with dom as there are differences in these types */ + + REGISTER_XMLREADER_CLASS_CONST_LONG("NONE", XML_READER_TYPE_NONE); + REGISTER_XMLREADER_CLASS_CONST_LONG("ELEMENT", XML_READER_TYPE_ELEMENT); + REGISTER_XMLREADER_CLASS_CONST_LONG("ATTRIBUTE", XML_READER_TYPE_ATTRIBUTE); + REGISTER_XMLREADER_CLASS_CONST_LONG("TEXT", XML_READER_TYPE_TEXT); + REGISTER_XMLREADER_CLASS_CONST_LONG("CDATA", XML_READER_TYPE_CDATA); + REGISTER_XMLREADER_CLASS_CONST_LONG("ENTITY_REF", XML_READER_TYPE_ENTITY_REFERENCE); + REGISTER_XMLREADER_CLASS_CONST_LONG("ENTITY", XML_READER_TYPE_ENTITY); + REGISTER_XMLREADER_CLASS_CONST_LONG("PI", XML_READER_TYPE_PROCESSING_INSTRUCTION); + REGISTER_XMLREADER_CLASS_CONST_LONG("COMMENT", XML_READER_TYPE_COMMENT); + REGISTER_XMLREADER_CLASS_CONST_LONG("DOC", XML_READER_TYPE_DOCUMENT); + REGISTER_XMLREADER_CLASS_CONST_LONG("DOC_TYPE", XML_READER_TYPE_DOCUMENT_TYPE); + REGISTER_XMLREADER_CLASS_CONST_LONG("DOC_FRAGMENT", XML_READER_TYPE_DOCUMENT_FRAGMENT); + REGISTER_XMLREADER_CLASS_CONST_LONG("NOTATION", XML_READER_TYPE_NOTATION); + REGISTER_XMLREADER_CLASS_CONST_LONG("WHITESPACE", XML_READER_TYPE_WHITESPACE); + REGISTER_XMLREADER_CLASS_CONST_LONG("SIGNIFICANT_WHITESPACE", XML_READER_TYPE_SIGNIFICANT_WHITESPACE); + REGISTER_XMLREADER_CLASS_CONST_LONG("END_ELEMENT", XML_READER_TYPE_END_ELEMENT); + REGISTER_XMLREADER_CLASS_CONST_LONG("END_ENTITY", XML_READER_TYPE_END_ENTITY); + REGISTER_XMLREADER_CLASS_CONST_LONG("XML_DECLARATION", XML_READER_TYPE_XML_DECLARATION); + + /* Constants for Parser options */ + REGISTER_XMLREADER_CLASS_CONST_LONG("LOADDTD", XML_PARSER_LOADDTD); + REGISTER_XMLREADER_CLASS_CONST_LONG("DEFAULTATTRS", XML_PARSER_DEFAULTATTRS); + REGISTER_XMLREADER_CLASS_CONST_LONG("VALIDATE", XML_PARSER_VALIDATE); + REGISTER_XMLREADER_CLASS_CONST_LONG("SUBST_ENTITIES", XML_PARSER_SUBST_ENTITIES); + + /* Constants for Errors when loading - not yet used until we implement custom error handling + REGISTER_XMLREADER_CLASS_CONST_LONG("VALIDITY_WARNING", XML_PARSER_SEVERITY_VALIDITY_WARNING, CONST_CS | CONST_PERSISTENT); + REGISTER_XMLREADER_CLASS_CONST_LONG("VALIDITY_ERROR", XML_PARSER_SEVERITY_VALIDITY_ERROR, CONST_CS | CONST_PERSISTENT); + REGISTER_XMLREADER_CLASS_CONST_LONG("WARNING", XML_PARSER_SEVERITY_WARNING, CONST_CS | CONST_PERSISTENT); + REGISTER_XMLREADER_CLASS_CONST_LONG("ERROR", XML_PARSER_SEVERITY_ERROR, CONST_CS | CONST_PERSISTENT); + */ + + return SUCCESS; +} +/* }}} */ + +/* {{{ PHP_MSHUTDOWN_FUNCTION + */ +PHP_MSHUTDOWN_FUNCTION(xmlreader) +{ + zend_hash_destroy(&xmlreader_prop_handlers); + return SUCCESS; +} +/* }}} */ + +/* {{{ PHP_MINFO_FUNCTION + */ +PHP_MINFO_FUNCTION(xmlreader) +{ + php_info_print_table_start(); + { + php_info_print_table_row(2, "XMLReader", "enabled"); + } + php_info_print_table_end(); +} +/* }}} */ + +/* + * Local variables: + * tab-width: 4 + * c-basic-offset: 4 + * End: + * vim600: noet sw=4 ts=4 fdm=marker + * vim<600: noet sw=4 ts=4 + */ diff --git a/ext/xmlreader/php_xmlreader.h b/ext/xmlreader/php_xmlreader.h new file mode 100644 index 0000000..a163135 --- /dev/null +++ b/ext/xmlreader/php_xmlreader.h @@ -0,0 +1,66 @@ +/* + +----------------------------------------------------------------------+ + | PHP Version 5 | + +----------------------------------------------------------------------+ + | Copyright (c) 1997-2013 The PHP Group | + +----------------------------------------------------------------------+ + | This source file is subject to version 3.01 of the PHP license, | + | that is bundled with this package in the file LICENSE, and is | + | available through the world-wide-web at the following url: | + | http://www.php.net/license/3_01.txt | + | If you did not receive a copy of the PHP license and are unable to | + | obtain it through the world-wide-web, please send a note to | + | license@php.net so we can mail you a copy immediately. | + +----------------------------------------------------------------------+ + | Author: Rob Richards <rrichards@php.net> | + +----------------------------------------------------------------------+ +*/ + +/* $Id$ */ + +#ifndef PHP_XMLREADER_H +#define PHP_XMLREADER_H + +extern zend_module_entry xmlreader_module_entry; +#define phpext_xmlreader_ptr &xmlreader_module_entry + +#ifdef ZTS +#include "TSRM.h" +#endif + +#include "ext/libxml/php_libxml.h" +#include <libxml/xmlreader.h> + +typedef struct _xmlreader_object { + zend_object std; + xmlTextReaderPtr ptr; + /* strings must be set in input buffer as copy is required */ + xmlParserInputBufferPtr input; + void *schema; + HashTable *prop_handler; + zend_object_handle handle; +} xmlreader_object; + +PHP_MINIT_FUNCTION(xmlreader); +PHP_MSHUTDOWN_FUNCTION(xmlreader); +PHP_MINFO_FUNCTION(xmlreader); + +#define REGISTER_XMLREADER_CLASS_CONST_LONG(const_name, value) \ + zend_declare_class_constant_long(xmlreader_class_entry, const_name, sizeof(const_name)-1, (long)value TSRMLS_CC); + +#ifdef ZTS +#define XMLREADER_G(v) TSRMG(xmlreader_globals_id, zend_xmlreader_globals *, v) +#else +#define XMLREADER_G(v) (xmlreader_globals.v) +#endif + +#endif /* PHP_XMLREADER_H */ + +/* + * Local variables: + * tab-width: 4 + * c-basic-offset: 4 + * End: + * vim600: noet sw=4 ts=4 fdm=marker + * vim<600: noet sw=4 ts=4 + */ diff --git a/ext/xmlreader/tests/001.phpt b/ext/xmlreader/tests/001.phpt new file mode 100644 index 0000000..ce9ade9 --- /dev/null +++ b/ext/xmlreader/tests/001.phpt @@ -0,0 +1,29 @@ +--TEST-- +XMLReader: libxml2 XML Reader, string data +--SKIPIF-- +<?php if (!extension_loaded("xmlreader")) print "skip"; ?> +--FILE-- +<?php +/* $Id$ */ + +$xmlstring = '<?xml version="1.0" encoding="UTF-8"?> +<books></books>'; + +$reader = new XMLReader(); +$reader->XML($xmlstring); + +// Only go through +while ($reader->read()) { + echo $reader->name."\n"; +} +$xmlstring = ''; +$reader = new XMLReader(); +$reader->XML($xmlstring); +?> +===DONE=== +--EXPECTF-- +books +books + +Warning: XMLReader::XML(): Empty string supplied as input in %s on line %d +===DONE=== diff --git a/ext/xmlreader/tests/002.phpt b/ext/xmlreader/tests/002.phpt new file mode 100644 index 0000000..7abd3e2 --- /dev/null +++ b/ext/xmlreader/tests/002.phpt @@ -0,0 +1,41 @@ +--TEST-- +XMLReader: libxml2 XML Reader, file data +--SKIPIF-- +<?php if (!extension_loaded("xmlreader")) print "skip"; ?> +--FILE-- +<?php +/* $Id$ */ +$filename = dirname(__FILE__) . '/_002.xml'; +$xmlstring = '<?xml version="1.0" encoding="UTF-8"?> +<books></books>'; +file_put_contents($filename, $xmlstring); + +$reader = new XMLReader(); +if ($reader->open('')) exit(); + +$reader = new XMLReader(); +if (!$reader->open($filename)) { + $reader->close(); + exit(); +} + +// Only go through +while ($reader->read()) { + echo $reader->name."\n"; +} +$reader->close(); +unlink($filename); +touch($filename); +$reader = new XMLReader(); +$reader->open($filename); +$reader->close(); +unlink($filename); + +?> +===DONE=== +--EXPECTF-- + +Warning: XMLReader::open(): Empty string supplied as input in %s on line %d +books +books +===DONE=== diff --git a/ext/xmlreader/tests/003.phpt b/ext/xmlreader/tests/003.phpt new file mode 100644 index 0000000..48aa4be --- /dev/null +++ b/ext/xmlreader/tests/003.phpt @@ -0,0 +1,84 @@ +--TEST-- +XMLReader: libxml2 XML Reader, attributes test +--SKIPIF-- +<?php if (!extension_loaded("xmlreader")) print "skip"; ?> +--FILE-- +<?php +/* $Id$ */ +$filename = dirname(__FILE__) . '/_002.xml'; + +$xmlstring = '<?xml version="1.0" encoding="UTF-8"?> +<books><book num="1" idx="2">book1</book></books>'; +file_put_contents($filename, $xmlstring); + +$reader = new XMLReader(); +if (!$reader->open($filename)) { + exit(); +} + +// Only go through +while ($reader->read()) { + if ($reader->nodeType != XMLREADER::END_ELEMENT) { + if ($reader->nodeType == XMLREADER::ELEMENT && $reader->hasAttributes) { + $attr = $reader->moveToFirstAttribute(); + echo $reader->name . ": "; + echo $reader->value . "\n"; + + if ($reader->getAttribute($reader->name) == $reader->value) { + echo "1st attr (num) failed\n"; + } + + + $attr = $reader->moveToNextAttribute(); + echo $reader->name . ": "; + echo $reader->value . "\n"; + + if ($reader->getAttribute($reader->name) == $reader->value) { + echo "2nd attr (idx) failed\n"; + } + + // Named attribute + $attr = $reader->moveToAttribute('num'); + echo $reader->name . ": "; + echo $reader->value . "\n"; + + if ($reader->getAttribute('num') == $reader->value) { + echo "attr num failed\n"; + } + + $attr = $reader->moveToAttribute('idx'); + echo $reader->name . ": "; + echo $reader->value . "\n"; + + if ($reader->getAttribute('idx') == $reader->value) { + echo "attr idx failed\n"; + } + + // Numeric positions of attributes + $attr = $reader->moveToAttributeNo(0); + echo $reader->name . ": "; + echo $reader->value . "\n"; + + if ($reader->getAttributeNo(0) == $reader->value) { + echo "attr 0 failed\n"; + } + + $attr = $reader->moveToAttributeNo(1); + echo $reader->name . ": "; + echo $reader->value . "\n"; + + } + } +} +$reader->close(); +unlink($filename); +?> +===DONE=== +--EXPECT-- +num: 1 +idx: 2 +num: 1 +idx: 2 +num: 1 +idx: 2 +===DONE=== diff --git a/ext/xmlreader/tests/004.phpt b/ext/xmlreader/tests/004.phpt new file mode 100644 index 0000000..d4f044e --- /dev/null +++ b/ext/xmlreader/tests/004.phpt @@ -0,0 +1,44 @@ +--TEST-- +XMLReader: libxml2 XML Reader, attributes test +--SKIPIF-- +<?php if (!extension_loaded("xmlreader")) print "skip"; ?> +--FILE-- +<?php +/* $Id$ */ +$filename = dirname(__FILE__) . '/_002.xml'; + +$xmlstring = '<?xml version="1.0" encoding="UTF-8"?> +<books><book num="1" idx="2">book1</book></books>'; +file_put_contents($filename, $xmlstring); + +$reader = new XMLReader(); +if (!$reader->open($filename)) { + exit(); +} + +while ($reader->read()) { + if ($reader->nodeType != XMLREADER::END_ELEMENT) { + echo $reader->name."\n"; + if ($reader->nodeType == XMLREADER::ELEMENT && $reader->hasAttributes) { + $attr = $reader->moveToFirstAttribute(); + while ($attr) { + echo " Attribute Name: ".$reader->name."\n"; + echo " Attribute Value: ".$reader->value."\n"; + $attr = $reader->moveToNextAttribute(); + } + } + } +} +$reader->close(); +unlink($filename); +?> +===DONE=== +--EXPECT-- +books +book + Attribute Name: num + Attribute Value: 1 + Attribute Name: idx + Attribute Value: 2 +#text +===DONE=== diff --git a/ext/xmlreader/tests/005.phpt b/ext/xmlreader/tests/005.phpt new file mode 100644 index 0000000..e6fd02c --- /dev/null +++ b/ext/xmlreader/tests/005.phpt @@ -0,0 +1,37 @@ +--TEST-- +XMLReader: libxml2 XML Reader, parser property set/get +--SKIPIF-- +<?php if (!extension_loaded("xmlreader")) print "skip"; ?> +--FILE-- +<?php +/* $Id$ */ + +$xmlstring = '<?xml version="1.0" encoding="UTF-8"?> +<books></books>'; + +$reader = new XMLReader(); + +$reader->XML($xmlstring); + + +$a = $reader->setParserProperty(XMLReader::LOADDTD, false); +$b = $reader->getParserProperty(XMLReader::LOADDTD); + +if (!$a && !$b) { + echo "ok\n"; +} + +$a = $reader->setParserProperty(XMLReader::SUBST_ENTITIES, true); +$b = $reader->getParserProperty(XMLReader::SUBST_ENTITIES); + +if ($a && $b) { + echo "ok\n"; +} +// Only go through +while ($reader->read()); +$reader->close(); +?> +===DONE=== +--EXPECT-- +ok +===DONE=== diff --git a/ext/xmlreader/tests/006.phpt b/ext/xmlreader/tests/006.phpt new file mode 100644 index 0000000..ce9bb45 --- /dev/null +++ b/ext/xmlreader/tests/006.phpt @@ -0,0 +1,36 @@ +--TEST-- +XMLReader: libxml2 XML Reader, moveToElement +--SKIPIF-- +<?php if (!extension_loaded("xmlreader")) print "skip"; ?> +--FILE-- +<?php +/* $Id$ */ + +$xmlstring = '<?xml version="1.0" encoding="UTF-8"?> +<books><book num="1"></book><test /></books>'; + +$reader = new XMLReader(); + +$reader->XML($xmlstring); + +// 2 read to get on the 2nd node +$reader->read(); +$reader->read(); + +if ($reader->nodeType != XMLREADER::END_ELEMENT) { + if ($reader->nodeType == XMLREADER::ELEMENT && $reader->hasAttributes) { + $attr = $reader->moveToFirstAttribute(); + if ($reader->moveToElement()) { + if ($reader->name == 'book') { + echo "ok\n"; + } + } + } +} + +$reader->close(); +?> +===DONE=== +--EXPECT-- +ok +===DONE=== diff --git a/ext/xmlreader/tests/007.phpt b/ext/xmlreader/tests/007.phpt new file mode 100644 index 0000000..842f25e --- /dev/null +++ b/ext/xmlreader/tests/007.phpt @@ -0,0 +1,57 @@ +--TEST-- +XMLReader: libxml2 XML Reader, setRelaxNGSchema +--SKIPIF-- +<?php if (!extension_loaded("xmlreader")) print "skip"; ?> +--FILE-- +<?php +/* $Id$ */ + +$xmlstring = '<TEI.2>hello</TEI.2>'; +$relaxngfile = dirname(__FILE__) . '/relaxNG.rng'; +$file = dirname(__FILE__) . '/__007.xml'; +file_put_contents($file, $xmlstring); + +$reader = new XMLReader(); +$reader->open($file); + +if ($reader->setRelaxNGSchema($relaxngfile)) { + while ($reader->read()); +} +if ($reader->isValid()) { + print "file relaxNG: ok\n"; +} else { + print "file relaxNG: failed\n"; +} +$reader->close(); +unlink($file); + + +$reader = new XMLReader(); +$reader->XML($xmlstring); + +if ($reader->setRelaxNGSchema($relaxngfile)) { + while ($reader->read()); +} +if ($reader->isValid()) { + print "string relaxNG: ok\n"; +} else { + print "string relaxNG: failed\n"; +} + +$reader->close(); + +$reader = new XMLReader(); +$reader->XML($xmlstring); + +if ($reader->setRelaxNGSchema('')) { + echo 'failed'; +} +$reader->close(); +?> +===DONE=== +--EXPECTF-- +file relaxNG: ok +string relaxNG: ok + +Warning: XMLReader::setRelaxNGSchema(): Schema data source is required in %s on line %d +===DONE=== diff --git a/ext/xmlreader/tests/008.phpt b/ext/xmlreader/tests/008.phpt new file mode 100644 index 0000000..e3af00e --- /dev/null +++ b/ext/xmlreader/tests/008.phpt @@ -0,0 +1,71 @@ +--TEST-- +XMLReader: libxml2 XML Reader, DTD +--SKIPIF-- +<?php if (!extension_loaded("xmlreader")) print "skip"; ?> +--FILE-- +<?php +/* $Id$ */ + +$xmlstring = '<?xml version="1.0" encoding="UTF-8" standalone="no"?> +<!DOCTYPE LIST SYSTEM "dtdexample.dtd"> +<LIST> +<MOVIE ID="x200338360"> +<TITLE>Move Title 1</TITLE> +<ORGTITLE/><LOC>Location 1</LOC> +<INFO/> +</MOVIE> +<MOVIE ID="m200338361"> +<TITLE>Move Title 2</TITLE> +<ORGTITLE/> +<LOC>Location 2</LOC> +<INFO/> +</MOVIE> +</LIST>'; + +$dtdfile = rawurlencode(dirname(__FILE__)) . '/dtdexample.dtd'; +$file = dirname(__FILE__) . '/__008.xml'; +file_put_contents($file, $xmlstring); + + +$reader = new XMLReader(); +$reader->open($file); +$reader->setParserProperty(XMLREADER::LOADDTD, TRUE); +$reader->setParserProperty(XMLREADER::VALIDATE, TRUE); +while($reader->read()); +if ($reader->isValid()) { + echo "file DTD: ok\n"; +} +$reader->close(); +unlink($file); + +$xmlstring = '<?xml version="1.0" encoding="UTF-8" standalone="no"?> +<!DOCTYPE LIST SYSTEM "file:///' . $dtdfile. '"> +<LIST> +<MOVIE ID="x200338360"> +<TITLE>Move Title 1</TITLE> +<ORGTITLE/><LOC>Location 1</LOC> +<INFO/> +</MOVIE> +<MOVIE ID="m200338361"> +<TITLE>Move Title 2</TITLE> +<ORGTITLE/> +<LOC>Location 2</LOC> +<INFO/> +</MOVIE> +</LIST>'; + +$reader = new XMLReader(); +$reader->XML($xmlstring); + +$reader->setParserProperty(XMLREADER::LOADDTD, TRUE); +$reader->setParserProperty(XMLREADER::VALIDATE, TRUE); +while($reader->read()); +if ($reader->isValid()) { + echo "string DTD: ok\n"; +} +?> +===DONE=== +--EXPECTF-- +file DTD: ok +string DTD: ok +===DONE=== diff --git a/ext/xmlreader/tests/009.phpt b/ext/xmlreader/tests/009.phpt new file mode 100644 index 0000000..613ef67 --- /dev/null +++ b/ext/xmlreader/tests/009.phpt @@ -0,0 +1,28 @@ +--TEST-- +XMLReader: libxml2 XML Reader, next +--SKIPIF-- +<?php if (!extension_loaded("xmlreader")) print "skip"; ?> +--FILE-- +<?php +/* $Id$ */ + +$xmlstring = '<?xml version="1.0" encoding="UTF-8"?> +<books><book num="1"><test /></book><book num="2" /></books>'; + +$reader = new XMLReader(); +$reader->XML($xmlstring); + +// Only go through +$reader->read(); +$reader->read(); + +$reader->next(); +echo $reader->name; +echo " "; +echo $reader->getAttribute('num'); +echo "\n"; +?> +===DONE=== +--EXPECTF-- +book 2 +===DONE=== diff --git a/ext/xmlreader/tests/010.phpt b/ext/xmlreader/tests/010.phpt new file mode 100644 index 0000000..a107c74 --- /dev/null +++ b/ext/xmlreader/tests/010.phpt @@ -0,0 +1,27 @@ +--TEST-- +XMLReader: libxml2 XML Reader, next +--SKIPIF-- +<?php if (!extension_loaded("xmlreader")) print "skip"; ?> +--FILE-- +<?php +/* $Id$ */ +$xmlstring = '<?xml version="1.0" encoding="UTF-8"?> +<prefix:books xmlns:prefix="uri" isbn="" prefix:isbn="12isbn">book1</prefix:books>'; + +$reader = new XMLReader(); +$reader->XML($xmlstring); + +// Only go through +$reader->read(); +$reader->read(); + +$reader->next(); +echo $reader->name; +echo " "; +echo $reader->getAttributeNs('isbn', 'uri'); +echo "\n"; +?> +===DONE=== +--EXPECTF-- +prefix:books 12isbn +===DONE=== diff --git a/ext/xmlreader/tests/011.phpt b/ext/xmlreader/tests/011.phpt new file mode 100644 index 0000000..8959923 --- /dev/null +++ b/ext/xmlreader/tests/011.phpt @@ -0,0 +1,34 @@ +--TEST-- +XMLReader: libxml2 XML Reader, string data +--SKIPIF-- +<?php if (!extension_loaded("xmlreader")) print "skip"; +$reader = new XMLReader(); +if (!method_exists($reader, 'readInnerXml')) print "skip"; +?> +--FILE-- +<?php +/* $Id$ */ + +$xmlstring = '<?xml version="1.0" encoding="UTF-8"?> +<books><book>test</book></books>'; + +$reader = new XMLReader(); +$reader->XML($xmlstring); +$reader->read(); +echo $reader->readInnerXml(); +echo "\n"; +$reader->close(); + + +$reader = new XMLReader(); +$reader->XML($xmlstring); +$reader->read(); +echo $reader->readOuterXml(); +echo "\n"; +$reader->close(); +?> +===DONE=== +--EXPECT-- +<book>test</book> +<books><book>test</book></books> +===DONE=== diff --git a/ext/xmlreader/tests/012.dtd b/ext/xmlreader/tests/012.dtd new file mode 100755 index 0000000..b65412a --- /dev/null +++ b/ext/xmlreader/tests/012.dtd @@ -0,0 +1,2 @@ +<!ELEMENT foo EMPTY> +<!ATTLIST foo bar CDATA '' baz CDATA ''> diff --git a/ext/xmlreader/tests/012.phpt b/ext/xmlreader/tests/012.phpt new file mode 100644 index 0000000..e0edeef --- /dev/null +++ b/ext/xmlreader/tests/012.phpt @@ -0,0 +1,75 @@ +--TEST-- +XMLReader: accessing empty and non existing attributes +--SKIPIF-- +<?php if (!extension_loaded("xmlreader")) print "skip"; ?> +--FILE-- +<?php +/* $Id$ */ + +$xmlstring =<<<EOF +<?xml version="1.0" encoding="UTF-8"?> +<foo bar=""/> +EOF; + +$reader = new XMLReader(); +$reader->XML($xmlstring); +$reader->read(); +var_dump($reader->getAttribute('bar')); +var_dump($reader->getAttribute('baz')); +$reader->close(); + +$xmlstring =<<<EOF +<?xml version="1.0" encoding="UTF-8"?> +<!DOCTYPE foo SYSTEM "012.dtd"> +<foo bar=""/> +EOF; + +$xmlstring = str_replace('012.dtd', dirname(__FILE__).'/012.dtd', $xmlstring); +if (DIRECTORY_SEPARATOR == '\\') { + $xmlstring = str_replace('\\',"/", $xmlstring); +} +$reader = new XMLReader(); +$reader->XML($xmlstring); +$reader->setParserProperty(XMLReader::DEFAULTATTRS, true); +while($reader->read() && $reader->nodeType != XMLReader::ELEMENT); +var_dump($reader->getAttribute('bar')); +var_dump($reader->getAttribute('baz')); +$reader->close(); + +echo "\nUsing URI:\n"; +$reader = new XMLReader(); +$file = dirname(__FILE__) . '/012.xml'; +if (DIRECTORY_SEPARATOR == '\\') { + $file = str_replace('\\',"/", $file); +} + +$reader->open($file); + +//$reader->setParserProperty(XMLReader::DEFAULTATTRS, true); +while($reader->read() && $reader->nodeType != XMLReader::ELEMENT); +var_dump($reader->getAttribute('bar')); +var_dump($reader->getAttribute('baz')); +$reader->close(); + +$reader = new XMLReader(); +$reader->open(dirname(__FILE__) . '/012.xml'); +$reader->setParserProperty(XMLReader::DEFAULTATTRS, true); +while($reader->read() && $reader->nodeType != XMLReader::ELEMENT); +var_dump($reader->getAttribute('bar')); +var_dump($reader->getAttribute('baz')); +$reader->close(); + +?> +===DONE=== +--EXPECT-- +string(0) "" +NULL +string(0) "" +string(0) "" + +Using URI: +string(0) "" +NULL +string(0) "" +string(0) "" +===DONE=== diff --git a/ext/xmlreader/tests/012.xml b/ext/xmlreader/tests/012.xml new file mode 100755 index 0000000..5012bd5 --- /dev/null +++ b/ext/xmlreader/tests/012.xml @@ -0,0 +1,3 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!DOCTYPE foo SYSTEM "012.dtd"> +<foo bar=""/> diff --git a/ext/xmlreader/tests/013.phpt b/ext/xmlreader/tests/013.phpt new file mode 100644 index 0000000..f9dcdee --- /dev/null +++ b/ext/xmlreader/tests/013.phpt @@ -0,0 +1,52 @@ +--TEST-- +XMLReader: Schema validation +--SKIPIF-- +<?php if (!extension_loaded('xmlreader')) die('skip');?> +<?php if (!method_exists('XMLReader','setSchema')) die('skip XMLReader::setSchema() not supported');?> +--FILE-- +<?php +/* $Id$ */ + +$xml =<<<EOF +<?xml version="1.0" encoding="UTF-8" ?> +<items> + <item>123</item> + <item>456</item> +</items> +EOF; + +$reader = new XMLReader(); +$reader->XML($xml); +$reader->setSchema(dirname(__FILE__) . '/013.xsd'); +while($reader->read()) { + if ($reader->nodeType == XMLReader::ELEMENT && $reader->name == 'item') { + $reader->read(); + var_dump($reader->value); + } +} +$reader->close(); + +?> +===FAIL=== +<?php + +$xml =<<<EOF +<?xml version="1.0" encoding="UTF-8" ?> +<foo/> +EOF; + +$reader = new XMLReader(); +$reader->XML($xml); +$reader->setSchema(dirname(__FILE__) . '/013.xsd'); +while($reader->read() && $reader->nodeType != XMLReader::ELEMENT); +$reader->close(); + +?> +===DONE=== +--EXPECTF-- +string(3) "123" +string(3) "456" +===FAIL=== + +Warning: XMLReader::read(): Element 'foo': %s +===DONE=== diff --git a/ext/xmlreader/tests/013.xsd b/ext/xmlreader/tests/013.xsd new file mode 100755 index 0000000..50b000b --- /dev/null +++ b/ext/xmlreader/tests/013.xsd @@ -0,0 +1,10 @@ +<?xml version="1.0" encoding="UTF-8" ?> +<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"> + <xsd:element name="items"> + <xsd:complexType> + <xsd:sequence> + <xsd:element name="item" type="xsd:integer" minOccurs="0" maxOccurs="unbounded" /> + </xsd:sequence> + </xsd:complexType> + </xsd:element> +</xsd:schema> diff --git a/ext/xmlreader/tests/bug36743.phpt b/ext/xmlreader/tests/bug36743.phpt new file mode 100644 index 0000000..374941b --- /dev/null +++ b/ext/xmlreader/tests/bug36743.phpt @@ -0,0 +1,27 @@ +--TEST-- +Bug #36743 (In a class extending XMLReader array properties are not writable) +--SKIPIF-- +<?php if (!extension_loaded("xmlreader")) print "skip"; ?> +--FILE-- +<?php + +class Test extends XMLReader +{ + private $testArr = array(); + public function __construct() + { + $this->testArr[] = 1; + var_dump($this->testArr); + } +} + +$t = new test; + +echo "Done\n"; +?> +--EXPECT-- +array(1) { + [0]=> + int(1) +} +Done diff --git a/ext/xmlreader/tests/bug42139.phpt b/ext/xmlreader/tests/bug42139.phpt new file mode 100644 index 0000000..19602f0 --- /dev/null +++ b/ext/xmlreader/tests/bug42139.phpt @@ -0,0 +1,31 @@ +--TEST-- +Bug #42139 (XMLReader option constants are broken using XML()) +--SKIPIF-- +<?php if (!extension_loaded("xmlreader")) print "skip"; +if (LIBXML_VERSION < 20628) die("skip: libxml2 2.6.28+ required"); +?> +--FILE-- +<?php + +$xml = <<<XML +<?xml version="1.0" encoding="utf-8"?> +<!DOCTYPE root [ +<!ELEMENT root ANY> +<!ENTITY x "y"> +]> +<root>&x;</root> +XML; + +$reader = new XMLReader; +$reader->XML( $xml, NULL, LIBXML_NOENT); +while ( $reader->read() ) { + echo "{$reader->nodeType}, {$reader->name}, {$reader->value}\n"; +} +$reader->close(); + +?> +--EXPECT-- +10, root, +1, root, +3, #text, y +15, root, diff --git a/ext/xmlreader/tests/dtdexample.dtd b/ext/xmlreader/tests/dtdexample.dtd new file mode 100644 index 0000000..ce53f0b --- /dev/null +++ b/ext/xmlreader/tests/dtdexample.dtd @@ -0,0 +1,8 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!ELEMENT LIST (MOVIE+)> +<!ELEMENT MOVIE (TITLE, ORGTITLE, LOC, INFO)> +<!ATTLIST MOVIE ID ID #REQUIRED> +<!ELEMENT TITLE (#PCDATA)> +<!ELEMENT ORGTITLE (#PCDATA)> +<!ELEMENT LOC (#PCDATA)> +<!ELEMENT INFO (#PCDATA)> diff --git a/ext/xmlreader/tests/expand.phpt b/ext/xmlreader/tests/expand.phpt new file mode 100644 index 0000000..c77e6c3 --- /dev/null +++ b/ext/xmlreader/tests/expand.phpt @@ -0,0 +1,37 @@ +--TEST-- +XMLReader: Expand into existing DOM documet +--SKIPIF-- +<?php if (!extension_loaded("xmlreader")) print "skip"; +if (!extension_loaded("dom")) print "skip DOM extension required"; +$reader = new XMLReader(); +if (!method_exists($reader, 'expand')) print "skip"; +?> +--FILE-- +<?php + +$basexml = '<?xml version="1.0" encoding="UTF-8"?> +<books><book>base book</book></books>'; + +$xmlstring = '<?xml version="1.0" encoding="UTF-8"?> +<books><book>new book</book></books>'; + +$dom = new DOMDocument(); +$dom->loadXML($basexml); + +$reader = new XMLReader(); +$reader->XML($xmlstring); +while ($reader->read()) { + if ($reader->localName == "book") { + $node = $reader->expand($dom); + if ($node->ownerDocument) { + echo $node->ownerDocument->documentElement->firstChild->textContent . "\n"; + } + break; + } +} +$reader->close(); +?> +===DONE=== +--EXPECT-- +base book +===DONE===
\ No newline at end of file diff --git a/ext/xmlreader/tests/relaxNG.rng b/ext/xmlreader/tests/relaxNG.rng new file mode 100644 index 0000000..f4357e0 --- /dev/null +++ b/ext/xmlreader/tests/relaxNG.rng @@ -0,0 +1,11 @@ +<?xml version="1.0" encoding="iso-8859-1"?> +<grammar xmlns="http://relaxng.org/ns/structure/1.0" + datatypeLibrary="http://www.w3.org/2001/XMLSchema-datatypes"> + +<include href="relaxNG2.rng"> +<define name="TEI.prose"><ref name="INCLUDE"/></define> +</include> +</grammar> + + + diff --git a/ext/xmlreader/tests/relaxNG2.rng b/ext/xmlreader/tests/relaxNG2.rng new file mode 100644 index 0000000..4adae7b --- /dev/null +++ b/ext/xmlreader/tests/relaxNG2.rng @@ -0,0 +1,23 @@ +<?xml version="1.0" encoding="utf-8"?> +<grammar xmlns="http://relaxng.org/ns/structure/1.0" xmlns:t="http://www.thaiopensource.com/ns/annotations" xmlns:a="http://relaxng.org/ns/compatibility/annotations/1.0" datatypeLibrary="http://www.w3.org/2001/XMLSchema-datatypes"> + + <start> + <ref name="TEI.2"/> + </start> + <define name="IGNORE"> + <notAllowed/> + </define> + <define name="INCLUDE"> + <empty/> + </define> + + + <include href="relaxNG3.rng"/> + + <define name="TEI.2"> + <element name="TEI.2"> + <text/> + </element> + </define> + +</grammar>
\ No newline at end of file diff --git a/ext/xmlreader/tests/relaxNG3.rng b/ext/xmlreader/tests/relaxNG3.rng new file mode 100644 index 0000000..73e1eb6 --- /dev/null +++ b/ext/xmlreader/tests/relaxNG3.rng @@ -0,0 +1,8 @@ +<?xml version="1.0" encoding="utf-8"?> +<grammar xmlns="http://relaxng.org/ns/structure/1.0" xmlns:t="http://www.thaiopensource.com/ns/annotations" xmlns:a="http://relaxng.org/ns/compatibility/annotations/1.0" datatypeLibrary="http://www.w3.org/2001/XMLSchema-datatypes"> + + <define name="TEI.prose" combine="interleave"> + <ref name="IGNORE"/> + </define> + +</grammar>
\ No newline at end of file diff --git a/ext/xmlreader/xmlreader.dsp b/ext/xmlreader/xmlreader.dsp new file mode 100644 index 0000000..7b21518 --- /dev/null +++ b/ext/xmlreader/xmlreader.dsp @@ -0,0 +1,114 @@ +# Microsoft Developer Studio Project File - Name="xmlreader" - Package Owner=<4>
+# Microsoft Developer Studio Generated Build File, Format Version 6.00
+# ** DO NOT EDIT **
+
+# TARGTYPE "Win32 (x86) Dynamic-Link Library" 0x0102
+
+CFG=xmlreader - Win32 Release_TS
+!MESSAGE This is not a valid makefile. To build this project using NMAKE,
+!MESSAGE use the Export Makefile command and run
+!MESSAGE
+!MESSAGE NMAKE /f "xmlreader.mak".
+!MESSAGE
+!MESSAGE You can specify a configuration when running NMAKE
+!MESSAGE by defining the macro CFG on the command line. For example:
+!MESSAGE
+!MESSAGE NMAKE /f "xmlreader.mak" CFG="xmlreader - Win32 Release_TS"
+!MESSAGE
+!MESSAGE Possible choices for configuration are:
+!MESSAGE
+!MESSAGE "xmlreader - Win32 Debug_TS" (based on "Win32 (x86) Dynamic-Link Library")
+!MESSAGE "xmlreader - Win32 Release_TS" (based on "Win32 (x86) Dynamic-Link Library")
+!MESSAGE
+
+# Begin Project
+# PROP AllowPerConfigDependencies 0
+# PROP Scc_ProjName ""
+# PROP Scc_LocalPath ""
+CPP=cl.exe
+MTL=midl.exe
+RSC=rc.exe
+
+!IF "$(CFG)" == "xmlreader - Win32 Debug_TS"
+
+# PROP BASE Use_MFC 0
+# PROP BASE Use_Debug_Libraries 1
+# PROP BASE Output_Dir "xmlreader___Win32_Debug_TS"
+# PROP BASE Intermediate_Dir "xmlreader___Win32_Debug_TS"
+# PROP BASE Target_Dir ""
+# PROP Use_MFC 0
+# PROP Use_Debug_Libraries 1
+# PROP Output_Dir "Debug_TS"
+# PROP Intermediate_Dir "Debug_TS"
+# PROP Ignore_Export_Lib 0
+# PROP Target_Dir ""
+# ADD BASE CPP /nologo /MTd /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "XMLREADER_EXPORTS" /YX /FD /GZ /c
+# ADD CPP /nologo /MDd /W3 /GX /ZI /Od /I "..\.." /I "..\..\Zend" /I "..\..\TSRM" /I "..\..\main" /D ZEND_DEBUG=1 /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "XMLREADER_EXPORTS" /D "COMPILE_DL_XMLREADER" /D ZTS=1 /D "ZEND_WIN32" /D "PHP_WIN32" /D "LIBXML_THREAD_ENABLED" /FR /YX /FD /GZ /c
+# ADD BASE MTL /nologo /D "_DEBUG" /mktyplib203 /win32
+# ADD MTL /nologo /D "NDEBUG" /mktyplib203 /win32
+# ADD BASE RSC /l 0x409 /d "_DEBUG"
+# ADD RSC /l 0x409 /d "NDEBUG"
+BSC32=bscmake.exe
+# ADD BASE BSC32 /nologo
+# ADD BSC32 /nologo
+LINK32=link.exe
+# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /dll /debug /machine:I386 /pdbtype:sept
+# ADD LINK32 php5ts_debug.lib resolv.lib kernel32.lib user32.lib gdi32.lib winspool.lib /nologo /dll /debug /machine:I386 /nodefaultlib:"msvcrt" /out:"..\..\Debug_TS/php_xmlreader.dll" /libpath:"..\..\Debug_TS" /libpath:"..\..\..\bindlib_w32\Release"
+
+!ELSEIF "$(CFG)" == "xmlreader - Win32 Release_TS"
+
+# PROP BASE Use_MFC 0
+# PROP BASE Use_Debug_Libraries 1
+# PROP BASE Output_Dir "xmlreader___Win32_Release_TS0"
+# PROP BASE Intermediate_Dir "xmlreader___Win32_Release_TS0"
+# PROP BASE Ignore_Export_Lib 0
+# PROP BASE Target_Dir ""
+# PROP Use_MFC 0
+# PROP Use_Debug_Libraries 1
+# PROP Output_Dir "Release_TS"
+# PROP Intermediate_Dir "Release_TS"
+# PROP Ignore_Export_Lib 0
+# PROP Target_Dir ""
+# ADD BASE CPP /nologo /MDd /W3 /GX /ZI /Od /I "..\.." /I "..\..\Zend" /I "..\..\TSRM" /I "..\..\main" /D ZEND_DEBUG=1 /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "XMLREADER_EXPORTS" /D "COMPILE_DL_XSL" /D ZTS=1 /D "ZEND_WIN32" /D "PHP_WIN32" /D "LIBXML_THREAD_ENABLED" /FR /YX /FD /GZ /c
+# ADD CPP /nologo /MD /W3 /GX /O2 /I "..\.." /I "..\..\Zend" /I "..\..\TSRM" /I "..\..\main" /D ZEND_DEBUG=0 /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "XMLREADER_EXPORTS" /D "COMPILE_DL_XSL" /D ZTS=1 /D "ZEND_WIN32" /D "PHP_WIN32" /D "LIBXML_THREAD_ENABLED" /YX /FD /GZ /c
+# SUBTRACT CPP /Fr
+# ADD BASE MTL /nologo /D "_DEBUG" /mktyplib203 /win32
+# ADD MTL /nologo /D "NDEBUG" /mktyplib203 /win32
+# ADD BASE RSC /l 0x409 /d "_DEBUG"
+# ADD RSC /l 0x409 /d "NDEBUG"
+BSC32=bscmake.exe
+# ADD BASE BSC32 /nologo
+# ADD BSC32 /nologo
+LINK32=link.exe
+# ADD BASE LINK32 php5ts_debug.lib resolv.lib kernel32.lib user32.lib gdi32.lib winspool.lib /nologo /dll /debug /machine:I386 /nodefaultlib:"msvcrt" /out:"..\..\Debug_TS/php_xmlreader.dll" /libpath:"..\..\Debug_TS" /libpath:"..\..\..\bindlib_w32\Release"
+# ADD LINK32 php5ts.lib resolv.lib kernel32.lib user32.lib gdi32.lib winspool.lib /nologo /dll /incremental:no /machine:I386 /out:"..\..\Release_TS/php_xmlreader.dll" /libpath:"..\..\Debug_TS" /libpath:"..\..\..\bindlib_w32\Release"
+# SUBTRACT LINK32 /debug
+
+!ENDIF
+
+# Begin Target
+
+# Name "xmlreader - Win32 Debug_TS"
+# Name "xmlreader - Win32 Release_TS"
+# Begin Group "Source Files"
+
+# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat"
+# Begin Source File
+
+SOURCE=.\php_xmlreader.c
+# End Source File
+# End Group
+# Begin Group "Header Files"
+
+# PROP Default_Filter "h;hpp;hxx;hm;inl"
+# Begin Source File
+
+SOURCE=.\php_xmlreader.h
+# End Source File
+# End Group
+# Begin Group "Resource Files"
+
+# PROP Default_Filter "ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe"
+# End Group
+# End Target
+# End Project
|