我的最终解决方案基于@dimitre-novatchev 的出色创意提案:
$res = $xpath->query("//form//div/@xmltag"); // OBS: xmltag not xmlTag
$total_fields = $res->length;
for ($i = 1; $i <= $total_fields; $i ++ )
{
$r = $xpath->query("//form//div[$i]/@xmltag");
$xmltag = $r->item(0)->value;
$r = $xpath->query("//form//div[$i]/@controltype");
$controltype = $r->item(0)->value;
$div[$i - 1] = array(
'xmltag' => $xmltag,
'controltype' => $controltype
);
}
输出样本:
array (
0 =>
array (
'xmltag' => 'Case_Number',
'controltype' => '',
),
1 =>
array (
'xmltag' => 'Plaintiff',
'controltype' => 'RadioButtons',
),
2 =>
array (
'xmltag' => 'Plaintiff_Name',
'controltype' => '',
),
美丽的!