我想显示通过字段名称和值区分文档的 xml 内容,请提供任何帮助。以下是我的 xml 文件内容。
<doc>
<field name="id">1</field>
<field name="name">A</field>
<field name="sk">Acce</field>
<field name="level">Beginner</field>
<field name="do">Tuto</field>
<field name="open">1</field>
<field name="type">Ct</field>
<field name="extensis">cl_ex</field>
<field name="features">Atos</field>
<field name="downl"></field>
<field name="source">AtomicCounters</field>
<field name="description">Ths.</field>
<field name="tag1"></field>
<field name="tag2"></field>
<field name="tag3"></field>
<field name="tag4">Global</field>
<field name="tag5">Atomic</field>
<field name="tag6"></field>
<field name="tag7"></field>
<field name="tag8"></field>
<field name="tag9"></field>
<field name="tag10"></field>
</doc>
<doc>
<field name="id">2</field>
<field name="name">Ar</field>
<field name="sk">Acrce</field>
<field name="level">Beginner</field>
<field name="do">Tuto1</field>
<field name="open">11</field>
<field name="type">C1t</field>
<field name="extensis">cl_exd</field>
<field name="features">Atos</field>
<field name="downl"></field>
<field name="source">ddddd</field>
<field name="description">Thsdd.</field>
<field name="tag1"></field>
<field name="tag2"></field>
<field name="tag3"></field>
<field name="tag4">Global1</field>
<field name="tag5">Atomic1</field>
<field name="tag6"></field>
<field name="tag7"></field>
<field name="tag8"></field>
<field name="tag9"></field>
<field name="tag10"></field>
</doc>
下面是我正在使用的代码..
<?php
$result="";
$document = new DOMDocument();
//$document->load('/wamp/www/amd/261013/test/amd_one.xml');
$document->load('http://localhost/solr/select');
// this will also output doctype and comments at top level
foreach($document->childNodes as $node)
$result[] .= $document->saveXML($node)."\n";
//echo $result[];
foreach($result as $key => $value)
{
echo "$key - $value<br/>";
}
?>
然而,它只是价值......就像1 Ar Acce......
我想要像 $field = id, $value = 1,$field = name, $value = A, $field = id, $value = 2,$field = name, $value = Ar,..
请有任何建议..