SimpleXML returns attribute values as SimpleXMLElement objects instead
of strings. E.g, given this:
$sxe = simplexml_load_string('<octopus arms="eight" legs="">Doc
Ock</octopus>');
$sxe['arms'] and $sxe['legs'] are SimpleXMLElement objects.
This mostly works OK, but causes problems when using empty() to test if
an attribute has a value. empty($sxe['arms']) is false, but so is
empty($sxe['legs']).
An easy workaround is to use strlen()
instead of empty(), I suppose
(except if an attribute value is "0"), but I am wondering why SimpleXML
works this way.
Thanks,
David
iterators...
SimpleXML returns attribute values as SimpleXMLElement objects instead
of strings. E.g, given this:$sxe = simplexml_load_string('<octopus arms="eight" legs="">Doc
Ock</octopus>');$sxe['arms'] and $sxe['legs'] are SimpleXMLElement objects.
This mostly works OK, but causes problems when using empty() to test if
an attribute has a value. empty($sxe['arms']) is false, but so is
empty($sxe['legs']).An easy workaround is to use
strlen()
instead of empty(), I suppose
(except if an attribute value is "0"), but I am wondering why SimpleXML
works this way.Thanks,
David
Ahh. Thanks.
David
Sterling Hughes wrote:
iterators...
SimpleXML returns attribute values as SimpleXMLElement objects instead
of strings. E.g, given this:$sxe = simplexml_load_string('<octopus arms="eight" legs="">Doc
Ock</octopus>');$sxe['arms'] and $sxe['legs'] are SimpleXMLElement objects.
This mostly works OK, but causes problems when using empty() to test if
an attribute has a value. empty($sxe['arms']) is false, but so is
empty($sxe['legs']).An easy workaround is to use
strlen()
instead of empty(), I suppose
(except if an attribute value is "0"), but I am wondering why SimpleXML
works this way.Thanks,
David