我有一个XML字符串,我试图提取儿童标签的名称。每个儿童标签都是自动关闭的。我试图用SimpleXMLElement
XML:PHP只解析一系列的儿童中的第一个
$xml_str = '1<?xml version="1.0" encoding="UTF-8"?><parent><personal_data><child1 attr="sth /><child2 attr=sth2/></personal_data><personal_data><child1 attr="sth /><child2 attr=sth2/></personal_data</parent>';
$sxe = new SimpleXMLElement($xml);
//get the children from the parent
$sxe = $sxe->children();
echo $sxe;
$form_mappers = array();
foreach ($sxe->children() as $child){
array_push($form_mappers, $child->getName());
}
echo var_dump($form_mappers); //only children from the first parent
这仅获得第aParent
节点的孩子。为什么我不能得到第二个孩子的节点?
@Ghost我认为,任何畸形的产物我把一个样本放在一起。这个验证器http://xmlgrid.net/validator.html说我的实际XML是有效的。 – 1252748 2015-02-12 00:10:04
无论如何预期输出是什么? 4个孩子?你需要循环内eeach个人资料 – Ghost 2015-02-12 00:11:04
是啊,四个孩子'child1,child2,child1,child1' – 1252748 2015-02-12 00:12:37