Skip to content

Instantly share code, notes, and snippets.

@perseoq
Created January 13, 2016 16:04
Show Gist options
  • Save perseoq/fda41ca39ad95167afdd to your computer and use it in GitHub Desktop.
Save perseoq/fda41ca39ad95167afdd to your computer and use it in GitHub Desktop.
Crear un archivo XML con CDATA con PHP
<?php
class SimpleXMLExtended extends SimpleXMLElement {
public function addCDATA($cData) {
$node = dom_import_simplexml($this);
$node->formatOutput = true;
$no = $node->ownerDocument;
$node->appendChild($no->createCDATASection($cData));
}
}
$get_num = $_POST['numero'];
$get_tit = $_POST['titulos'];
$get_cap = $_POST['capitulos'];
$get_secc = $_POST['secciones'];
$get_atrib = $_POST['editor1'];
$dicc = new SimpleXMLExtended('datagrid.xml', null, true);
$nodo = $dicc->addChild('articulo');
$path = $nodo->addChild('atributo');
$path->addCDATA(html_entity_decode($get_atrib));
$nodo->addChild('numero',$get_num);
$nodo->addChild('titulo',$get_tit);
$nodo->addChild('capitulo',$get_cap);
$nodo->addChild('seccion',$get_secc);
$dicc->asXML('datagrid.xml');
header('location: index.php');
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment