i have simplexml object , looks fine, when convert part of it... like: $xmlmeshheading = $meshheading->asxml();
i attributes can't find in simple xml object...? here parts of 2 files:
simplexmlobject: [meshheadinglist] => simplexmlelement object [descriptorname] => acoustic stimulation ( [meshheading] => array ( [0] => simplexmlelement object ( [qualifiername] => methods ) [1] => simplexmlelement object ( [descriptorname] => adolescent ) [2] => simplexmlelement object ( [descriptorname] => age factors ) [3] => simplexmlelement object ( [descriptorname] => child ) [4] => simplexmlelement object ( [descriptorname] => electromyography [qualifiername] => methods ) [5] => simplexmlelement object ( [descriptorname] => female ) [6] => simplexmlelement object ( [descriptorname] => galvanic skin response [qualifiername] => physiology ) [7] => simplexmlelement object ( [descriptorname] => humans ) [8] => simplexmlelement object ( [descriptorname] => male ) [9] => simplexmlelement object ( [descriptorname] => muscle, skeletal [qualifiername] => physiology ) [10] => simplexmlelement object ( [descriptorname] => probability ) [11] => simplexmlelement object ( [descriptorname] => reaction time [qualifiername] => physiology ) [12] => simplexmlelement object ( [descriptorname] => sex factors ) [13] => simplexmlelement object ( [descriptorname] => startle reaction [qualifiername] => physiology )
and here asxml file it's same source...:
<meshheadinglist> <meshheading> <descriptorname majortopicyn="n">acoustic stimulation</descriptorname> <qualifiername majortopicyn="n">methods</qualifiername> </meshheading> <meshheading> <descriptorname majortopicyn="n">adolescent</descriptorname> </meshheading> <meshheading> <descriptorname majortopicyn="n">age factors</descriptorname> </meshheading> <meshheading> <descriptorname majortopicyn="n">child</descriptorname> </meshheading> <meshheading> <descriptorname majortopicyn="n">electromyography</descriptorname> <qualifiername majortopicyn="y">methods</qualifiername> </meshheading> <meshheading> <descriptorname majortopicyn="n">female</descriptorname> </meshheading> <meshheading> <descriptorname majortopicyn="n">galvanic skin response</descriptorname> <qualifiername majortopicyn="n">physiology</qualifiername> </meshheading> <meshheading> <descriptorname majortopicyn="n">humans</descriptorname> </meshheading> <meshheading> <descriptorname majortopicyn="n">male</descriptorname> </meshheading> <meshheading> <descriptorname majortopicyn="n">muscle, skeletal</descriptorname> <qualifiername majortopicyn="y">physiology</qualifiername> </meshheading> <meshheading> <descriptorname majortopicyn="n">probability</descriptorname> </meshheading> <meshheading> <descriptorname majortopicyn="n">reaction time</descriptorname> <qualifiername majortopicyn="n">physiology</qualifiername> </meshheading> <meshheading> <descriptorname majortopicyn="n">sex factors</descriptorname> </meshheading> <meshheading> <descriptorname majortopicyn="n">startle reaction</descriptorname> <qualifiername majortopicyn="y">physiology</qualifiername> </meshheading> </meshheadinglist>
my question is... 1. there function "unhide" attributes in simplexml? or 2. how can stuff xml file, attributes , values...?
best, thijs
yes. attributes returned when accessing specific node. per example:
$xml = new simplexmlelement('<xml><foo bar="baz">hello world</foo></xml>'); print_r($xml);
outputs:
simplexmlelement object ( [foo] => hello world )
while this:
$xml = new simplexmlelement('<xml><foo bar="baz">hello world</foo></xml>'); print_r($xml->foo);
outputs:
simplexmlelement object ( [@attributes] => array ( [bar] => baz ) [0] => hello world )
it's because of internal structure of simplexmlelement
. many built-in objects in php (domdocument, etc.), properties aren't printed out when using print_r
on them. simplexml attributes, print_r
won't display them unless access node, because overload __get
(kind of).
Comments
Post a Comment