note 91227 deleted from simplexml.examples-basic by danbrown
| From: | danbrown@php.net | Date: | Mon, 01 Jun 2009 13:07:03 +0000 |
| Subject: | note 91227 deleted from simplexml.examples-basic by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-156252@lists.php.net to get a copy of this message | ||
Note Submitter: nightblade
----
@radams: Personally I think it is simpler to check if an element exists by using isset().
<?php
$xml = <<<EOT
<?xml version='1.0' standalone='yes'?>
<root>
<test1></test1>
<test2 />
<test4> </test4>
</root>
EOT;
$xmlDoc = new SimpleXMLElement($xml);
echo isset($xmlDoc->test1) ? "true" : "false"; //true
echo isset($xmlDoc->test2) ? "true" : "false"; //true
echo isset($xmlDoc->test3) ? "true" : "false"; //false
echo isset($xmlDoc->test4) ? "true" : "false"; //true
?>
Excuse lack of formatting in output, just makes code look nicer.