note 94296 added to class.simplexmlelement

From: Date: Wed, 28 Oct 2009 00:53:34 +0000
Subject: note 94296 added to class.simplexmlelement
Groups: php.notes 
Request: Send a blank email to php-notes+get-162165@lists.php.net to get a copy of this message
Figuring out how to access the properties of a SimpleXmlElement object was a little tricky for me. In particular, it took a while to discover that I needed to cast my SimpleXmlElement properties to be of type "string" to print them or do comparisons on them. For instance, assuming you already have a string of xml in $xmlstr... <?php $sxml= new SimpleXmlElement($xmlstr); if ((string) $sxml->property== "somevalue") { echo (string) $sxml->property; } ?> The properties of a SimpleXmlElement object are objects themselves, so you need to put "(string)" before them, which casts their values to a string instead of an object. I assume if you were doing a numeric comparison you'd want to cast to an (int) or something numeric instead. ---- Server IP: 208.69.120.35 Probable Submitter: 75.164.62.144 ---- Manual Page -- http://www.php.net/manual/en/class.simplexmlelement.php Edit -- https://master.php.net/note/edit/94296 Del: integrated -- https://master.php.net/note/delete/94296/integrated Del: useless -- https://master.php.net/note/delete/94296/useless Del: bad code -- https://master.php.net/note/delete/94296/bad+code Del: spam -- https://master.php.net/note/delete/94296/spam Del: non-english -- https://master.php.net/note/delete/94296/non-english Del: in docs -- https://master.php.net/note/delete/94296/in+docs Del: other reasons-- https://master.php.net/note/delete/94296 Reject -- https://master.php.net/note/reject/94296 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#162165) next »