Michael Fesser wrote:
.oO(Chuck Anderson)
>Maybe I shouldn't use this thread to ask this question , but ......
I'm confused by the '@' notation on @attributes in a SimpleXMLElement
Object.
I can find no documentation explaining what it means or how it got there.
I may be wrong, but I don't think it has any special meaning. Remember
that SimpleXML is written in C and not limited to what the PHP parser
accepts. Since '@attributes' only seem to appear once in the SimpleXML
source code, I think it's just a naming convention, perhaps following
the XPath syntax for accessing attributes.
>Can anyone explain? And how would I create a member like this in an
object I create?
Not directly, because the parser wouldn't allow it. But there are other
ways to define and access class members of almost arbitrary names if you
have to, e.g.
<?php
$foo = new StdClass();
$bar = '@attributes';
$foo->$bar = 'something';
var_dump($foo);
?>
Micha
Okay, thanks for the explanation. What confused me is when using
SimpleXML, I can not access "@attributes" like the other object members.
When I do a print_r of a SimpleXMLElement Object, attributes are listed
(along with children) this way:
[node1] SimpleXMLElement Object
(
[@attributes] =array
(
['attribname'] =attribvalue
)
[child1] =child1value
[child2] =child2value
}
I only can access the value of the attribute "attribname" by either:
$value = node1['attribname']
.... which bypasses the array it appears to be in (@attributes). ??
or
$attribs = node1->attributes();
$value = $attribs['attribname']
.... using the object method, attributes().
--
*****************************
Chuck Anderson • Boulder, CO
http://www.CycleTourist.com
Nothing he's got he really needs
Twenty first century schizoid man.
***********************************