X
<?php
$xw = New xmlWriter(); // Neues xmlWriter Objekt
$xw->openMemory(); // Oeffnen eines XML-Dokuments im Speicher
$xw->setIndent(TRUE); // sieht einfach besser aus ;-)
$xw->startDocument(); // start document
$xw->startElement("book"); // start <book>
$xw->writeElement('title', 'Titel des Test-Books'); // <title> with content
$xw->startElement("chapter"); // start <chapter>
$xw->writeAttribute("id", 1); // add attribute to example
$xw->writeElement('title', 'Titel des Test-Chapters'); // <title> with content
$xw->startElement("para"); // add node <para>
$xw->text("irgendein Text"); // add content to node <data>
$xw->endElement(); // close node <para>
$xw->endElement(); // close node <chapter>
$xw->endElement(); // close node <book>
$xw->endDocument(); // end document
echo $xw->outputMemory(); // Ausgabe des erzeugten XML
?>
X
<?xml version="1.0"?> <book> <title>Titel des Test-Books</title> <chapter id="1"> <title>Titel des Test-Chapters</title> <para>irgendein Text</para> </chapter> </book>