Overview
KB
Technical FAQ
PHP Manual
CSS2 Manual
HTML Manual
JS Guide
JS Reference
PhpDock Manual
Nu-Coder Manual
PhpExpress Manual
PHP Joomla
Development
Learn PHP
 
<Working with XML namespacesXMLWriter>
^ExamplesLast updated: Mon, 26 Oct 2026

Working with the OO API

This example shows how to work with XMLWriter's object-oriented API.

Example #1 Working with the OO API

<?php

$xw = new XMLWriter();
$xw->openMemory();
$xw->startDocument("1.0");
$xw->startElement("book");
$xw->text("example");
$xw->endElement();
$xw->endDocument();
echo $xw->outputMemory();

The above example will output:

<?xml version="1.0"?>
<book>example</book>


<Working with XML namespacesXMLWriter>
^ExamplesLast updated: Mon, 26 Oct 2026