Citation:
<?
class ajaxFluxXML {
    
    protected $dom;
    protected $main;
    protected $elements;
    protected $javascripts;
    
    
    public function __construct($version="1.0",$char="iso-8859-15")
    {
        $this->dom=new DOMDocument($version,$char);
        $main = $this->dom->createElement('main');
        $this->main = $this->dom->appendChild($main);
    }
    
    public function addElement($HTMLid,$HTMLcontenu)
    {
        $elem = $this->dom->createElement('elements');
        $this->elements = $this->main->appendChild($elem);
        $id=$this->dom->createElement('id',$HTMLid);
        $contenu=$this->dom->createElement('contenu',$HTMLcontenu);
        $this->elements->appendChild($id);
        $this->elements->appendChild($contenu);
        $this->elements->appendChild($contenu);
    }
    
    public function addScript($script)
    {
        $java = $this->dom->createElement('javascripts',$script);
        $this->javascripts = $this->main->appendChild($java);
    }
    public function __toString()
    {
        return $this->dom->saveXML(); 
    }
    
    public function setHeader()
    {
        header("Content-Type: text/xml");
    }
}
?>
que j'utilise ainsi:
Citation:
<?
include_once($_SERVER['DOCUMENT_ROOT']."global/lib.inc.php");
$contenu=<<<END
<div>
  Text en <b>HTML</b>
  <textarea>plop</textarea>
</div>
END;
$fluxAjax=new ajaxFluxXML();
$fluxAjax->addElement($_POST['noeuddest'],$contenu);
$fluxAjax->addScript("alert('bonjour');");
$fluxAjax->addScript("alert('bonjour2');");
$fluxAjax->setHeader();
print $fluxAjax;
?>
Et le code javascript qui récupere le DOM: