Repository navigation
Getting Started: 10. Exporting
Daniele Orlando edited this page Feb 21, 2016
·
3 revisions
The document can be exported in multiple ways.
$dom = $book->dom();
Concise syntax
$xml =(string) $book;Extended syntax
$xml = $book->xml();
<?xml version="1.0" encoding="UTF-8"?> <book> ... </book>
The XML declaration can be removed from the output string too.
$xml = $book->xml(true);
<book> ... </book>
Not only the entire document but even only specific nodes (with their content) can be exported.
$xml = $book->query('//chapter')->xml();
<chapter lang="en" first="">Ideas About The Universe</chapter> <chapter lang="en" last="">The Expanding Universe</chapter>
$book->save('book.xml');
As for ->xml(), the output document can be saved without the XML declaration
$book->save('book.xml', true);
or only specific nodes can be saved.
$book->query('//chapter') ->save('book_chapters.xml');
Saving is fluent too.
$book->save('book.xml') ->save('book_tidy.xml', true) ->query('//chapter') ->save('book_chapters.xml');