SimpleXMLElement no built-in properties that allow you to talk about this separately.
As others suggested dom_import_simplexml , it may be advisable, however, that a function can change nodes on the fly sometimes, for example, if you go to the list of child nodes or named child nodes, it will take them and turn them into the first element.
If this is an empty list, for example, no attributes returned from attributes() or nonexistent named child nodes, it will warn you that you were given an invalid node type:
Warning: dom_import_simplexml (): invalid Nodetype type for import
So, if you need this precision with snappy boolean true / false , here is how it works with Simplexml:
$isElement = $element->xpath('.') == array($element); $isAttribute = $element[0] == $element and $element->xpath('.') != array($element);
It works similar to attribute lists and element lists, I just wrote about it in the morning , you need to have some knowledge about what to evaluate for what, so I created a cheat sheet for it:
+------------------+---------------------------------------------+ | TYPE | TEST | +------------------+---------------------------------------------+ | Element | $element->xpath('.') == array($element) | +------------------+---------------------------------------------+ | Attribute | $element[0] == $element | | | and $element->xpath('.') != array($element) | +------------------+---------------------------------------------+ | Attributes | $element->attributes() === NULL | +------------------+---------------------------------------------+ | Elements | $element[0] != $element | | | and $element->attributes() !== NULL | +------------------+---------------------------------------------+ | Single | $element[0] == $element | +------------------+---------------------------------------------+ | Empty List | $element[0] == NULL | +------------------+---------------------------------------------+ | Document Element | $element->xpath('/*') == array($element) | +------------------+---------------------------------------------+
hakre Feb 12 '13 at 9:29 2013-02-12 09:29
source share