title: simple xml add attribute
body: <p>How can I set attributes when I add new elements in XML with PHP. My PHP code is like this:   </p>
  
  <pre><code> &lt;?php
       $xml = simplexml_load_file ( 'log.xml' );
  
       $movies = $xml-&gt;addChild("time");
        // add attribut `value` here in tag time
  
       $user = $movies-&gt;addChild("user", "");
       // add attribut `id` here in tag user
  
       $action = $user-&gt;addChild("action","");
       // add attribut `value` here in tag action
  
       $action-&gt;addChild("table","customers");
  
       $action-&gt;addChild("table_id","1");
  
       echo $xml-&gt;saveXML( 'log.xml' );
   ?&gt;
  </code></pre>
  
  <p>And I want output to look like this:</p>
  
  <pre><code>// log.xml
  &lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;log&gt;
  &lt;time value="2013-01-10 12:20:01"&gt;
      &lt;user id="1"&gt;
          &lt;action value="delete"&gt;
              &lt;table&gt;customer&lt;/table&gt;
              &lt;table_id&gt;1&lt;/table_id&gt;
          &lt;/action&gt;   
          &lt;action value="insert"&gt;
              &lt;table&gt;customer&lt;/table&gt;
              &lt;data&gt;
                  &lt;nama&gt;budi&lt;/nama&gt;
              &lt;/data&gt;
          &lt;/action&gt;
          &lt;action value="update"&gt;
              &lt;table&gt;customer&lt;/table&gt;
              &lt;table_id&gt;1&lt;/table_id&gt;
              &lt;old_data&gt;
                  &lt;nama&gt;andi&lt;/nama&gt;
              &lt;/old_data&gt;
              &lt;new_data&gt;
                  &lt;nama&gt;budi&lt;/nama&gt;
              &lt;/new_data&gt;
          &lt;/action&gt;
      &lt;/user&gt;
  &lt;/time&gt;
  &lt;/log&gt;
  </code></pre>
  
  <p>please help me..i am very new about xml</p>