Hi,
It seems that var_dump() of a SimpleXMLElement does not show an
attribute of elements that contain text content?
I hope my examples might show what I mean:
$xml = '<root rootattr="root value"><inner attr="value"/></root>';
$simple = new SimpleXMLElement($xml);
var_dump($simple);
echo $simple->asXML();
This results in:
object(SimpleXMLElement)#1 (2) {
["@attributes"]=>
array(1) {
["rootattr"]=>
string(10) "root value"
}
["inner"]=>
object(SimpleXMLElement)#2 (1) {
["@attributes"]=>
array(1) {
["attr"]=>
string(5) "value"
}
}
}
<?xml version="1.0"?>
<root rootattr="root value"><inner attr="value"/></root>
...and that's fine, though it would have been nice to also know that the
root element is called "root".
The second example manifests the weirdness:
$xml = '<root rootattr="root value"><inner
attr="value">text</inner></root>';
$simple = new SimpleXMLElement($xml);
var_dump($simple);
echo $simple->asXML();
Outputs:
object(SimpleXMLElement)#1 (2) {
["@attributes"]=>
array(1) {
["rootattr"]=>
string(10) "root value"
}
["inner"]=>
string(4) "text"
}
<?xml version="1.0"?>
<root rootattr="root value"><inner attr="value">text</inner></root>
Notice that the attribute "attr" of the element "inner" is not displayed.
In the third case, I replace the content of the "inner" element with
another element:
$xml = '<root rootattr="root value"><inner
attr="value"><deep/></inner></root>';
$simple = new SimpleXMLElement($xml);
var_dump($simple);
echo $simple->asXML();
Outputs:
object(SimpleXMLElement)#1 (2) {
["@attributes"]=>
array(1) {
["rootattr"]=>
string(10) "root value"
}
["inner"]=>
object(SimpleXMLElement)#2 (2) {
["@attributes"]=>
array(1) {
["attr"]=>
string(5) "value"
}
["deep"]=>
object(SimpleXMLElement)#3 (0) {
}
}
}
<?xml version="1.0"?>
<root rootattr="root value"><inner attr="value"><deep/></inner></root>
The "invisible" attributes are still accessible with xpath(), etc (the
asXML() dump shows that it is still present, but just not visible. This
might be a bug? Or am I just not understanding something?
Cheers,
Mattias
PHP 5.2.6
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php