davidannis Posted March 8, 2014 Share Posted March 8, 2014 I am trying to get the names of the children nodes in XML Here is the code: foreach ($pos->children() as $child) { echo "I never get here"; echo $child->getName() . "\n"; } //} echo "but the node has children---<br>"; print_r($pos); which I modeled on the code from http://www.php.net/manual/en/simplexmlelement.getname.php and here is a sample of the output: SimpleXMLElement Object ( [n] => SimpleXMLElement Object ( ) ) but the node has children--- SimpleXMLElement Object ( [int] => SimpleXMLElement Object ( ) ) but the node has children--- SimpleXMLElement Object ( [n] => SimpleXMLElement Object ( ) ) Why can't I go through the chldren with foreach? Quote Link to comment Share on other sites More sharing options...
requinix Posted March 9, 2014 Share Posted March 9, 2014 What's the source XML? Quote Link to comment Share on other sites More sharing options...
davidannis Posted March 9, 2014 Author Share Posted March 9, 2014 The source XML is huge but here's a sample: <entry> <ent_seq>1000320</ent_seq> <k_ele> <keb>彼処</keb> <ke_pri>ichi1</ke_pri> </k_ele> <k_ele> <keb>彼所</keb> </k_ele> <r_ele> <reb>あそこ</reb> <re_pri>ichi1</re_pri> </r_ele> <r_ele> <reb>あすこ</reb> </r_ele> <r_ele> <reb>かしこ</reb> </r_ele> <r_ele> <reb>あしこ</reb> <re_inf>&ok;</re_inf> </r_ele> <r_ele> <reb>あこ</reb> <re_inf>&ok;</re_inf> </r_ele> <sense> <pos>&pn;</pos> <pos>&adj-no;</pos> <xref>何処</xref> <xref>此処</xref> <xref>其処</xref> <misc>&uk;</misc> <gloss>there (place physically distant from both speaker and listener)</gloss> <gloss>over there</gloss> <gloss>that place</gloss> <gloss>yonder</gloss> </sense> <sense> <stagr>あそこ</stagr> <stagr>あすこ</stagr> <pos>&n;</pos> <misc>&col;</misc> <gloss>genitals</gloss> </sense> <sense> <xref>あれほど</xref> <gloss>that far (something psychologically distant from both speaker and listener)</gloss> <gloss>that much</gloss> <gloss>that point</gloss> </sense> </entry> <entry> <ent_seq>1000360</ent_seq> <r_ele> <reb>あっさり</reb> <re_pri>ichi1</re_pri> </r_ele> <info> <audit> <upd_date>2012-08-04</upd_date> <upd_detl>Entry created</upd_detl> </audit> <audit> <upd_date>2012-08-04</upd_date> <upd_detl>Entry amended</upd_detl> </audit> </info> <sense> <pos>&adv-to;</pos> <pos>&vs;</pos> <misc>&on-mim;</misc> <gloss>easily</gloss> <gloss>readily</gloss> <gloss>quickly</gloss> </sense> <sense> <misc>&on-mim;</misc> <gloss>lightly (flavored food, applied makeup)</gloss> </sense> </entry> Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.