Friday, September 19, 2014

PHP create XML file

Pragmatically create XML using PHP.

  $xml = "<company>";
  $xml .= "<employee>";
  $xml .= "<id>100</id>";  
  $xml .= "<name>name</name>";
  $xml .= "<email>email</email>";  
  $xml .= "<salary>salary</salary>";    
  $xml .= "</employee>";  
  $xml .= "</company>";
  $xml_obj = new SimpleXMLElement($xml);
  $xml_obj->asXML('public://myfile.xml'); // Drupal file path.


No comments:

Post a Comment