Fix errors and add "Comparing Elements and Attributes with Text" section.

git-svn-id: https://svn.php.net/repository/phpdoc/en/trunk@153313 c90b9560-bf6c-de11-be94-00142212c4b1
This commit is contained in:
Adam Trachtenberg 2004-03-10 06:33:25 +00:00
parent 34f8696231
commit 368c38958e

View file

@ -1,5 +1,5 @@
<?xml version="1.0" encoding="iso-8859-1"?>
<!-- $Revision: 1.8 $ -->
<!-- $Revision: 1.9 $ -->
<reference id="ref.simplexml">
<title>SimpleXML functions</title>
<titleabbrev>SimpleXML</titleabbrev>
@ -51,7 +51,7 @@ $xmlstr = <<<XML
</character>
<character>
<name>Mr. Coder</name>
<actor>El Act&oacute;r</actor>
<actor>El Act&#211;r</actor>
</character>
</characters>
<plot>
@ -128,7 +128,7 @@ $xml = simplexml_load_string($xmlstr);
/* Access the <rating> nodes of the first movie.
* Output the rating scale, too. */
foreach ($xml->movie[0]->rating as $rating) {
switch($rating['type']) { // Get attributes as element indices
switch((string) $rating['type']) { // Get attributes as element indices
case 'thumbs':
echo $rating, ' thumbs up';
break;
@ -138,6 +138,28 @@ foreach ($xml->movie[0]->rating as $rating) {
}
}
?>
]]>
</programlisting>
</example>
</para>
<para>
<example>
<title>Comparing Elements and Attributes with Text</title>
<simpara>
To compare an element with a string or pass it into a
function, you must cast it to a string using <literal>(string)</literal>.
Otherwise, PHP treats the element as an object.
</simpara>
<programlisting role="php"><![CDATA[
<?php
include 'example.php';
$xml = simplexml_load_string($xmlstr);
if ((string) $xml->movie->title == 'PHP: Behind the Parser') {
print 'My favorite movie.';
}
?>
]]>
</programlisting>
</example>