値を持つxmlフィールド$xmlstring
があります。
'<result>
<customerAccount xmlns="http://www.ibm.com>
<AccountStatus xmlns="">Due</AccountStatus>
<ComponentCustomerAccount xmlns="">
<Name>ADSL</Name>
<CharacteristicValue>
<Characteristic>
<Name>Balance</Name>
</Characteristic>
<Value>0.0</Value>
</CharacteristicValue>
<CharacteristicValue>
<Characteristic>
<Name>Date</Name>
</Characteristic>
<Value>21.10.1990</Value>
</CharacteristicValue>
<AccountStatus>Active</AccountStatus>
</ComponentCustomerAccount>
<ComponentCustomerAccount xmlns="">
<Name>IPTV</Name>
<CharacteristicValue>
<Characteristic>
<Name>Balance</Name>
</Characteristic>
<Value>100</Value>
</CharacteristicValue>
<CharacteristicValue>
<Characteristic>
<Name>Date</Name>
</Characteristic>
<Value>21.10.1990</Value>
</CharacteristicValue>
<AccountStatus>Active</AccountStatus>
</ComponentCustomerAccount>
</customerAccount>
</result>';
テーブル内の HTML フィールドに表示したい:
NAME STATUS VALUE
ADSL ACTIVE 0.0
IPTV ACTIVE 100
ご覧のとおり、繰り返している要素がいくつかあります。ComponentCustomerAccount は繰り返され、複数の要素を持つことができます。最初の AccountStatus 要素は必要ありませんが、ComponentCustomerAccount 内に AccountStatus 要素が必要です。また、ComponentCustomerAccount 要素内の最初の要素 Name が必要です。
$xml = new SimpleXMLElement($xmlString);
$html = "<table>";
$html .= "<tr><th>Account Name</th><th>Status</th><th>Amount</th></tr>";
foreach($xml->customerAccount as $cust) {
$html .= "<tr><th>" . $cust->Name .
"</th><th>" . $cust->AccountStatus. "</th><th>" . $cust->Value . "</th></tr>";
}
$html .= "</table>";
しかし、空白の出力が得られます。何を変更する必要がありますか? ありがとうございました