PHP で XML に新しい要素を追加するときに属性を設定するにはどうすればよいですか。私のPHPコードは次のようなものです:
<?php
$xml = simplexml_load_file ( 'log.xml' );
$movies = $xml->addChild("time");
// add attribut `value` here in tag time
$user = $movies->addChild("user", "");
// add attribut `id` here in tag user
$action = $user->addChild("action","");
// add attribut `value` here in tag action
$action->addChild("table","customers");
$action->addChild("table_id","1");
echo $xml->saveXML( 'log.xml' );
?>
そして、出力を次のようにしたい:
// log.xml
<?xml version="1.0" encoding="utf-8"?>
<log>
<time value="2013-01-10 12:20:01">
<user id="1">
<action value="delete">
<table>customer</table>
<table_id>1</table_id>
</action>
<action value="insert">
<table>customer</table>
<data>
<nama>budi</nama>
</data>
</action>
<action value="update">
<table>customer</table>
<table_id>1</table_id>
<old_data>
<nama>andi</nama>
</old_data>
<new_data>
<nama>budi</nama>
</new_data>
</action>
</user>
</time>
</log>
私を助けてください..私はxmlについて非常に新しいです