Created
August 7, 2017 21:46
-
-
Save IMSoP/dab21ce9d97980adbc22fc867e6e9fcf to your computer and use it in GitHub Desktop.
Sample SimpleXML usage for testing https://github.com/JetBrains/phpstorm-stubs/pull/245
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$xml = <<<XML | |
<foo> | |
<bar baz="bob">1<bing>bang</bing></bar> | |
<bar>2</bar> | |
</foo> | |
XML; | |
$sx = simplexml_load_string($xml); | |
$a1 = $sx->bar; | |
$a1a = $a1->attributes()->baz; | |
$b1 = $sx->bar[0]; | |
$b1a = $b1->attributes()->baz; | |
$c1 = $sx->bar['baz']; | |
$d1 = $sx->bar[0]['baz']; | |
$e1 = $sx->bar->bing; | |
$f1 = $sx->bar[0]->bing; | |
$g1 = $sx->bar[0]->bing[0]; | |
$a2 = $sx[0]->bar; | |
$b2 = $sx[0]->bar[0]; | |
$c2 = $sx[0]->bar['baz']; | |
$d2 = $sx[0]->bar[0]['baz']; | |
$e2 = $sx[0]->bar->bing; | |
$f2 = $sx[0]->bar[0]->bing; | |
$g2 = $sx[0]->bar[0]->bing[0]; | |
$a3 = $sx->children()->bar; | |
$b3 = $sx->children()->bar[0]; | |
$c3 = $sx->children()->bar['baz']; | |
$d3 = $sx->children()->bar[0]['baz']; | |
$e3 = $sx->children()->bar->bing; | |
$f3 = $sx->children()->bar[0]->bing; | |
$g3 = $sx->children()->bar[0]->bing[0]; | |
$a4 = $sx[0]->children()->bar; | |
$b4 = $sx[0]->children()->bar[0]; | |
$c4 = $sx[0]->children()->bar['baz']; | |
$d4 = $sx[0]->children()->bar[0]['baz']; | |
$e4 = $sx[0]->children()->bar->bing; | |
$f4 = $sx[0]->children()->bar[0]->bing; | |
$g4 = $sx[0]->children()->bar[0]->bing[0]; | |
$c5 = $sx[0]->bar->attributes()->baz; | |
$d5 = $sx[0]->bar[0]->attributes()->baz; | |
$e5 = $sx[0]->bar->children()->bing; | |
$f5 = $sx[0]->bar[0]->children()->bing; | |
$c6 = $sx->bar->attributes()->baz; | |
$d6 = $sx->bar[0]->attributes()->baz; | |
$e6 = $sx->bar->children()->bing; | |
$f6 = $sx->bar[0]->children()->bing; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment