#include "ext/spl/spl_sxe.h"
#endif
+#define SXE_ELEMENT_BY_NAME 0
+
zend_class_entry *sxe_class_entry = NULL;
ZEND_API zend_class_entry *sxe_get_element_class_entry(TSRMLS_D)
}
}
-/* {{{ match_ns()
- */
-static inline int
-match_ns(php_sxe_object *sxe, xmlNodePtr node, xmlChar *name)
+static inline int match_ns(php_sxe_object *sxe, xmlNodePtr node, xmlChar *name) /* {{{ */
{
if (name == NULL && (node->ns == NULL || node->ns->prefix == NULL)) {
return 1;
}
/* }}} */
-/* {{{ sxe_get_element_node()
- */
-static xmlNodePtr sxe_get_element_by_offset(php_sxe_object *sxe, long offset, xmlNodePtr node) {
+static xmlNodePtr sxe_get_element_by_offset(php_sxe_object *sxe, long offset, xmlNodePtr node) /* {{{ */
+{
long nodendx = 0;
if (sxe->iter.type == SXE_ITER_NONE) {
}
/* }}} */
+#if SXE_ELEMENT_BY_NAME
+static xmlNodePtr sxe_find_element_by_name(php_sxe_object *sxe, xmlNodePtr node, char *name TSRMLS_DC) /* {{{ */
+{
+ while (node) {
+ SKIP_TEXT(node)
+ if (node->type == XML_ELEMENT_NODE && match_ns(sxe, node, sxe->iter.nsprefix)) {
+ if (!xmlStrcmp(node->name, name)) {
+ return node;
+ }
+ }
+next_iter:
+ node = node->next;
+ }
+ return NULL;
+} /* }}} */
+
+static xmlNodePtr sxe_get_element_by_name(php_sxe_object *sxe, xmlNodePtr node, char **name, int *type TSRMLS_DC) /* {{{ */
+{
+ int orgtype;
+ xmlNodePtr orgnode = node;
+ xmlNodePtr retnode = NULL;
+
+ if (sxe->iter.type != SXE_ITER_ATTRLIST)
+ {
+ orgtype = sxe->iter.type;
+ if (sxe->iter.type == SXE_ITER_NONE) {
+ sxe->iter.type = SXE_ITER_CHILD;
+ }
+ node = php_sxe_get_first_node(sxe, node TSRMLS_CC);
+ sxe->iter.type = orgtype;
+ }
+
+ if (sxe->iter.type == SXE_ITER_ELEMENT) {
+ orgnode = sxe_find_element_by_name(sxe, node, sxe->iter.name TSRMLS_CC);
+ node = orgnode->children;
+ }
+
+ while (node) {
+ SKIP_TEXT(node)
+ if (node->type == XML_ELEMENT_NODE && match_ns(sxe, node, sxe->iter.nsprefix)) {
+ if (!xmlStrcmp(node->name, *name)) {
+ if (1||retnode)
+ {
+ *type = SXE_ITER_ELEMENT;
+ return orgnode;
+ }
+ retnode = node;
+ }
+ }
+next_iter:
+ node = node->next;
+ }
+
+ if (retnode)
+ {
+ *type = SXE_ITER_NONE;
+ *name = NULL;
+ return retnode;
+ }
+
+ return NULL;
+}
+/* }}} */
+#endif /* SXE_ELEMENT_BY_NAME */
+
/* {{{ sxe_prop_dim_read()
*/
static zval * sxe_prop_dim_read(zval *object, zval *member, zend_bool elements, zend_bool attribs, zend_bool silent TSRMLS_DC)
xmlNodePtr node;
xmlAttrPtr attr;
zval tmp_zv;
- int nodendx = 0;
+ int nodendx = 0;
sxe = php_sxe_fetch_object(object TSRMLS_CC);
attribs = 0;
elements = 1;
}
+ name = NULL;
} else {
if (Z_TYPE_P(member) != IS_STRING) {
tmp_zv = *member;
member = &tmp_zv;
convert_to_string(member);
}
+ name = Z_STRVAL_P(member);
}
MAKE_STD_ZVAL(return_value);
ZVAL_NULL(return_value);
- name = Z_STRVAL_P(member);
-
GET_NODE(sxe, node);
- if (sxe->iter.type != SXE_ITER_CHILD && sxe->iter.type != SXE_ITER_ATTRLIST) {
+ if (sxe->iter.type == SXE_ITER_ATTRLIST) {
+ attribs = 1;
+ elements = 0;
+ } else if (sxe->iter.type != SXE_ITER_CHILD && sxe->iter.type != SXE_ITER_ATTRLIST) {
node = php_sxe_get_first_node(sxe, node TSRMLS_CC);
}
-
if (node) {
if (attribs) {
- if (Z_TYPE_P(member) == IS_LONG && sxe->iter.type != SXE_ITER_ATTRLIST) {
- attr = NULL;
- } else {
+ if (Z_TYPE_P(member) != IS_LONG || sxe->iter.type == SXE_ITER_ATTRLIST) {
attr = node->properties;
if (Z_TYPE_P(member) == IS_LONG) {
while (attr && nodendx <= Z_LVAL_P(member)) {
_node_as_zval(sxe, node, return_value, SXE_ITER_NONE, NULL, sxe->iter.nsprefix TSRMLS_CC);
}
} else {
+#if SXE_ELEMENT_BY_NAME
+ int newtype;
+
+ GET_NODE(sxe, node);
+ node = sxe_get_element_by_name(sxe, node, &name, &newtype TSRMLS_CC);
+ if (node) {
+ _node_as_zval(sxe, node, return_value, newtype, name, sxe->iter.nsprefix TSRMLS_CC);
+ }
+#else
_node_as_zval(sxe, node, return_value, SXE_ITER_ELEMENT, name, sxe->iter.nsprefix TSRMLS_CC);
+#endif
}
}
}
}
/* }}} */
+static void sxe_properties_add(HashTable *rv, char *name, int namelen, zval *value TSRMLS_DC)
+{
+ zval **data_ptr;
+ zval *newptr;
+ ulong h = zend_hash_func(name, namelen);
+
+ if (zend_hash_quick_find(rv, name, namelen, h, (void **) &data_ptr) == SUCCESS) {
+ if (Z_TYPE_PP(data_ptr) == IS_ARRAY) {
+ zend_hash_next_index_insert(Z_ARRVAL_PP(data_ptr), &value, sizeof(zval *), NULL);
+ } else {
+ MAKE_STD_ZVAL(newptr);
+ array_init(newptr);
+
+ zval_add_ref(data_ptr);
+ zend_hash_next_index_insert(Z_ARRVAL_P(newptr), data_ptr, sizeof(zval *), NULL);
+ zend_hash_next_index_insert(Z_ARRVAL_P(newptr), &value, sizeof(zval *), NULL);
+
+ zend_hash_quick_update(rv, name, namelen, h, &newptr, sizeof(zval *), NULL);
+ }
+ } else {
+ zend_hash_quick_update(rv, name, namelen, h, &value, sizeof(zval *), NULL);
+ }
+}
+
/* {{{ sxe_properties_get()
*/
-static HashTable *
-sxe_properties_get(zval *object TSRMLS_DC)
+static HashTable * sxe_properties_get(zval *object TSRMLS_DC)
{
- zval **data_ptr;
zval *value;
- zval *newptr;
+ zval *zattr;
HashTable *rv;
php_sxe_object *sxe;
char *name;
xmlNodePtr node;
- ulong h;
+ xmlAttrPtr attr;
int namelen;
sxe = php_sxe_fetch_object(object TSRMLS_CC);
}
GET_NODE(sxe, node);
- node = php_sxe_get_first_node(sxe, node TSRMLS_CC);
+ if (1||sxe->iter.type != SXE_ITER_CHILD) {
+ if (sxe->iter.type == SXE_ITER_ELEMENT) {
+ node = php_sxe_get_first_node(sxe, node TSRMLS_CC);
+ }
+ attr = node ? (xmlAttrPtr)node->properties : NULL;
+ zattr = NULL;
+ while (attr) {
+ if (match_ns(sxe, (xmlNodePtr)attr, sxe->iter.nsprefix)) {
+ MAKE_STD_ZVAL(value);
+ ZVAL_STRING(value, xmlNodeListGetString((xmlDocPtr) sxe->document->ptr, attr->children, 1), 1);
+ namelen = xmlStrlen(attr->name) + 1;
+ if (!zattr) {
+ MAKE_STD_ZVAL(zattr);
+ array_init(zattr);
+ sxe_properties_add(rv, "@attributes", sizeof("@attributes"), zattr TSRMLS_CC);
+ }
+ add_assoc_zval_ex(zattr, (char*)attr->name, namelen, value);
+ }
+ attr = attr->next;
+ }
+ }
- if (node) {
+ GET_NODE(sxe, node);
+ node = php_sxe_get_first_node(sxe, node TSRMLS_CC);
+ if (node && sxe->iter.type != SXE_ITER_ATTRLIST) {
if (node->type == XML_ATTRIBUTE_NODE) {
MAKE_STD_ZVAL(value);
ZVAL_U_STRING(ZEND_U_CONVERTER(UG(runtime_encoding_conv)), value, xmlNodeListGetString(node->doc, node->children, 1), 1);
_get_base_node_value(sxe, node, &value, sxe->iter.nsprefix TSRMLS_CC);
- h = zend_hash_func(name, namelen);
- if (zend_hash_quick_find(rv, name, namelen, h, (void **) &data_ptr) == SUCCESS) {
- if (Z_TYPE_PP(data_ptr) == IS_ARRAY) {
- zend_hash_next_index_insert(Z_ARRVAL_PP(data_ptr), &value, sizeof(zval *), NULL);
- } else {
- MAKE_STD_ZVAL(newptr);
- array_init(newptr);
-
- zval_add_ref(data_ptr);
- zend_hash_next_index_insert(Z_ARRVAL_P(newptr), data_ptr, sizeof(zval *), NULL);
- zend_hash_next_index_insert(Z_ARRVAL_P(newptr), &value, sizeof(zval *), NULL);
-
- zend_hash_quick_update(rv, name, namelen, h, &newptr, sizeof(zval *), NULL);
- }
- } else {
- zend_hash_quick_update(rv, name, namelen, h, &value, sizeof(zval *), NULL);
- }
-
+ sxe_properties_add(rv, name, namelen, value TSRMLS_CC);
next_iter:
node = node->next;
}
/* {{{ cast_object()
*/
-static int
-cast_object(zval *object, int type, char *contents TSRMLS_DC)
+static int cast_object(zval *object, int type, char *contents TSRMLS_DC)
{
if (contents) {
ZVAL_STRINGL(object, contents, strlen(contents), 1);
/* {{{ sxe_object_cast()
*/
-static int
-sxe_object_cast(zval *readobj, zval *writeobj, int type TSRMLS_DC)
+static int sxe_object_cast(zval *readobj, zval *writeobj, int type TSRMLS_DC)
{
php_sxe_object *sxe;
char *contents = NULL;
--- /dev/null
+--TEST--
+SimpleXML: var_dump()
+--SKIPIF--
+<?php if (!extension_loaded("simplexml")) print "skip"; ?>
+--FILE--
+<?php
+
+$sxe = simplexml_load_file(dirname(__FILE__).'/000.xml');
+
+function test($what)
+{
+ global $sxe;
+ echo "===$what\n";
+ eval("var_dump(isset(\$$what));");
+ eval("var_dump(\$$what);");
+}
+
+test('sxe');
+test('sxe->elem1');
+test('sxe->elem1[0]');
+test('sxe->elem1[0]->elem2');
+test('sxe->elem1[0]->elem2->bla');
+test('sxe->elem1[0]["attr1"]');
+test('sxe->elem1[0]->attr1');
+test('sxe->elem1[1]');
+test('sxe->elem1[2]');
+test('sxe->elem11');
+test('sxe->elem11->elem111');
+test('sxe->elem11->elem111->elem1111');
+test('sxe->elem22');
+test('sxe->elem22->elem222');
+test('sxe->elem22->attr22');
+test('sxe->elem22["attr22"]');
+
+?>
+===DONE===
+<?php exit(0); ?>
+--EXPECTF--
+===sxe
+bool(true)
+object(SimpleXMLElement)#%d (3) {
+ ["@attributes"]=>
+ array(1) {
+ ["id"]=>
+ string(3) "123"
+ }
+ ["elem1"]=>
+ array(2) {
+ [0]=>
+ string(36) "There is some text.Here is some more"
+ [1]=>
+ object(SimpleXMLElement)#%d (1) {
+ ["@attributes"]=>
+ array(2) {
+ ["attr1"]=>
+ string(2) "11"
+ ["attr2"]=>
+ string(2) "12"
+ }
+ }
+ }
+ ["elem11"]=>
+ object(SimpleXMLElement)#%d (1) {
+ ["elem111"]=>
+ object(SimpleXMLElement)#%d (1) {
+ ["elem1111"]=>
+ object(SimpleXMLElement)#%d (0) {
+ }
+ }
+ }
+}
+===sxe->elem1
+bool(true)
+object(SimpleXMLElement)#%d (3) {
+ ["@attributes"]=>
+ array(2) {
+ ["attr1"]=>
+ string(5) "first"
+ ["attr2"]=>
+ string(6) "second"
+ }
+ ["comment"]=>
+ object(SimpleXMLElement)#%d (0) {
+ }
+ ["elem2"]=>
+ object(SimpleXMLElement)#%d (2) {
+ ["@attributes"]=>
+ array(2) {
+ ["att25"]=>
+ string(2) "25"
+ ["att42"]=>
+ string(2) "42"
+ }
+ ["elem3"]=>
+ object(SimpleXMLElement)#%d (1) {
+ ["elem4"]=>
+ object(SimpleXMLElement)#%d (1) {
+ ["test"]=>
+ object(SimpleXMLElement)#%d (0) {
+ }
+ }
+ }
+ }
+}
+===sxe->elem1[0]
+bool(true)
+object(SimpleXMLElement)#%d (3) {
+ ["@attributes"]=>
+ array(2) {
+ ["attr1"]=>
+ string(5) "first"
+ ["attr2"]=>
+ string(6) "second"
+ }
+ ["comment"]=>
+ object(SimpleXMLElement)#%d (0) {
+ }
+ ["elem2"]=>
+ object(SimpleXMLElement)#%d (2) {
+ ["@attributes"]=>
+ array(2) {
+ ["att25"]=>
+ string(2) "25"
+ ["att42"]=>
+ string(2) "42"
+ }
+ ["elem3"]=>
+ object(SimpleXMLElement)#%d (1) {
+ ["elem4"]=>
+ object(SimpleXMLElement)#%d (1) {
+ ["test"]=>
+ object(SimpleXMLElement)#%d (0) {
+ }
+ }
+ }
+ }
+}
+===sxe->elem1[0]->elem2
+bool(true)
+object(SimpleXMLElement)#%d (2) {
+ ["@attributes"]=>
+ array(2) {
+ ["att25"]=>
+ string(2) "25"
+ ["att42"]=>
+ string(2) "42"
+ }
+ ["elem3"]=>
+ object(SimpleXMLElement)#%d (1) {
+ ["elem4"]=>
+ object(SimpleXMLElement)#%d (1) {
+ ["test"]=>
+ object(SimpleXMLElement)#%d (0) {
+ }
+ }
+ }
+}
+===sxe->elem1[0]->elem2->bla
+bool(false)
+object(SimpleXMLElement)#%d (0) {
+}
+===sxe->elem1[0]["attr1"]
+bool(true)
+object(SimpleXMLElement)#%d (1) {
+ [0]=>
+ string(5) "first"
+}
+===sxe->elem1[0]->attr1
+bool(false)
+object(SimpleXMLElement)#%d (0) {
+}
+===sxe->elem1[1]
+bool(true)
+object(SimpleXMLElement)#%d (1) {
+ ["@attributes"]=>
+ array(2) {
+ ["attr1"]=>
+ string(2) "11"
+ ["attr2"]=>
+ string(2) "12"
+ }
+}
+===sxe->elem1[2]
+bool(false)
+NULL
+===sxe->elem11
+bool(true)
+object(SimpleXMLElement)#%d (1) {
+ ["elem111"]=>
+ object(SimpleXMLElement)#%d (1) {
+ ["elem1111"]=>
+ object(SimpleXMLElement)#%d (0) {
+ }
+ }
+}
+===sxe->elem11->elem111
+bool(true)
+object(SimpleXMLElement)#%d (1) {
+ ["elem1111"]=>
+ object(SimpleXMLElement)#%d (0) {
+ }
+}
+===sxe->elem11->elem111->elem1111
+bool(true)
+object(SimpleXMLElement)#%d (0) {
+}
+===sxe->elem22
+bool(false)
+object(SimpleXMLElement)#%d (0) {
+}
+===sxe->elem22->elem222
+bool(false)
+NULL
+===sxe->elem22->attr22
+bool(false)
+NULL
+===sxe->elem22["attr22"]
+bool(false)
+NULL
+===DONE===
--- /dev/null
+<?xml version='1.0'?>
+<!DOCTYPE sxe SYSTEM "sxe.dtd" [
+<!ENTITY % incent SYSTEM "sxe.ent">
+%incent;
+]>
+<sxe id="123">
+ <elem1 attr1='first' attr2='second'>There is some text.<!-- comment --><elem2 att25='25' att42='42'>
+ <elem3>
+ <elem4>
+ <?test processing instruction ?>
+ </elem4>
+ </elem3>
+ </elem2>Here is some more</elem1>
+ <elem1 attr1='11' attr2='12'/>
+ <elem11><elem111><elem1111/></elem111></elem11>
+</sxe>
\ No newline at end of file
--FILE--
<?php
-$sxe = simplexml_load_file(dirname(__FILE__).'/sxe.xml');
-
-print_r($sxe);
-
-echo "---Done---\n";
+var_dump(simplexml_load_file(dirname(__FILE__).'/sxe.xml'));
?>
---EXPECT--
-SimpleXMLElement Object
-(
- [elem1] => SimpleXMLElement Object
- (
- [comment] => SimpleXMLElement Object
- (
- )
-
- [elem2] => SimpleXMLElement Object
- (
- [elem3] => SimpleXMLElement Object
- (
- [elem4] => SimpleXMLElement Object
- (
- [test] => SimpleXMLElement Object
- (
- )
-
- )
-
- )
-
- )
-
- )
-
-)
----Done---
+===DONE===
+--EXPECTF--
+object(SimpleXMLElement)#%d (2) {
+ ["@attributes"]=>
+ array(1) {
+ ["id"]=>
+ string(5) "elem1"
+ }
+ ["elem1"]=>
+ object(SimpleXMLElement)#%d (3) {
+ ["@attributes"]=>
+ array(1) {
+ ["attr1"]=>
+ string(5) "first"
+ }
+ ["comment"]=>
+ object(SimpleXMLElement)#%d (0) {
+ }
+ ["elem2"]=>
+ object(SimpleXMLElement)#%d (1) {
+ ["elem3"]=>
+ object(SimpleXMLElement)#%d (1) {
+ ["elem4"]=>
+ object(SimpleXMLElement)#%d (1) {
+ ["test"]=>
+ object(SimpleXMLElement)#%d (0) {
+ }
+ }
+ }
+ }
+ }
+}
+===DONE===
--TEST--
-SimpleXML and clone
+SimpleXML: clone
--SKIPIF--
<?php if (!extension_loaded("simplexml")) print "skip"; ?>
--FILE--
$copy = clone $sxe;
-print_r($copy);
-
-echo "---Done---\n";
+var_dump($copy);
?>
---EXPECT--
-SimpleXMLElement Object
-(
- [elem1] => SimpleXMLElement Object
- (
- [comment] => SimpleXMLElement Object
- (
- )
-
- [elem2] => SimpleXMLElement Object
- (
- [elem3] => SimpleXMLElement Object
- (
- [elem4] => SimpleXMLElement Object
- (
- [test] => SimpleXMLElement Object
- (
- )
-
- )
-
- )
-
- )
-
- )
-
-)
----Done---
+===DONE===
+--EXPECTF--
+object(SimpleXMLElement)#%d (2) {
+ ["@attributes"]=>
+ array(1) {
+ ["id"]=>
+ string(5) "elem1"
+ }
+ ["elem1"]=>
+ object(SimpleXMLElement)#%d (3) {
+ ["@attributes"]=>
+ array(1) {
+ ["attr1"]=>
+ string(5) "first"
+ }
+ ["comment"]=>
+ object(SimpleXMLElement)#%d (0) {
+ }
+ ["elem2"]=>
+ object(SimpleXMLElement)#%d (1) {
+ ["elem3"]=>
+ object(SimpleXMLElement)#%d (1) {
+ ["elem4"]=>
+ object(SimpleXMLElement)#%d (1) {
+ ["test"]=>
+ object(SimpleXMLElement)#%d (0) {
+ }
+ }
+ }
+ }
+ }
+}
+===DONE===
--TEST--
-SimpleXML and Entities
+SimpleXML: Entities
--SKIPIF--
<?php if (!extension_loaded("simplexml")) print "skip"; ?>
--FILE--
</sxe>
EOF;
-$sxe = simplexml_load_string($xml);
-
-print_r($sxe);
-
-echo "---Done---\n";
+var_dump(simplexml_load_string($xml));
?>
---EXPECT--
-SimpleXMLElement Object
-(
- [elem1] => SimpleXMLElement Object
- (
- [comment] => SimpleXMLElement Object
- (
- )
-
- [elem2] => SimpleXMLElement Object
- (
- [elem3] => SimpleXMLElement Object
- (
- [included-entity] => SimpleXMLElement Object
- (
- [included-entity] => This is text included from an entity
- )
-
- [elem4] => SimpleXMLElement Object
- (
- [test] => SimpleXMLElement Object
- (
- )
-
- )
-
- )
-
- )
-
- )
-
-)
----Done---
+===DONE===
+--EXPECTF--
+object(SimpleXMLElement)#%d (2) {
+ ["@attributes"]=>
+ array(1) {
+ ["id"]=>
+ string(5) "elem1"
+ }
+ ["elem1"]=>
+ object(SimpleXMLElement)#%d (3) {
+ ["@attributes"]=>
+ array(1) {
+ ["attr1"]=>
+ string(5) "first"
+ }
+ ["comment"]=>
+ object(SimpleXMLElement)#%d (0) {
+ }
+ ["elem2"]=>
+ object(SimpleXMLElement)#%d (1) {
+ ["elem3"]=>
+ object(SimpleXMLElement)#%d (2) {
+ ["included-entity"]=>
+ object(SimpleXMLElement)#%d (1) {
+ ["included-entity"]=>
+ string(36) "This is text included from an entity"
+ }
+ ["elem4"]=>
+ object(SimpleXMLElement)#%d (1) {
+ ["test"]=>
+ object(SimpleXMLElement)#%d (0) {
+ }
+ }
+ }
+ }
+ }
+}
+===DONE===
--TEST--
-SimpleXML and CDATA
+SimpleXML: CDATA
--SKIPIF--
<?php if (!extension_loaded("simplexml")) print "skip"; ?>
--FILE--
EOF
);
-print_r($sxe);
+var_dump($sxe);
$elem1 = $sxe->elem1;
$elem2 = $elem1->elem2;
?>
===DONE===
---EXPECT--
-SimpleXMLElement Object
-(
- [elem1] => SimpleXMLElement Object
- (
- [comment] => SimpleXMLElement Object
- (
- )
-
- [elem2] => SimpleXMLElement Object
- (
- [elem3] => SimpleXMLElement Object
- (
- [elem4] => SimpleXMLElement Object
- (
- [test] => SimpleXMLElement Object
- (
- )
-
- )
-
- )
-
- )
-
- )
-
-)
+--EXPECTF--
+object(SimpleXMLElement)#%d (2) {
+ ["@attributes"]=>
+ array(1) {
+ ["id"]=>
+ string(5) "elem1"
+ }
+ ["elem1"]=>
+ object(SimpleXMLElement)#%d (3) {
+ ["@attributes"]=>
+ array(1) {
+ ["attr1"]=>
+ string(5) "first"
+ }
+ ["comment"]=>
+ object(SimpleXMLElement)#%d (0) {
+ }
+ ["elem2"]=>
+ object(SimpleXMLElement)#%d (1) {
+ ["elem3"]=>
+ object(SimpleXMLElement)#%d (1) {
+ ["elem4"]=>
+ object(SimpleXMLElement)#%d (1) {
+ ["test"]=>
+ object(SimpleXMLElement)#%d (0) {
+ }
+ }
+ }
+ }
+ }
+}
string(11) "CDATA block"
===DONE===
---UEXPECT--
-SimpleXMLElement Object
-(
- [elem1] => SimpleXMLElement Object
- (
- [comment] => SimpleXMLElement Object
- (
- )
-
- [elem2] => SimpleXMLElement Object
- (
- [elem3] => SimpleXMLElement Object
- (
- [elem4] => SimpleXMLElement Object
- (
- [test] => SimpleXMLElement Object
- (
- )
-
- )
-
- )
-
- )
-
- )
-
-)
-unicode(11) "CDATA block"
-===DONE===
--TEST--
-SimpleXML and text data
+SimpleXML: Text data
--SKIPIF--
<?php if (!extension_loaded("simplexml")) print "skip"; ?>
--FILE--
--TEST--
-SimpleXML and foreach
+SimpleXML: foreach
--SKIPIF--
<?php if (!extension_loaded("simplexml")) print "skip"; ?>
--FILE--
--TEST--
-SimpleXML and attributes
+SimpleXML: Attributes
--SKIPIF--
<?php if (!extension_loaded("simplexml")) print "skip"; ?>
--FILE--
===Done===
--EXPECTF--
===Property===
-object(SimpleXMLElement)#%d (2) {
+object(SimpleXMLElement)#%d (3) {
+ ["@attributes"]=>
+ array(1) {
+ ["attr1"]=>
+ string(5) "first"
+ }
["comment"]=>
object(SimpleXMLElement)#%d (0) {
}
int(4)
int(4)
===Done===
---UEXPECTF--
-===Property===
-object(SimpleXMLElement)#%d (2) {
- [u"comment"]=>
- object(SimpleXMLElement)#%d (0) {
- }
- [u"elem2"]=>
- object(SimpleXMLElement)#%d (1) {
- [u"elem3"]=>
- object(SimpleXMLElement)#%d (1) {
- [u"elem4"]=>
- object(SimpleXMLElement)#%d (1) {
- [u"test"]=>
- object(SimpleXMLElement)#%d (0) {
- }
- }
- }
- }
-}
-===Array===
-object(SimpleXMLElement)#%d (1) {
- [0]=>
- unicode(5) "elem1"
-}
-object(SimpleXMLElement)#%d (1) {
- [0]=>
- unicode(5) "first"
-}
-===Set===
-object(SimpleXMLElement)#%d (1) {
- [0]=>
- unicode(8) "Changed1"
-}
-object(SimpleXMLElement)#%d (1) {
- [0]=>
- unicode(2) "12"
-}
-===Unset===
-NULL
-NULL
-===Misc.===
-int(4)
-int(4)
-===Done===
--TEST--
-SimpleXML and XPath
+SimpleXML: XPath
--SKIPIF--
<?php if (!extension_loaded("simplexml")) print "skip"; ?>
--FILE--
--TEST--
-SimpleXML and foreach
+SimpleXML: foreach
--SKIPIF--
<?php if (!extension_loaded("simplexml")) print "skip"; ?>
--FILE--
</sxe>
EOF;
-$sxe = simplexml_load_string($xml, 'simplexml_inherited');
-
-print_r($sxe);
+var_dump(simplexml_load_string($xml, 'simplexml_inherited'));
?>
===DONE===
---EXPECT--
-simplexml_inherited Object
-(
- [elem1] => simplexml_inherited Object
- (
- [comment] => simplexml_inherited Object
- (
- )
-
- [elem2] => simplexml_inherited Object
- (
- [elem3] => simplexml_inherited Object
- (
- [elem4] => simplexml_inherited Object
- (
- [test] => simplexml_inherited Object
- (
- )
-
- )
-
- )
-
- )
-
- )
-
-)
+--EXPECTF--
+object(simplexml_inherited)#%d (2) {
+ ["@attributes"]=>
+ array(1) {
+ ["id"]=>
+ string(5) "elem1"
+ }
+ ["elem1"]=>
+ object(simplexml_inherited)#%d (3) {
+ ["@attributes"]=>
+ array(1) {
+ ["attr1"]=>
+ string(5) "first"
+ }
+ ["comment"]=>
+ object(simplexml_inherited)#%d (0) {
+ }
+ ["elem2"]=>
+ object(simplexml_inherited)#%d (1) {
+ ["elem3"]=>
+ object(simplexml_inherited)#%d (1) {
+ ["elem4"]=>
+ object(simplexml_inherited)#%d (1) {
+ ["test"]=>
+ object(simplexml_inherited)#%d (0) {
+ }
+ }
+ }
+ }
+ }
+}
===DONE===
--TEST--
-SimpleXML and echo/print
+SimpleXML: echo/print
--SKIPIF--
<?php
if (!extension_loaded('simplexml')) print 'skip';
--TEST--
-SimpleXML and Attribute creation
+SimpleXML: Attribute creation
--SKIPIF--
<?php
if (!extension_loaded('simplexml')) print 'skip';
--TEST--
-SimpleXML and Split text content
+SimpleXML: Split text content
--SKIPIF--
<?php
if (!extension_loaded('simplexml')) print 'skip';
--TEST--
-SimpleXML and foreach with children()
+SimpleXML: foreach with children()
--SKIPIF--
<?php if (!extension_loaded("simplexml")) print "skip"; ?>
--FILE--
--TEST--
-SimpleXML attribute compared to string
+SimpleXML: Attribute compared to string
--SKIPIF--
<?php if (!extension_loaded("simplexml")) print "skip"; ?>
--FILE--
--TEST--
-SimpleXML element check
+SimpleXML: Element check
--SKIPIF--
<?php if (!extension_loaded("simplexml")) print "skip"; ?>
--FILE--
--TEST--
-SimpleXML and attributes inside foreach
+SimpleXML: Attributes inside foreach
--SKIPIF--
<?php if (!extension_loaded("simplexml")) print "skip"; ?>
--FILE--
$sxe = simplexml_load_string($xml);
+echo "===CONTENT===\n";
+var_dump($sxe->content);
+
+echo "===FILE===\n";
+var_dump($sxe->content->file);
+
+echo "===FOREACH===\n";
foreach($sxe->content->file as $file)
{
var_dump($file);
?>
===DONE===
--EXPECTF--
-object(SimpleXMLElement)#%d (0) {
+===CONTENT===
+object(SimpleXMLElement)#%d (1) {
+ ["file"]=>
+ object(SimpleXMLElement)#%d (1) {
+ ["@attributes"]=>
+ array(1) {
+ ["glob"]=>
+ string(11) "slide_*.xml"
+ }
+ }
}
+===FILE===
object(SimpleXMLElement)#%d (1) {
- [0]=>
- string(11) "slide_*.xml"
+ ["@attributes"]=>
+ array(1) {
+ ["glob"]=>
+ string(11) "slide_*.xml"
+ }
}
-===DONE===
---UEXPECTF--
-object(SimpleXMLElement)#%d (0) {
+===FOREACH===
+object(SimpleXMLElement)#%d (1) {
+ ["@attributes"]=>
+ array(1) {
+ ["glob"]=>
+ string(11) "slide_*.xml"
+ }
}
object(SimpleXMLElement)#%d (1) {
[0]=>
- unicode(11) "slide_*.xml"
+ string(11) "slide_*.xml"
}
===DONE===
?>
===DONE===
--EXPECTF--
-object(SimpleXMLElement)#%d (0) {
+object(SimpleXMLElement)#%d (1) {
+ ["@attributes"]=>
+ array(1) {
+ ["attr"]=>
+ string(%d) "foo%sbar%sbaz"
+ }
}
object(SimpleXMLElement)#%d (1) {
[0]=>
--TEST--
-#27010: segfault and node text not displayed when returned from children()
+Bug #27010: segfault and node text not displayed when returned from children()
--FILE--
<?php
</root>
');
-echo $root->children('reserved-ns')->child;
-echo "\n";
-echo $root->children('special-ns')->child;
-foreach ($root->child as $child) {
- echo "$child\n";
-}
-echo "\n---Done---\n";
+var_dump($root->children('reserved-ns')->child);
+var_dump($root->children('special-ns')->child);
+var_dump((string)$root->children('reserved-ns')->child);
+var_dump((string)$root->children('special-ns')->child);
+var_dump($root->child);
?>
---EXPECT--
-Hello
-World
----Done---
+===DONE===
+--EXPECTF--
+object(SimpleXMLElement)#%d (1) {
+ [0]=>
+ string(5) "Hello"
+}
+object(SimpleXMLElement)#%d (1) {
+ [0]=>
+ string(5) "World"
+}
+string(5) "Hello"
+string(5) "World"
+object(SimpleXMLElement)#%d (0) {
+}
+===DONE===
--TEST--
-Interop: simplexml_import_dom
+SimpleXML [interop]: simplexml_import_dom
--SKIPIF--
<?php if (!extension_loaded("simplexml")) print "skip"; ?>
<?php if (!extension_loaded("dom")) print "skip. dom extension not loaded"; ?>
<?xml encoding='US-ASCII'?>\r
\r
-<!ELEMENT sxe elem1, elem 11>\r
+<!ELEMENT sxe (elem1+, elem11, elem22*)>\r
<!ATTLIST sxe id CDATA #implied>\r
\r
-<!ELEMENT elem1 elem2>\r
+<!ELEMENT elem1 elem2*>\r
<!ATTLIST elem1 attr1 CDATA #required\r
attr2 CDATA "default>\r
\r
-<!ELEMENT elem2 elem3>\r
-<!ATTLIST elem2>\r
+<!ELEMENT elem2 elem3*>\r
+<!ATTLIST elem2 att25 CDATA #implied\r
+ att42 CDATA #implied>\r
\r
-<!ELEMENT elem3 elem4>\r
+<!ELEMENT elem3 elem4*>\r
<!ATTLIST elem3>\r
\r
<!ELEMENT elem4 EMPTY>\r
<!ATTLIST elem4>\r
\r
-<!ELEMENT elem11 EMPTY>\r
+<!ELEMENT elem11 elem111*>\r
<!ATTLIST elem11>\r
\r
+<!ELEMNET elem111 elem1111*>\r
+<!ATTLIST elem111>\r
+\r
+<!ELEMENT elem1111 EMPTY>\r
+<!ATTLIST elem1111>\r
+\r
+<!ELEMENT elem22 elem222*>\r
+<!ATTLIST elem22 attr22 CDATA #implied>\r
+\r
+<!ELEMENT elem222 EMPTY>\r
+<!ATTLIST elem222>\r
+\r