我的XML格式如下:
<?xml version="1.0" encoding="utf-8"?>
<Partners Default="123">
<PID id="123" Value="Kell Partners" DefGID="345">
<GID id="345" Country="US" Value="3.5% + $0.35/transaction + $0/month" Default="True"></GID>
<GID id="455" Country="US" Value="3.5% + $0.35/transaction + $0/month"></GID>
<GID id="789" Country="US" Value="3.5% + $0.35/transaction + $0/month"></GID>
<GID id="159" Country="EU" Value="3.5% + $0.35/transaction + $0/month" Default="True"></GID>
</PID>
<PID id="456" Value="Test Company 2" DefGID="224">
<GID id="222" Country="CA" Value="3.5% + $0.35/transaction + $0/month" Default="True"></GID>
<GID id="224" Country="CA" Value="3.5% + $0.35/transaction + $0/month"></GID>
<GID id="225" Country="UK" Value="3.5% + $0.35/transaction + $0/month"></GID>
<GID id="226" Country="UK" Value="3.5% + $0.35/transaction + $0/month" Default="True"></GID>
</PID>
</Partners>
我使用下面的代码片段来读取PHP中的xml数据,其中My xml将父节点显示为@attributes。
<?php
$xmlparser=simplexml_load_file("partners.xml") or die("Cannot open the file.");
echo "<pre>";
print_r($xmlparser->attributes());
?>
在上面的问题中,我想阅读
从合作伙伴节点默认。我无法通过使用上述代码阅读..
并使用Default i将获取子节点数据。
答案 0 :(得分:0)
<?php
$xml=simplexml_load_file("partners.xml") or die("Cannot open the file.");
echo "<pre>";
foreach($xml->children() as $child) {
foreach($child as $value) {
print_r($value->children());
}
}
echo "</pre>";
?>
通过此代码,您可以获取GID
个节点的数据。要获得它,您不必获得合作伙伴默认值。