import zend simplexml tests

Esse commit está contido em:
Paul Tarjan
2013-04-23 16:13:15 -07:00
commit de Sara Golemon
commit bd5e0b1f7b
192 arquivos alterados com 3877 adições e 1 exclusões
+34
Ver Arquivo
@@ -0,0 +1,34 @@
<?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((bool)\$$what);");
eval("var_dump(count(\$$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');
if (!ini_get("unicode_semantics")) 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); ?>
@@ -0,0 +1,214 @@
===sxe
bool(true)
bool(true)
int(3)
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)
bool(true)
int(2)
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)
bool(true)
int(1)
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)
bool(true)
int(1)
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)
bool(false)
int(0)
object(SimpleXMLElement)#%d (0) {
}
===sxe->elem1[0]["attr1"]
bool(true)
bool(true)
int(0)
object(SimpleXMLElement)#%d (1) {
[0]=>
string(5) "first"
}
===sxe->elem1[0]->attr1
bool(false)
bool(false)
int(0)
object(SimpleXMLElement)#%d (0) {
}
===sxe->elem1[1]
bool(true)
bool(true)
int(0)
object(SimpleXMLElement)#%d (1) {
["@attributes"]=>
array(2) {
["attr1"]=>
string(2) "11"
["attr2"]=>
string(2) "12"
}
}
===sxe->elem1[2]
bool(false)
bool(false)
int(0)
NULL
===sxe->elem11
bool(true)
bool(true)
int(1)
object(SimpleXMLElement)#%d (1) {
["elem111"]=>
object(SimpleXMLElement)#%d (1) {
["elem1111"]=>
object(SimpleXMLElement)#%d (0) {
}
}
}
===sxe->elem11->elem111
bool(true)
bool(true)
int(1)
object(SimpleXMLElement)#%d (1) {
["elem1111"]=>
object(SimpleXMLElement)#%d (0) {
}
}
===sxe->elem11->elem111->elem1111
bool(true)
bool(true)
int(1)
object(SimpleXMLElement)#%d (0) {
}
===sxe->elem22
bool(false)
bool(false)
int(0)
object(SimpleXMLElement)#%d (0) {
}
===sxe->elem22->elem222
bool(false)
bool(false)
int(0)
NULL
===sxe->elem22->attr22
bool(false)
bool(false)
int(0)
NULL
===sxe->elem22["attr22"]
bool(false)
bool(false)
int(0)
NULL
===DONE===
+6
Ver Arquivo
@@ -0,0 +1,6 @@
<?php
var_dump(simplexml_load_file(dirname(__FILE__).'/sxe.xml'));
?>
===DONE===
@@ -0,0 +1,31 @@
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===
+27
Ver Arquivo
@@ -0,0 +1,27 @@
<?php
$xml =<<<EOF
<?xml version='1.0'?>
<!DOCTYPE sxe SYSTEM "notfound.dtd">
<sxe id="elem1">
<elem1 attr1='first'>
<!-- comment -->
<elem2>
<elem3>
<elem4>
<?test processing instruction ?>
</elem4>
</elem3>
</elem2>
</elem1>
</sxe>
EOF;
$sxe = simplexml_load_string($xml);
$copy = clone $sxe;
var_dump($copy);
?>
===DONE===
@@ -0,0 +1,31 @@
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===
+27
Ver Arquivo
@@ -0,0 +1,27 @@
<?php
$xml =<<<EOF
<?xml version='1.0'?>
<!DOCTYPE sxe SYSTEM "notfound.dtd" [
<!ENTITY included-entity "This is text included from an entity">
]>
<sxe id="elem1">
Plain text.
<elem1 attr1='first'>
<!-- comment -->
<elem2>
<elem3>
&included-entity;
<elem4>
<?test processing instruction ?>
</elem4>
</elem3>
</elem2>
</elem1>
</sxe>
EOF;
var_dump(simplexml_load_string($xml));
?>
===DONE===
@@ -0,0 +1,36 @@
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===
+30
Ver Arquivo
@@ -0,0 +1,30 @@
<?php
$sxe = simplexml_load_string(<<<EOF
<?xml version='1.0'?>
<!DOCTYPE sxe SYSTEM "notfound.dtd">
<sxe id="elem1">
Plain text.
<elem1 attr1='first'>
<!-- comment -->
<elem2>
<![CDATA[CDATA block]]>
<elem3>
<elem4>
<?test processing instruction ?>
</elem4>
</elem3>
</elem2>
</elem1>
</sxe>
EOF
);
var_dump($sxe);
$elem1 = $sxe->elem1;
$elem2 = $elem1->elem2;
var_dump(trim((string)$elem2));
?>
===DONE===
@@ -0,0 +1,32 @@
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===
+30
Ver Arquivo
@@ -0,0 +1,30 @@
<?php
$sxe = simplexml_load_string(<<<EOF
<?xml version='1.0'?>
<!DOCTYPE sxe SYSTEM "notfound.dtd">
<sxe id="elem1">
Plain text.
<elem1 attr1='first'>
<!-- comment -->
<elem2>
Here we have some text data.
<elem3>
And here some more.
<elem4>
Wow once again.
</elem4>
</elem3>
</elem2>
</elem1>
</sxe>
EOF
);
var_dump(trim($sxe->elem1->elem2));
var_dump(trim($sxe->elem1->elem2->elem3));
var_dump(trim($sxe->elem1->elem2->elem3->elem4));
echo "---Done---\n";
?>
@@ -0,0 +1,4 @@
string(28) "Here we have some text data."
string(19) "And here some more."
string(15) "Wow once again."
---Done---
+58
Ver Arquivo
@@ -0,0 +1,58 @@
<?php
$sxe = simplexml_load_string(<<<EOF
<?xml version='1.0'?>
<!DOCTYPE sxe SYSTEM "notfound.dtd">
<sxe id="elem1">
Plain text.
<elem1 attr1='first'>
Bla bla 1.
<!-- comment -->
<elem2>
Here we have some text data.
<elem3>
And here some more.
<elem4>
Wow once again.
</elem4>
</elem3>
</elem2>
</elem1>
<elem11 attr2='second'>
Bla bla 2.
<elem111>
Foo Bar
</elem111>
</elem11>
</sxe>
EOF
);
foreach($sxe as $name => $data) {
var_dump($name);
var_dump(trim($data));
}
echo "===CLONE===\n";
foreach(clone $sxe as $name => $data) {
var_dump($name);
var_dump(trim($data));
}
echo "===ELEMENT===\n";
foreach($sxe->elem11 as $name => $data) {
var_dump($name);
var_dump(trim($data));
}
echo "===COMMENT===\n";
foreach($sxe->elem1 as $name => $data) {
var_dump($name);
var_dump(trim($data));
}
?>
===DONE===
@@ -0,0 +1,16 @@
string(5) "elem1"
string(10) "Bla bla 1."
string(6) "elem11"
string(10) "Bla bla 2."
===CLONE===
string(5) "elem1"
string(10) "Bla bla 1."
string(6) "elem11"
string(10) "Bla bla 2."
===ELEMENT===
string(6) "elem11"
string(10) "Bla bla 2."
===COMMENT===
string(5) "elem1"
string(10) "Bla bla 1."
===DONE===
+43
Ver Arquivo
@@ -0,0 +1,43 @@
<?php
$xml =<<<EOF
<?xml version='1.0'?>
<!DOCTYPE sxe SYSTEM "notfound.dtd">
<sxe id="elem1">
<elem1 attr1='first'>
<!-- comment -->
<elem2>
<elem3>
<elem4>
<?test processing instruction ?>
</elem4>
</elem3>
</elem2>
</elem1>
</sxe>
EOF;
$sxe = simplexml_load_string($xml);
echo "===Property===\n";
var_dump($sxe->elem1);
echo "===Array===\n";
var_dump($sxe['id']);
var_dump($sxe->elem1['attr1']);
echo "===Set===\n";
$sxe['id'] = "Changed1";
var_dump($sxe['id']);
$sxe->elem1['attr1'] = 12;
var_dump($sxe->elem1['attr1']);
echo "===Unset===\n";
unset($sxe['id']);
var_dump($sxe['id']);
unset($sxe->elem1['attr1']);
var_dump($sxe->elem1['attr1']);
echo "===Misc.===\n";
$a = 4;
var_dump($a);
$dummy = $sxe->elem1[$a];
var_dump($a);
?>
===Done===
@@ -0,0 +1,48 @@
===Property===
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) {
}
}
}
}
}
===Array===
object(SimpleXMLElement)#%d (1) {
[0]=>
string(5) "elem1"
}
object(SimpleXMLElement)#%d (1) {
[0]=>
string(5) "first"
}
===Set===
object(SimpleXMLElement)#%d (1) {
[0]=>
string(8) "Changed1"
}
object(SimpleXMLElement)#%d (1) {
[0]=>
string(2) "12"
}
===Unset===
NULL
NULL
===Misc.===
int(4)
int(4)
===Done===
+27
Ver Arquivo
@@ -0,0 +1,27 @@
<?php
$xml =<<<EOF
<?xml version='1.0'?>
<!DOCTYPE sxe SYSTEM "notfound.dtd">
<sxe id="elem1">
<elem1 attr1='first'>
<!-- comment -->
<elem2>
<elem3>
<elem4>
<?test processing instruction ?>
</elem4>
</elem3>
</elem2>
</elem1>
</sxe>
EOF;
$sxe = simplexml_load_string($xml);
var_dump($sxe->xpath("elem1/elem2/elem3/elem4"));
//valid expression
var_dump($sxe->xpath("***"));
//invalid expression
var_dump($sxe->xpath("**"));
?>
@@ -0,0 +1,13 @@
array(1) {
[0]=>
object(SimpleXMLElement)#%d (1) {
["test"]=>
object(SimpleXMLElement)#%d (0) {
}
}
}
array(0) {
}
HipHop Warning: %a
HipHop Warning: %a
bool(false)
+17
Ver Arquivo
@@ -0,0 +1,17 @@
<?php
$sxe = simplexml_load_string(<<<EOF
<?xml version='1.0'?>
<!DOCTYPE sxe SYSTEM "notfound.dtd">
<sxe id="elem1">
Plain text.
<elem1 attr1='first'>Bla bla 1.<!-- comment --><elem2>
Here we have some text data.
</elem2></elem1>
<elem11 attr2='second'>Bla bla 2.</elem11>
</sxe>
EOF
);
var_dump($sxe->children());
?>
===DONE===
<?php exit(0); ?>
@@ -0,0 +1,12 @@
object(SimpleXMLElement)#%d (3) {
["@attributes"]=>
array(1) {
["id"]=>
string(5) "elem1"
}
["elem1"]=>
string(10) "Bla bla 1."
["elem11"]=>
string(10) "Bla bla 2."
}
===DONE===
+24
Ver Arquivo
@@ -0,0 +1,24 @@
<?php
$xml =<<<EOF
<?xml version="1.0" encoding="ISO-8859-1" ?>
<foo/>
EOF;
$sxe = simplexml_load_string($xml);
$sxe[""] = "warning";
$sxe["attr"] = "value";
echo $sxe->asXML();
$sxe["attr"] = "new value";
echo $sxe->asXML();
$sxe[] = "error";
__HALT_COMPILER();
?>
===DONE===
@@ -0,0 +1,6 @@
HipHop Warning: %a
<?xml version="1.0" encoding="ISO-8859-1"?>
<foo attr="value"/>
<?xml version="1.0" encoding="ISO-8859-1"?>
<foo attr="new value"/>
HipHop Fatal error: %a
+13
Ver Arquivo
@@ -0,0 +1,13 @@
<?php
$xml =<<<EOF
<?xml version="1.0" encoding="ISO-8859-1" ?>
<foo>bar<baz/>bar</foo>
EOF;
$sxe = simplexml_load_string($xml);
var_dump((string)$sxe);
?>
===DONE===
@@ -0,0 +1,2 @@
string(6) "barbar"
===DONE===
+27
Ver Arquivo
@@ -0,0 +1,27 @@
<?php
$xml =<<<EOF
<people>
<person name="Joe"></person>
</people>
EOF;
$people = simplexml_load_string($xml);
var_dump($people->person['name']);
var_dump($people->person['age']);
$person = $people->person;
$person['name'] = "XXX";
var_dump($people->person['name']);
$people->person['age'] = 30;
var_dump($people->person['age']);
echo "---Unset:---\n";
unset($people->person['age']);
echo "---Unset?---\n";
var_dump($people->person['age']);
var_dump(isset($people->person['age']));
$people->person['age'] = 30;
echo "---Unsupported---\n";
var_dump($people->person['age']);
$people->person['age'] += 5;
var_dump($people->person['age']);
?>
===DONE===
@@ -0,0 +1,27 @@
object(SimpleXMLElement)#%d (1) {
[0]=>
string(3) "Joe"
}
NULL
object(SimpleXMLElement)#%d (1) {
[0]=>
string(3) "XXX"
}
object(SimpleXMLElement)#%d (1) {
[0]=>
string(2) "30"
}
---Unset:---
---Unset?---
NULL
bool(false)
---Unsupported---
object(SimpleXMLElement)#%d (1) {
[0]=>
string(2) "30"
}
object(SimpleXMLElement)#%d (1) {
[0]=>
string(2) "35"
}
===DONE===
+26
Ver Arquivo
@@ -0,0 +1,26 @@
<?php
$xml =<<<EOF
<people>
<person name="Joe"></person>
</people>
EOF;
$people = simplexml_load_string($xml);
var_dump($people->person[0]['name']);
var_dump($people->person[0]['age']);
$person = $people->person[0];
$person['name'] = "XXX";
var_dump($people->person[0]['name']);
$people->person[0]['age'] = 30;
var_dump($people->person[0]['age']);
echo "---Unset:---\n";
unset($people->person[0]['age']);
echo "---Unset?---\n";
var_dump($people->person[0]['age']);
var_dump(isset($people->person[0]['age']));
echo "---Unsupported---\n";
var_dump($people->person[0]['age']);
$people->person['age'] += 5;
var_dump($people->person[0]['age']);
?>
===DONE===
@@ -0,0 +1,24 @@
object(SimpleXMLElement)#%d (1) {
[0]=>
string(3) "Joe"
}
NULL
object(SimpleXMLElement)#%d (1) {
[0]=>
string(3) "XXX"
}
object(SimpleXMLElement)#%d (1) {
[0]=>
string(2) "30"
}
---Unset:---
---Unset?---
NULL
bool(false)
---Unsupported---
NULL
object(SimpleXMLElement)#%d (1) {
[0]=>
string(1) "5"
}
===DONE===
+26
Ver Arquivo
@@ -0,0 +1,26 @@
<?php
$xml =<<<EOF
<people>
<person name="Joe"></person>
<person name="Boe"></person>
</people>
EOF;
$people = simplexml_load_string($xml);
var_dump($people->person[0]['name']);
var_dump($people->person[1]['age']);
$person = $people->person[1];
$person['name'] = "XXX";
var_dump($people->person[1]['name']);
$people->person[1]['age'] = 30;
var_dump($people->person[1]['age']);
echo "---Unset:---\n";
unset($people->person[1]['age']);
echo "---Unset?---\n";
var_dump($people->person[1]['age']);
var_dump(isset($people->person[1]['age']));
echo "---Unsupported---\n";
$people->person[1]['age'] += 5;
var_dump($people->person[1]['age']);
?>
===DONE===
@@ -0,0 +1,23 @@
object(SimpleXMLElement)#%d (1) {
[0]=>
string(3) "Joe"
}
NULL
object(SimpleXMLElement)#%d (1) {
[0]=>
string(3) "XXX"
}
object(SimpleXMLElement)#%d (1) {
[0]=>
string(2) "30"
}
---Unset:---
---Unset?---
NULL
bool(false)
---Unsupported---
object(SimpleXMLElement)#%d (1) {
[0]=>
string(1) "5"
}
===DONE===
+33
Ver Arquivo
@@ -0,0 +1,33 @@
<?php
$xml =<<<EOF
<people>
<person name="Joe"></person>
</people>
EOF;
$xml2 =<<<EOF
<people>
<person name="Joe"></person>
<person name="Boe"></person>
</people>
EOF;
$people = simplexml_load_string($xml);
var_dump($people->person['name']);
var_dump($people->person[0]['name']);
//$people->person['name'] = "XXX";
//var_dump($people->person['name']);
//var_dump($people->person[0]['name']);
//$people->person[0]['name'] = "YYY";
//var_dump($people->person['name']);
//var_dump($people->person[0]['name']);
//unset($people->person[0]['name']);
//var_dump($people->person['name']);
//var_dump($people->person[0]['name']);
//var_dump(isset($people->person['name']));
//var_dump(isset($people->person[0]['name']));
$people = simplexml_load_string($xml2);
var_dump($people->person[0]['name']);
var_dump($people->person[1]['name']);
?>
===DONE===
@@ -0,0 +1,17 @@
object(SimpleXMLElement)#%d (1) {
[0]=>
string(3) "Joe"
}
object(SimpleXMLElement)#%d (1) {
[0]=>
string(3) "Joe"
}
object(SimpleXMLElement)#%d (1) {
[0]=>
string(3) "Joe"
}
object(SimpleXMLElement)#%d (1) {
[0]=>
string(3) "Boe"
}
===DONE===
+25
Ver Arquivo
@@ -0,0 +1,25 @@
<?php
$xml =<<<EOF
<people>
<person name="Joe"></person>
</people>
EOF;
$people = simplexml_load_string($xml);
var_dump($people->person['name']);
$people->person['name'] = $people->person['name'] . 'Foo';
var_dump($people->person['name']);
$people->person['name'] .= 'Bar';
var_dump($people->person['name']);
echo "---[0]---\n";
$people = simplexml_load_string($xml);
var_dump($people->person[0]['name']);
$people->person[0]['name'] = $people->person[0]['name'] . 'Foo';
var_dump($people->person[0]['name']);
$people->person[0]['name'] .= 'Bar';
var_dump($people->person[0]['name']);
?>
===DONE===
@@ -0,0 +1,26 @@
object(SimpleXMLElement)#%d (1) {
[0]=>
string(3) "Joe"
}
object(SimpleXMLElement)#%d (1) {
[0]=>
string(6) "JoeFoo"
}
object(SimpleXMLElement)#%d (1) {
[0]=>
string(9) "JoeFooBar"
}
---[0]---
object(SimpleXMLElement)#%d (1) {
[0]=>
string(3) "Joe"
}
object(SimpleXMLElement)#%d (1) {
[0]=>
string(6) "JoeFoo"
}
object(SimpleXMLElement)#%d (1) {
[0]=>
string(9) "JoeFooBar"
}
===DONE===
+14
Ver Arquivo
@@ -0,0 +1,14 @@
<?php
$xml =<<<EOF
<people>
<person name="Foo"></person>
</people>
EOF;
$people = simplexml_load_string($xml);
var_dump($people->person['name']);
$people->person['name'] .= 'Bar';
var_dump($people->person['name']);
?>
===DONE===
@@ -0,0 +1,9 @@
object(SimpleXMLElement)#%d (1) {
[0]=>
string(3) "Foo"
}
object(SimpleXMLElement)#%d (1) {
[0]=>
string(6) "FooBar"
}
===DONE===
+51
Ver Arquivo
@@ -0,0 +1,51 @@
<?php
$xml =<<<EOF
<people>
<person name="Joe">
<child name="Ann" />
<child name="Marray" />
</person>
<person name="Boe">
<child name="Joe" />
<child name="Ann" />
</person>
</people>
EOF;
$xml1 =<<<EOF
<people>
<person name="Joe">
<child name="Ann" />
</person>
</people>
EOF;
function print_xml($xml) {
foreach($xml->children() as $person) {
echo "person: ".$person['name']."\n";
foreach($person->children() as $child) {
echo " child: ".$child['name']."\n";
}
}
}
function print_xml2($xml) {
$persons = 2;
for ($i=0;$i<$persons;$i++) {
echo "person: ".$xml->person[$i]['name']."\n";
$children = 2;
for ($j=0;$j<$children;$j++) {
echo " child: ".$xml->person[$i]->child[$j]['name']."\n";
}
}
}
echo "---11---\n";
print_xml(simplexml_load_string($xml));
echo "---12---\n";
print_xml(simplexml_load_string($xml1));
echo "---21---\n";
print_xml2(simplexml_load_string($xml));
echo "---22---\n";
print_xml2(simplexml_load_string($xml1));
?>
===DONE===
@@ -0,0 +1,27 @@
---11---
person: Joe
child: Ann
child: Marray
person: Boe
child: Joe
child: Ann
---12---
person: Joe
child: Ann
---21---
person: Joe
child: Ann
child: Marray
person: Boe
child: Joe
child: Ann
---22---
person: Joe
child: Ann
child:
person:
HipHop Notice: %a
child:
HipHop Notice: %a
child:
===DONE===
+41
Ver Arquivo
@@ -0,0 +1,41 @@
<?php
$xml =<<<EOF
<people>
<person name="Joe">
Text1
<child name="Ann" />
Text2
<child name="Marray" />
Text3
</person>
<person name="Boe">
<child name="Joe" />
<child name="Ann" />
</person>
</people>
EOF;
$xml1 =<<<EOF
<people>
<person name="Joe">
<child />
</person>
</people>
EOF;
function traverse_xml($pad,$xml) {
foreach($xml->children() as $name => $node) {
echo $pad."<$name";
foreach($node->attributes() as $attr => $value) {
echo " $attr=\"$value\"";
}
echo ">\n";
traverse_xml($pad." ",$node);
echo $pad."</$name>\n";
}
}
traverse_xml("",simplexml_load_string($xml));
echo "----------\n";
traverse_xml("",simplexml_load_string($xml1));
echo "---Done---\n";
?>
@@ -0,0 +1,18 @@
<person name="Joe">
<child name="Ann">
</child>
<child name="Marray">
</child>
</person>
<person name="Boe">
<child name="Joe">
</child>
<child name="Ann">
</child>
</person>
----------
<person name="Joe">
<child>
</child>
</person>
---Done---
+58
Ver Arquivo
@@ -0,0 +1,58 @@
<?php
$sxe = simplexml_load_string(<<<EOF
<?xml version='1.0'?>
<!DOCTYPE sxe SYSTEM "notfound.dtd">
<sxe id="elem1">
Plain text.
<elem1 attr1='first'>
Bla bla 1.
<!-- comment -->
<elem2>
Here we have some text data.
<elem3>
And here some more.
<elem4>
Wow once again.
</elem4>
</elem3>
</elem2>
</elem1>
<elem11 attr2='second'>
Bla bla 2.
<elem111>
Foo Bar
</elem111>
</elem11>
</sxe>
EOF
);
foreach($sxe->children() as $name => $data) {
var_dump($name);
var_dump(trim($data));
}
echo "===CLONE===\n";
foreach(clone $sxe->children() as $name => $data) {
var_dump($name);
var_dump(trim($data));
}
echo "===ELEMENT===\n";
foreach($sxe->elem11->children() as $name => $data) {
var_dump($name);
var_dump(trim($data));
}
echo "===COMMENT===\n";
foreach($sxe->elem1->children() as $name => $data) {
var_dump($name);
var_dump(trim($data));
}
?>
===DONE===
@@ -0,0 +1,16 @@
string(5) "elem1"
string(10) "Bla bla 1."
string(6) "elem11"
string(10) "Bla bla 2."
===CLONE===
string(5) "elem1"
string(10) "Bla bla 1."
string(6) "elem11"
string(10) "Bla bla 2."
===ELEMENT===
string(7) "elem111"
string(7) "Foo Bar"
===COMMENT===
string(5) "elem2"
string(28) "Here we have some text data."
===DONE===
+24
Ver Arquivo
@@ -0,0 +1,24 @@
<?php
$xml =<<<EOF
<?xml version='1.0'?>
<pres><content><file glob="slide_*.xml"/></content></pres>
EOF;
$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);
var_dump($file['glob']);
}
?>
===DONE===
@@ -0,0 +1,32 @@
===CONTENT===
object(SimpleXMLElement)#%d (1) {
["file"]=>
object(SimpleXMLElement)#%d (1) {
["@attributes"]=>
array(1) {
["glob"]=>
string(11) "slide_*.xml"
}
}
}
===FILE===
object(SimpleXMLElement)#%d (1) {
["@attributes"]=>
array(1) {
["glob"]=>
string(11) "slide_*.xml"
}
}
===FOREACH===
object(SimpleXMLElement)#%d (1) {
["@attributes"]=>
array(1) {
["glob"]=>
string(11) "slide_*.xml"
}
}
object(SimpleXMLElement)#%d (1) {
[0]=>
string(11) "slide_*.xml"
}
===DONE===
+18
Ver Arquivo
@@ -0,0 +1,18 @@
<?php
$xml =<<<EOF
<?xml version='1.0'?>
<!DOCTYPE talks SYSTEM "nbsp.dtd" [
<!ELEMENT root EMPTY>
<!ATTLIST root attr1 CDATA #IMPLIED>
<!ENTITY nbsp "&#38;#x00A0;">
]>
<root attr='foo&nbsp;bar&nbsp;baz'></root>
EOF;
$sxe = simplexml_load_string($xml);
var_dump($sxe);
var_dump($sxe['attr']);
?>
===DONE===
@@ -0,0 +1,12 @@
object(SimpleXMLElement)#%d (1) {
["@attributes"]=>
array(1) {
["attr"]=>
string(%d) "foo%sbar%sbaz"
}
}
object(SimpleXMLElement)#%d (1) {
[0]=>
string(%d) "foo%sbar%sbaz"
}
===DONE===
+28
Ver Arquivo
@@ -0,0 +1,28 @@
<?php
$xml =<<<EOF
<?xml version='1.0'?>
<root>
<elem attr1='11' attr2='12' attr3='13'/>
<elem attr1='21' attr2='22' attr3='23'/>
<elem attr1='31' attr2='32' attr3='33'/>
</root>
EOF;
$sxe = simplexml_load_string($xml);
function test($xpath)
{
global $sxe;
echo "===$xpath===\n";
var_dump($sxe->xpath($xpath));
}
test('elem/@attr2');
test('//@attr2');
test('//@*');
test('elem[2]/@attr2');
?>
===DONE===
@@ -0,0 +1,141 @@
===elem/@attr2===
array(3) {
[0]=>
object(SimpleXMLElement)#%d (1) {
["@attributes"]=>
array(1) {
["attr2"]=>
string(2) "12"
}
}
[1]=>
object(SimpleXMLElement)#%d (1) {
["@attributes"]=>
array(1) {
["attr2"]=>
string(2) "22"
}
}
[2]=>
object(SimpleXMLElement)#%d (1) {
["@attributes"]=>
array(1) {
["attr2"]=>
string(2) "32"
}
}
}
===//@attr2===
array(3) {
[0]=>
object(SimpleXMLElement)#%d (1) {
["@attributes"]=>
array(1) {
["attr2"]=>
string(2) "12"
}
}
[1]=>
object(SimpleXMLElement)#%d (1) {
["@attributes"]=>
array(1) {
["attr2"]=>
string(2) "22"
}
}
[2]=>
object(SimpleXMLElement)#%d (1) {
["@attributes"]=>
array(1) {
["attr2"]=>
string(2) "32"
}
}
}
===//@*===
array(9) {
[0]=>
object(SimpleXMLElement)#%d (1) {
["@attributes"]=>
array(1) {
["attr1"]=>
string(2) "11"
}
}
[1]=>
object(SimpleXMLElement)#%d (1) {
["@attributes"]=>
array(1) {
["attr2"]=>
string(2) "12"
}
}
[2]=>
object(SimpleXMLElement)#%d (1) {
["@attributes"]=>
array(1) {
["attr3"]=>
string(2) "13"
}
}
[3]=>
object(SimpleXMLElement)#%d (1) {
["@attributes"]=>
array(1) {
["attr1"]=>
string(2) "21"
}
}
[4]=>
object(SimpleXMLElement)#%d (1) {
["@attributes"]=>
array(1) {
["attr2"]=>
string(2) "22"
}
}
[5]=>
object(SimpleXMLElement)#%d (1) {
["@attributes"]=>
array(1) {
["attr3"]=>
string(2) "23"
}
}
[6]=>
object(SimpleXMLElement)#%d (1) {
["@attributes"]=>
array(1) {
["attr1"]=>
string(2) "31"
}
}
[7]=>
object(SimpleXMLElement)#%d (1) {
["@attributes"]=>
array(1) {
["attr2"]=>
string(2) "32"
}
}
[8]=>
object(SimpleXMLElement)#%d (1) {
["@attributes"]=>
array(1) {
["attr3"]=>
string(2) "33"
}
}
}
===elem[2]/@attr2===
array(1) {
[0]=>
object(SimpleXMLElement)#%d (1) {
["@attributes"]=>
array(1) {
["attr2"]=>
string(2) "22"
}
}
}
===DONE===
+40
Ver Arquivo
@@ -0,0 +1,40 @@
<?php
$xml =<<<EOF
<people></people>
EOF;
function traverse_xml($xml, $pad = '')
{
$name = $xml->getName();
echo "$pad<$name";
foreach($xml->attributes() as $attr => $value)
{
echo " $attr=\"$value\"";
}
echo ">" . trim($xml) . "\n";
foreach($xml->children() as $node)
{
traverse_xml($node, $pad.' ');
}
echo $pad."</$name>\n";
}
$people = simplexml_load_string($xml);
traverse_xml($people);
$people->person = 'Joe';
$people->person['gender'] = 'male';
traverse_xml($people);
$people->person = 'Jane';
traverse_xml($people);
$people->person['gender'] = 'female';
$people->person[1] = 'Joe';
$people->person[1]['gender'] = 'male';
traverse_xml($people);
$people->person[3] = 'Minni-me';
$people->person[2]['gender'] = 'male';
traverse_xml($people);
$people->person[3]['gender'] = 'error';
traverse_xml($people);
?>
===DONE===
@@ -0,0 +1,36 @@
<people>
</people>
<people>
<person gender="male">Joe
</person>
</people>
<people>
<person gender="male">Jane
</person>
</people>
<people>
<person gender="female">Jane
</person>
<person gender="male">Joe
</person>
</people>
HipHop Warning: %a
<people>
<person gender="female">Jane
</person>
<person gender="male">Joe
</person>
<person gender="male">Minni-me
</person>
</people>
<people>
<person gender="female">Jane
</person>
<person gender="male">Joe
</person>
<person gender="male">Minni-me
</person>
<person gender="error">
</person>
</people>
===DONE===
+29
Ver Arquivo
@@ -0,0 +1,29 @@
<?php
$xml =<<<EOF
<people></people>
EOF;
function traverse_xml($xml, $pad = '')
{
$name = $xml->getName();
echo "$pad<$name";
foreach($xml->attributes() as $attr => $value)
{
echo " $attr=\"$value\"";
}
echo ">" . trim($xml) . "\n";
foreach($xml->children() as $node)
{
traverse_xml($node, $pad.' ');
}
echo $pad."</$name>\n";
}
$people = simplexml_load_string($xml);
traverse_xml($people);
$people->person['name'] = 'John';
traverse_xml($people);
?>
===DONE===
@@ -0,0 +1,7 @@
<people>
</people>
<people>
<person name="John">
</person>
</people>
===DONE===
+24
Ver Arquivo
@@ -0,0 +1,24 @@
<?php
$xml =<<<EOF
<people>
<person name="Joe"/>
<person name="John">
<children>
<person name="Joe"/>
</children>
</person>
<person name="Jane"/>
</people>
EOF;
$people = simplexml_load_string($xml);
foreach($people as $person)
{
var_dump((string)$person['name']);
var_dump(count($people));
var_dump(count($person));
}
?>
===DONE===
@@ -0,0 +1,10 @@
string(3) "Joe"
int(3)
int(0)
string(4) "John"
int(3)
int(1)
string(4) "Jane"
int(3)
int(0)
===DONE===
+28
Ver Arquivo
@@ -0,0 +1,28 @@
<?php
$xml =<<<EOF
<root s:att1="b" att1="a"
xmlns:s="urn::test" xmlns:t="urn::test-t">
<child1>test</child1>
<child1>test 2</child1>
<s:child3 />
</root>
EOF;
$sxe = simplexml_load_string($xml);
echo $sxe->child1[0]."\n";
echo $sxe->child1[1]."\n\n";
var_dump(isset($sxe->child1[1]));
unset($sxe->child1[1]);
var_dump(isset($sxe->child1[1]));
echo "\n";
$atts = $sxe->attributes("urn::test");
var_dump(isset($atts[0]));
unset($atts[0]);
var_dump(isset($atts[0]));
var_dump(isset($atts[TRUE]));
?>
===DONE===
@@ -0,0 +1,10 @@
test
test 2
bool(true)
bool(false)
bool(true)
bool(false)
bool(false)
===DONE===
+35
Ver Arquivo
@@ -0,0 +1,35 @@
<?php
$xml =<<<EOF
<people>
<person name="Joe"/>
<person name="John">
<children>
<person name="Joe"/>
</children>
</person>
<person name="Jane"/>
</people>
EOF;
$xml1 =<<<EOF
<people>
<person name="John">
<children>
<person name="Joe"/>
</children>
</person>
<person name="Jane"/>
</people>
EOF;
$people = simplexml_load_string($xml);
$people1 = simplexml_load_string($xml);
$people2 = simplexml_load_string($xml1);
var_dump($people1 == $people);
var_dump($people2 == $people);
var_dump($people2 == $people1);
?>
===DONE===
@@ -0,0 +1,4 @@
bool(false)
bool(false)
bool(false)
===DONE===
+33
Ver Arquivo
@@ -0,0 +1,33 @@
<?php
$xml =<<<EOF
<people>
test
<person name="Joe"/>
<person name="John">
<children>
<person name="Joe"/>
</children>
</person>
<person name="Jane"/>
</people>
EOF;
$foo = simplexml_load_string( "<foo />" );
$people = simplexml_load_string($xml);
var_dump((bool)$foo);
var_dump((bool)$people);
var_dump((int)$foo);
var_dump((int)$people);
var_dump((double)$foo);
var_dump((double)$people);
var_dump((string)$foo);
var_dump((string)$people);
var_dump((array)$foo);
var_dump((array)$people);
var_dump((object)$foo);
var_dump((object)$people);
?>
===DONE===
@@ -0,0 +1,98 @@
bool(false)
bool(true)
int(0)
int(0)
float(0)
float(0)
string(0) ""
string(15) "
test
"
array(0) {
}
array(1) {
["person"]=>
array(3) {
[0]=>
object(SimpleXMLElement)#%d (1) {
["@attributes"]=>
array(1) {
["name"]=>
string(3) "Joe"
}
}
[1]=>
object(SimpleXMLElement)#%d (2) {
["@attributes"]=>
array(1) {
["name"]=>
string(4) "John"
}
["children"]=>
object(SimpleXMLElement)#%d (1) {
["person"]=>
object(SimpleXMLElement)#%d (1) {
["@attributes"]=>
array(1) {
["name"]=>
string(3) "Joe"
}
}
}
}
[2]=>
object(SimpleXMLElement)#%d (1) {
["@attributes"]=>
array(1) {
["name"]=>
string(4) "Jane"
}
}
}
}
object(SimpleXMLElement)#%d (0) {
}
object(SimpleXMLElement)#%d (1) {
["person"]=>
array(3) {
[0]=>
object(SimpleXMLElement)#%d (1) {
["@attributes"]=>
array(1) {
["name"]=>
string(3) "Joe"
}
}
[1]=>
object(SimpleXMLElement)#%d (2) {
["@attributes"]=>
array(1) {
["name"]=>
string(4) "John"
}
["children"]=>
object(SimpleXMLElement)#%d (1) {
["person"]=>
object(SimpleXMLElement)#%d (1) {
["@attributes"]=>
array(1) {
["name"]=>
string(3) "Joe"
}
}
}
}
[2]=>
object(SimpleXMLElement)#%d (1) {
["@attributes"]=>
array(1) {
["name"]=>
string(4) "Jane"
}
}
}
}
===DONE===
+15
Ver Arquivo
@@ -0,0 +1,15 @@
<?php
$string = '<?xml version="1.0"?>
<foo><bar>
<p>Blah 1</p>
<p>Blah 2</p>
<p>Blah 3</p>
<tt>Blah 4</tt>
</bar></foo>
';
$foo = simplexml_load_string($string);
$p = $foo->bar->p;
echo count($p);
$p = (array)$foo->bar->p;
echo count($p);
?>
@@ -0,0 +1 @@
33
+13
Ver Arquivo
@@ -0,0 +1,13 @@
<?php
class SXE extends SimpleXmlElement {
public function count() {
echo "Called Count!\n";
return parent::count();
}
}
$str = '<xml><c>asdf</c><c>ghjk</c></xml>';
$sxe = new SXE($str);
var_dump(count($sxe));
?>
==Done==
@@ -0,0 +1,3 @@
Called Count!
int(2)
==Done==
@@ -0,0 +1,7 @@
<?php
$simple = simplexml_load_file(dirname(__FILE__)."/book.xml");
$simple->addAttribute('type','novels');
var_dump($simple->attributes());
echo "Done";
?>
@@ -0,0 +1,8 @@
object(SimpleXMLElement)#2 (1) {
["@attributes"]=>
array(1) {
["type"]=>
string(6) "novels"
}
}
Done
@@ -0,0 +1,23 @@
<?php
$xml=<<<EOF
<drinks xmlns:hot="http://www.example.com/hot">
<hot:drink><hot:name>Coffee</hot:name></hot:drink>
<hot:drink><hot:name>Tea</hot:name></hot:drink>
<drink><name>Cola</name></drink>
<drink><name>Juice</name></drink>
</drinks>
EOF;
$sxe = simplexml_load_string($xml);
foreach ($sxe as $element_name => $element) {
print "$element_name is $element->name\n";
}
foreach ($sxe->children('http://www.example.com/hot') as $element_name => $element) {
print "$element_name is $element->name\n";
}
?>
===DONE===
@@ -0,0 +1,5 @@
drink is Cola
drink is Juice
drink is Coffee
drink is Tea
===DONE===
@@ -0,0 +1,16 @@
<?php
$xml = simplexml_load_string("<root></root>");
$xml->bla->posts->name = "FooBar";
echo $xml->asXML();
$xml = simplexml_load_string("<root></root>");
$count = count($xml->bla->posts);
var_dump($count);
$xml->bla->posts[$count]->name = "FooBar";
echo $xml->asXML();
$xml = simplexml_load_string("<root></root>");
$xml->bla->posts[]->name = "FooBar";
echo $xml->asXML();
?>
===DONE===
<?php exit(0); __halt_compiler(); ?>
@@ -0,0 +1,8 @@
<?xml version="1.0"?>
<root><bla><posts><name>FooBar</name></posts></bla></root>
int(0)
<?xml version="1.0"?>
<root><bla><posts><name>FooBar</name></posts></bla></root>
<?xml version="1.0"?>
<root><bla><posts><name>FooBar</name></posts></bla></root>
===DONE===
@@ -0,0 +1,21 @@
<?php
$xml_str = <<<EOD
<?xml version="1.0" encoding="ISO-8859-1" ?>
<c_fpobel >
<pos >
<pos/>
</pos>
</c_fpobel>
EOD;
$xml = simplexml_load_string ($xml_str) ;
$val = 1;
var_dump($val);
$zml->pos["act_idx"] = $val;
var_dump($val) ;
?>
===DONE===
@@ -0,0 +1,3 @@
int(1)
int(1)
===DONE===
@@ -0,0 +1,6 @@
<?php
$xml = simplexml_load_string("<root><foo /></root>");
$xml->{""} .= "bar";
print $xml->asXML();
?>
===DONE===
@@ -0,0 +1,5 @@
HipHop Warning: %a
HipHop Warning: %a
<?xml version="1.0"?>
<root><foo/></root>
===DONE===
@@ -0,0 +1,14 @@
<?php
$sx1 = new SimpleXMLElement((binary)"<root />");
$sx1->node[0] = 'node1';
$sx1->node[1] = 'node2';
print $sx1->asXML()."\n";
$node = $sx1->node[0];
$node[0] = 'New Value';
print $sx1->asXML();
?>
@@ -0,0 +1,5 @@
<?xml version="1.0"?>
<root><node>node1</node><node>node2</node></root>
<?xml version="1.0"?>
<root><node>New Value</node><node>node2</node></root>
@@ -0,0 +1,18 @@
<?php
function my_error_handler($errno, $errstr, $errfile, $errline) {
echo "Error: $errstr\n";
}
set_error_handler('my_error_handler');
class Setting extends ReflectionObject
{
}
Reflection::export(simplexml_load_string('<test/>', 'Setting'));
Reflection::export(simplexml_load_file('data:,<test/>', 'Setting'));
?>
===DONE===
@@ -0,0 +1,7 @@
Error: simplexml_load_string() expects parameter 2 to be a class name derived from SimpleXMLElement, 'Setting' given
Error: Argument 1 passed to Reflection::export() must implement interface Reflector, null given
Error: Reflection::export() expects parameter 1 to be Reflector, null given
Error: simplexml_load_file() expects parameter 2 to be a class name derived from SimpleXMLElement, 'Setting' given
Error: Argument 1 passed to Reflection::export() must implement interface Reflector, null given
Error: Reflection::export() expects parameter 1 to be Reflector, null given
===DONE===
@@ -0,0 +1,16 @@
<?php
function iterate($xml)
{
print_r($xml);
foreach ($xml->item as $item) {
echo "This code will crash!";
}
}
$xmlstr = "<xml><item>Item 1</item><item>Item 2</item></xml>";
$xml = simplexml_load_string($xmlstr);
iterate($xml->unknown);
echo "Done\n";
?>
@@ -0,0 +1,5 @@
SimpleXMLElement Object
(
)
HipHop Warning: %a
Done
@@ -0,0 +1,14 @@
<?php
$item = new SimpleXMLElement(b'<something />');
$item->attribute = b'something';
var_dump($item->attribute);
$item->otherAttribute = $item->attribute;
var_dump($item->otherAttribute);
$a = array();
$item->$a = new stdclass;
echo "Done\n";
?>
@@ -0,0 +1,11 @@
object(SimpleXMLElement)#%d (1) {
[0]=>
string(9) "something"
}
object(SimpleXMLElement)#%d (1) {
[0]=>
string(9) "something"
}
HipHop Notice: %a
HipHop Warning: %a
Done
@@ -0,0 +1,15 @@
<?php
$xml = '<?xml version="1.0" encoding="utf-8" ?>
<test>
</test>';
$root = simplexml_load_string($xml);
$clone = clone $root;
var_dump($root);
var_dump($clone);
var_dump($clone->asXML());
echo "Done\n";
?>
@@ -0,0 +1,16 @@
object(SimpleXMLElement)#%d (1) {
[0]=>
string(2) "
"
}
object(SimpleXMLElement)#%d (1) {
[0]=>
string(2) "
"
}
string(15) "<test>
</test>"
Done
@@ -0,0 +1,21 @@
<?php
$xml = '<?xml version="1.0" ?>
<test>
<level1>
<level2a>text1</level2a>
<level2b>text2</level2b>
</level1>
</test>';
$test = simplexml_load_string($xml);
var_dump($test->level1->level2a);
$test2 = clone $test;
var_dump($test2->level1->level2a);
$test3 = clone $test->level1->level2a;
var_dump($test3);
echo "Done\n";
?>
@@ -0,0 +1,13 @@
object(SimpleXMLElement)#%d (1) {
[0]=>
string(5) "text1"
}
object(SimpleXMLElement)#%d (1) {
[0]=>
string(5) "text1"
}
object(SimpleXMLElement)#%d (1) {
[0]=>
string(5) "text1"
}
Done
@@ -0,0 +1,11 @@
<?php
$xml = new SimpleXMLElement('<?xml version="1.0" standalone="yes"?>
<collection></collection>');
$xml->movie[]->characters->character[0]->name = 'Miss Coder';
echo($xml->asXml());
?>
===DONE===
@@ -0,0 +1,3 @@
<?xml version="1.0" standalone="yes"?>
<collection><movie><characters><character><name>Miss Coder</name></character></characters></movie></collection>
===DONE===
@@ -0,0 +1,28 @@
<?php
$xml = simplexml_load_string('<root>
<first_node_no_ns />
<ns1:node1 xmlns:ns1="#ns1" />
<ns2:node2 xmlns:ns2="#ns2" />
<ns3:node3 xmlns:ns3="#ns3" />
<last_node_no_ns />
</root>');
$name = $xml->getName();
$namespaces = $xml->getNamespaces(True);
echo "root(recursive): '$name' -- namespaces: ", implode(', ', $namespaces), "\n";
$namespaces = $xml->getNamespaces(False);
echo "root(non-recursive): '$name' -- namespaces: ", implode(', ', $namespaces), "\n";
foreach (array(null, '#ns1', '#ns2', '#ns3') as $ns)
{
foreach ($xml->children($ns) as $child)
{
$name = $child->getName();
$namespaces = $child->getNamespaces(false);
echo "children($ns): '$name' -- namespaces: ", implode(', ', $namespaces), "\n";
}
}
?>
===DONE===
@@ -0,0 +1,8 @@
root(recursive): 'root' -- namespaces: #ns1, #ns2, #ns3
root(non-recursive): 'root' -- namespaces:
children(): 'first_node_no_ns' -- namespaces:
children(): 'last_node_no_ns' -- namespaces:
children(#ns1): 'node1' -- namespaces: #ns1
children(#ns2): 'node2' -- namespaces: #ns2
children(#ns3): 'node3' -- namespaces: #ns3
===DONE===
@@ -0,0 +1,32 @@
<?php
$xml =<<<EOF
<xml>
<fieldset1>
<field1/>
<field2/>
</fieldset1>
<fieldset2>
<options>
<option1/>
<option2/>
<option3/>
</options>
<field1/>
<field2/>
</fieldset2>
</xml>
EOF;
$sxe = new SimpleXMLIterator($xml);
$rit = new RecursiveIteratorIterator($sxe, RecursiveIteratorIterator::LEAVES_ONLY);
foreach ($rit as $child) {
$path = '';
$ancestry = $child->xpath('ancestor-or-self::*');
foreach ($ancestry as $ancestor) {
$path .= $ancestor->getName() . '/';
}
$path = substr($path, 0, strlen($path) - 1);
echo count($ancestry) . ' steps: ' . $path . PHP_EOL;
}
?>
===DONE===
@@ -0,0 +1,8 @@
3 steps: xml/fieldset1/field1
3 steps: xml/fieldset1/field2
4 steps: xml/fieldset2/options/option1
4 steps: xml/fieldset2/options/option2
4 steps: xml/fieldset2/options/option3
3 steps: xml/fieldset2/field1
3 steps: xml/fieldset2/field2
===DONE===
@@ -0,0 +1,9 @@
<?php
$xml = simplexml_load_string('<?xml version="1.0" encoding="utf-8"?><root />');
$n = $xml->addChild("node", "value");
$n->addAttribute("a", "b");
$n->addAttribute("c", "d", "http://bar.com");
$n->addAttribute("foo:e", "f", "http://bar.com");
print_r($xml->asXml());
?>
===DONE===
@@ -0,0 +1,4 @@
HipHop Warning: %a
<?xml version="1.0" encoding="utf-8"?>
<root><node xmlns:foo="http://bar.com" a="b" foo:e="f">value</node></root>
===DONE===
@@ -0,0 +1,23 @@
<?php
$xml =<<<XML
<xml xmlns:a="http://a">
<data a:label="I am A" label="I am Nothing">test1</data>
<a:data a:label="I am a:A" label="I am a:Nothing">test2</a:data>
</xml>
XML;
$x = simplexml_load_string($xml);
$x->registerXPathNamespace("a", "http://a");
$atts = $x->xpath("/xml/data/@a:label");
echo $atts[0] . "\n";
$atts = $x->xpath("/xml/a:data");
echo $atts[0]->attributes() . "\n";
$atts = $x->xpath("/xml/a:data/@a:label");
echo $atts[0] . "\n";
$atts = $x->xpath("/xml/a:data/@label");
echo $atts[0] . "\n";
$atts = $x->xpath("/xml/data/@label");
echo $atts[0] . "\n";
?>
===DONE===
@@ -0,0 +1,6 @@
I am A
I am a:Nothing
I am a:A
I am a:Nothing
I am Nothing
===DONE===
@@ -0,0 +1,10 @@
<?php
$xml = '
<data id="1">
<key>value</key>
</data>
';
$obj = simplexml_load_string($xml);
print_r(get_object_vars($obj));
?>
===DONE===
@@ -0,0 +1,10 @@
Array
(
[@attributes] => Array
(
[id] => 1
)
[key] => value
)
===DONE===
@@ -0,0 +1,13 @@
<?php
$sxe = simplexml_load_string('<root><node1>1</node1></root>');
$nodes = $sxe->xpath("/root/node2/@test");
if (! is_array($nodes)) {
echo "An error occurred\n";
} else {
echo "Result Count: " . count($nodes) . "\n";
}
?>
@@ -0,0 +1 @@
Result Count: 0

Alguns arquivos não foram exibidos porque demasiados arquivos foram alterados neste diff Mostrar Mais