Skip to content

Instantly share code, notes, and snippets.

@enlacee
Created February 8, 2013 23:30
Show Gist options
  • Save enlacee/4742832 to your computer and use it in GitHub Desktop.
Save enlacee/4742832 to your computer and use it in GitHub Desktop.
Generar XML para almacenar en una base de datos relacional
<?php
$xml = new DOMDocument('1.0','UTF-8');
$lms = $xml->createElement('data');
$xml->appendChild($lms);
//id
$id = $xml->createElement('id','6699');
$lms->appendChild($id);
//data
$data =$xml->createElement('data-person');
$lms->appendChild($data);
$person = $xml->createElement('person');
$data->appendChild($person);
//person
$first_name = $xml->createElement('first-name','Victor Anibal');
$person->appendChild($first_name);
$second_name = $xml->createElement('second-name','Copitan Norabuena');
$person->appendChild($second_name);
//driver
$driver = $xml->createElement('driver');
$person->appendChild($driver);
$driver_licence = $xml->createElement('licence','12345678912');
$driver->appendChild($driver_licence);
$driver_eyear = $xml->createElement('experience-year','2');
$driver->appendChild($driver_eyear);
$driver_emonth = $xml->createElement('experience-month','3');
$driver->appendChild($driver_emonth);
//vehicles
$vehicle = $xml->createElement('vehicle');
$person->appendChild($vehicle);
$vehicle_year = $xml->createElement('year','2009');
$vehicle->appendChild($vehicle_year);
$vehicle_make = $xml->createElement('make','US');
$vehicle->appendChild($vehicle_make);
$vehicle_model = $xml->createElement('model','VMX');
$vehicle->appendChild($vehicle_model);
var_dump($first_name);
$xml->formatOutput = true;
$string_xml = $xml->saveXML();
$xml->save('php-xml.xml');
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment