SEARCH
0-9 A B C D E F G H I J K L M N O P Q R S T U V W X Y Z
Prev | Current Page 202 | Next

Hasin Hayder

"Object-Oriented Programming with PHP5"

tld
there is no subject
symbols]]>


END;
$sxml = simplexml_load_string($str);
print_r($sxml);
?>
The output is like this:
SimpleXMLElement Object
(
[email] => SimpleXMLElement Object
(
[from] => nowhere@notadomain.tld
[to] => unknown@unknown.tld
[subject] => there is no subject
[body] => SimpleXMLElement Object
( )
)
)
So now you can ask how to access each of these properties individually. You can
access each of them like an object. For example, $sxml->email[0] returns the first
email object. To access the from element under this email, you can use the following
code like:
echo $sxml->email[0]->from
Cooking XML with OOP
[ 198 ]
So, each object, unless available more than once, can be accessed just by its name.
Otherwise you have to access them like a collection. For example, if you have
multiple elements, you can access each of them using a foreach loop:
foreach ($sxml->email as $email)
echo $email->from;
Accessing Attributes
As we saw in the previous example, XML nodes may have attributes. Remember the
example document with class, age, and title? Now you can easily access these
attributes using SimpleXML API.


Pages:
190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214
hotel jelenia góra Russian bride Free English grammar and study guid powiekszenia wielkoformatowe counter strike 1.6