How do I save an XML file with Laravel?

0

I'm trying to save the xml file with laravel but I can not do it

        $xml = new \DomDocument('1.0', 'UTF-8');

        $raiz = $xml->createElement('raiz');
        $raiz = $xml->appendChild($raiz);

        $nodo = $xml->createElement('Grafico');
        $nodo = $raiz->appendChild($nodo);

        $subnodo = $xml->createElement('item','texto dentro del item');
        $subnodo = $nodo->appendChild($subnodo);

        $xml->formatOutput = true;
        $xml->saveXML();
        $xml->save('albatros_Web/public/file_XML/archivo.xml');

When I try to save I get the following error

  

DOMDocument :: save (albatros_Web / public / file_XML /): failed to open   stream:       No such file or directory

    
asked by Alejo Florez 17.05.2017 в 22:35
source

1 answer

0

I found the form With simple XML

$xml = new \DomDocument('1.0', 'UTF-8'); //Se crea el docuemnto

// The root of the element is created

$raiz = $xml->createElement('raiz');
$raiz = $xml->appendChild($raiz);

// And nested nodes are created

$nodo_First = $xml->createElement('Grafico');
$nodo_First = $raiz->appendChild($nodo_First);

        /*---------------------------------------------inicio nodo_Second nodo de vector---------------------------------*/

        $nodo_Second = $xml->createElement('options');
        $nodo_Second = $nodo_First->appendChild($nodo_Second);

        /*---------------------------------------------Inicio nodo_Third nodo de atributo--------------------------------*/

        $nodo_Third = $xml->createElement('chart');
        $nodo_Third = $nodo_Second->appendChild($nodo_Third);

        $subnodo = $xml->createElement('type',$requestJSON[$i]->{'options'}->{'chart'}->{'type'}.'');
        $subnodo = $nodo_Third->appendChild($subnodo);

At the end

//Se eliminan espacios en blanco
$xml->preserveWhiteSpace = false;

//Se ingresa formato de salida
$xml->formatOutput = true;

//Se instancia el objeto
$xml_string =$xml->saveXML();

//Y se guarda en el nombre del archivo 'achivo.xml', y el obejto nstanciado
\Storage::disk('local')->put('archivo.xml',$xml_string);

I hope this could help someone

    
answered by 18.05.2017 / 17:12
source