SimpleXMl problem HELP please
Posted: Thu Jan 22, 2009 4:15 am
Hers is an example:
<?php
$xmlstr = <<<XML
<?xml version='1.0' standalone='yes'?>
<movies>
<movie>
<title>CSS</title>
<name>Mr. Coder</name>
<actor>El ActÓr</actor>
<plot>
So, this language. It\'s like, a programming language. Or is it a
scripting language? All is revealed in this thrilling horror spoof
of a documentary.
</plot>
<rating type="thumbs">7</rating>
<rating type="stars">5</rating>
</movie>
<movie>
<title>java</title>
<name>Ms. Coder</name>
<actor>Onlivia Actora</actor>
<plot>
So, this language. It\'s like, a programming language. Or is it a
scripting language? All is revealed in this thrilling horror spoof
of a documentary.
</plot>
<rating type="thumbs">7</rating>
<rating type="stars">5</rating>
</movie>
</movies>
XML;
$xml = new SimpleXMLElement($xmlstr);
echo('<pre>');
var_dump($xml->movie);
echo('<br/>');
echo('</pre>');
?>
In this situation, it will print out the structure of the first movie. but if you change to var_dump($xml->movie[0]), it will also print out the first movie.
now, if I change to this :foreach ($xml->movie as $movie) {var_dump($movie);} it will output both movies.
So, my question is what on earth $xml->movie refer to? the first movie or the nodelist of 2 movies? Thanks
<?php
$xmlstr = <<<XML
<?xml version='1.0' standalone='yes'?>
<movies>
<movie>
<title>CSS</title>
<name>Mr. Coder</name>
<actor>El ActÓr</actor>
<plot>
So, this language. It\'s like, a programming language. Or is it a
scripting language? All is revealed in this thrilling horror spoof
of a documentary.
</plot>
<rating type="thumbs">7</rating>
<rating type="stars">5</rating>
</movie>
<movie>
<title>java</title>
<name>Ms. Coder</name>
<actor>Onlivia Actora</actor>
<plot>
So, this language. It\'s like, a programming language. Or is it a
scripting language? All is revealed in this thrilling horror spoof
of a documentary.
</plot>
<rating type="thumbs">7</rating>
<rating type="stars">5</rating>
</movie>
</movies>
XML;
$xml = new SimpleXMLElement($xmlstr);
echo('<pre>');
var_dump($xml->movie);
echo('<br/>');
echo('</pre>');
?>
In this situation, it will print out the structure of the first movie. but if you change to var_dump($xml->movie[0]), it will also print out the first movie.
now, if I change to this :foreach ($xml->movie as $movie) {var_dump($movie);} it will output both movies.
So, my question is what on earth $xml->movie refer to? the first movie or the nodelist of 2 movies? Thanks