Last active
March 15, 2018 13:48
-
-
Save bluvertigo/71dd2e62a9f92b5524cf5c5cae7f5d96 to your computer and use it in GitHub Desktop.
Gestione XML con PHP
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php function SingoloXml() | |
{ | |
$doc = new DOMDocument; | |
$l1 = $doc->createElement("L1"); | |
$l2 = $doc->createElement("L2"); | |
$l1->appendChild($l2); | |
$doc->appendChild($l1); | |
return $doc->documentElement; | |
// per poi appendere all'altro nodo | |
} | |
function GeneraXML($list) | |
{ | |
$doc = new DOMDocument; | |
$nodo = $doc->createElement("nodo"); | |
$xmlnsAttribute = $doc->createAttribute('xmlns'); | |
$xmlnsAttribute->value = 'test'; | |
$nodo->appendChild($xmlnsAttribute); | |
$nodo_2 = $doc->createElement('nodo_2'); | |
foreach ($list as $order) { | |
$tempNodo = $doc->importNode($this->SingoloXml(), true); | |
$nodo_2->appendChild($tempNodo); | |
} | |
$nodo->appendChild($nodo_2); | |
$doc->appendChild($nodo); | |
return $doc->saveXml($doc->documentElement); | |
// fatto così per non caricare la parte iniziale dell'xML | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment