Reading content and children from an XML tag in php -
i have xml tree, have tag
<et> middle english (scots) <it>polit</it> , latin <it>politus,</it> past participle of <it>polire</it> </et> i want read content of et, , put words in <it> in italics. can read direct text inside et , not children. php code
this puts words in <it> $itarray:
$myxmldata = "<?xml version='1.0' encoding='utf-8'?> <et> middle english (scots) <it>polit</it> , latin <it>politus,</it> past participle of <it>polire</it> </et>"; $xml=simplexml_load_string($myxmldata) or die("error: cannot create object"); $itarray = array(); foreach($xml->it $it){ array_push($itarray, $it); } print($itarray[0]); // polit print($itarray[1]); // politus print($itarray[2]); // polire i'm not sure want <et>, prints out of <et> content:
$xml= new simplexmlelement($myxmldata); $xml->asxml(); print($xml); edit: i'll assume you'll want put content in <et> in array well. since xml messed up, you'll have use regex.
hope i've helped.
Comments
Post a Comment