-
Notifications
You must be signed in to change notification settings - Fork 20
XMLWriter
Thomas Weinert edited this page Aug 19, 2017
·
2 revisions
FluentDOM\XMLWriter
extends XMLWriter with improved namespace support.
Most of it is to work around a bug that adds unnecessary namespace nodes.
public function registerNamespace(string $prefix, string $namespace)
This method registers a namespace on the XMLReader
itself. This allows other methods to resolve prefixes in tag name arguments.
$writer = new FluentDOM\XMLWriter();
$writer->openURI('php://stdout');
$writer->registerNamespace('', 'http://www.sitemaps.org/schemas/sitemap/0.9');
$writer->registerNamespace('video', 'http://www.google.com/schemas/sitemap-video/1.1');
$writer->setIndent(2);
$writer->startDocument();
$writer->startElement('urlset');
$writer->writeAttribute('xmlns:video', 'http://www.google.com/schemas/sitemap-video/1.1');
foreach ($videos as $video) {
$writer->startElement('url');
$writer->writeElement('loc', $video['url']);
$writer->startElement('video:video');
$writer->writeElement('video:title', $video['title']);
$writer->endElement();
$writer->endElement();
}
$writer->endElement();
$writer->endDocument();
public function collapse(\DOMNode|\Traversable|array $nodes, int $maximumDepth = 1000)
This method allows you to write a DOM node or a list of DOM nodes into the XMLWriter output.
In some regard it is the opposite of XMLReader::expand()
.
The second argument allows to limit the recursion depth.
- Home
- Getting Started
- Tasks
- Plugins
- Functions
- Lists
- Creator (5.1)
- CSS Selectors
- Convertors
- Loaders
- Serializers (5.1)
- Transformers (5.1)
- Extended DOM
- XMLReader (6.1)
- XMLWriter (6.1)
- Interfaces