Posted By

hejaaa on 12/05/10


Tagged

xml simplexml


Versions (?)

addChild and attribute with simpleXml


 / Published in: PHP
 

  1. <?php
  2. header('Content-type: text/xml');
  3.  
  4. // first <winner id="1" /> node
  5. $xml =
  6. '<win visit="0">
  7. <winner id="1" />
  8. </win>';
  9. $xml = simplexml_load_string($xml);
  10.  
  11. // second node
  12. $newNode = $xml->addChild("winner");
  13. $newNode->addAttribute("id","2");
  14.  
  15. // three node
  16. $newNode = $xml->addChild("winner");
  17. $newNode->addAttribute("id","3");
  18.  
  19. echo $xml->asXML();
  20. ?>
  21.  
  22. // RESULT
  23. <win visit="0">
  24. <winner id="1"/>
  25. <winner id="2"/>
  26. <winner id="3"/>
  27. </win>

Report this snippet  

Comments

RSS Icon Subscribe to comments
Posted By: hejaaa on December 5, 2010

in firefox view result from CTRL+U, in Opera is no problem show result without shortcut:)

You need to login to post a comment.