Php simplexml\u加载\u字符串松散数据
我目前正在使用file\u get\u contents获取xml。 它工作得很好,当我用正确的MIME类型标题('Content-type:text/xml')显示xml时,我得到如下结果:Php simplexml\u加载\u字符串松散数据,php,xml,simplexml,Php,Xml,Simplexml,我目前正在使用file\u get\u contents获取xml。 它工作得很好,当我用正确的MIME类型标题('Content-type:text/xml')显示xml时,我得到如下结果: <?xml version="1.0" encoding="iso-8859-1" ?> <tarification compagnie="banane" cle="laclef"> <gamme reference="equilibre-sante"> &
<?xml version="1.0" encoding="iso-8859-1" ?>
<tarification compagnie="banane" cle="laclef">
<gamme reference="equilibre-sante">
<tarif formule="f100">Xx.xx</tarif>
<tarif formule="f200">Xx.xx</tarif>
</gamme>
</tarification>
SimpleXMLElement Object
(
[@attributes] => Array
(
[compagnie] => banane
[cle] => laclef
)
[gamme] => Array
(
[0] => SimpleXMLElement Object
(
[@attributes] => Array
(
[reference] => equilibre-sante
)
[tarif] => Array
(
[0] => Xx.xx
[1] => Xx.xx
)
)
)
)
我想获取公式属性,我已经按照此操作进行了测试,但没有成功。您需要使用as:
支持此答案。出于某种原因,var_转储不会显示XML元素的属性。这是为什么?@codaddict谢谢你的帮助如果你知道属性的密钥,有没有更直接的方法来获取属性?在上一节课上,我看到一个例子使用了类似于
$xml->attributes(“gd”,1)的东西代码>但是我没有找到任何关于这个的文档。
$xml = simplexml_load_string($xmlstring);
foreach($xml->gamme->tarif as $tarif) {
foreach($tarif->attributes() as $a => $b) {
echo $a,'="',$b,"\"\n";
}
}