--- /dev/null
+--TEST--
+XMLWriter: libxml2 XML Writer, file buffer, flush
+--SKIPIF--
+<?php if (!extension_loaded("xmlwriter")) print "skip"; ?>
+--FILE--
+<?php
+/* $Id$ */
+
+$doc_dest = '001.xml';
+$xw = xmlwriter_open_uri($doc_dest);
+xmlwriter_start_document($xw, '1.0', 'utf8');
+xmlwriter_start_element($xw, "tag1");
+xmlwriter_end_document($xw);
+
+// Force to write and empty the buffer
+$output_bytes = xmlwriter_flush($xw, true);
+echo file_get_contents($doc_dest);
+unlink('001.xml');
+echo "---Done---\n";
+?>
+--EXPECT--
+<?xml version="1.0" encoding="utf8"?>
+<tag1/>
+---Done---
--- /dev/null
+--TEST--
+XMLWriter: libxml2 XML Writer, membuffer, flush
+--SKIPIF--
+<?php if (!extension_loaded("xmlwriter")) print "skip"; ?>
+--FILE--
+<?php
+/* $Id$ */
+
+$doc_dest = '001.xml';
+$xw = xmlwriter_open_memory($doc_dest);
+xmlwriter_start_document($xw, '1.0', 'utf8');
+xmlwriter_start_element($xw, "tag1");
+xmlwriter_end_document($xw);
+
+// Force to write and empty the buffer
+echo xmlwriter_flush($xw, true);
+echo "---Done---\n";
+?>
+--EXPECT--
+<?xml version="1.0" encoding="utf8"?>
+<tag1/>
+---Done---
--- /dev/null
+--TEST--
+XMLWriter: libxml2 XML Writer, membuffer, flush, attribute
+--SKIPIF--
+<?php if (!extension_loaded("xmlwriter")) print "skip"; ?>
+--FILE--
+<?php
+/* $Id$ */
+
+$doc_dest = '001.xml';
+$xw = xmlwriter_open_memory($doc_dest);
+xmlwriter_start_document($xw, '1.0', 'utf8');
+xmlwriter_start_element($xw, "tag1");
+
+
+$res = xmlwriter_start_attribute($xw, 'attr1');
+xmlwriter_text($xw, "attr1_value");
+xmlwriter_end_attribute($xw);
+
+xmlwriter_write_attribute($xw, "att2", "att2_value");
+xmlwriter_text($xw, "Test text for tag1");
+$res = xmlwriter_start_element($xw, 'tag2');
+if ($res < 1) {
+ echo "StartElement context validation failed\n";
+ exit();
+}
+xmlwriter_end_document($xw);
+
+// Force to write and empty the buffer
+echo xmlwriter_flush($xw, true);
+echo "---Done---\n";
+?>
+--EXPECT--
+<?xml version="1.0" encoding="utf8"?>
+<tag1 attr1="attr1_value" att2="att2_value">Test text for tag1<tag2/></tag1>
+---Done---
--- /dev/null
+--TEST--
+XMLWriter: libxml2 XML Writer, file buffer, flush
+--SKIPIF--
+<?php if (!extension_loaded("xmlwriter")) print "skip"; ?>
+--FILE--
+<?php
+/* $Id$ */
+
+$doc_dest = '001.xml';
+$xw = xmlwriter_open_uri($doc_dest);
+xmlwriter_start_document($xw, '1.0', 'utf8');
+xmlwriter_start_element($xw, "tag1");
+
+xmlwriter_start_pi($xw, "PHP");
+xmlwriter_text($xw, 'echo $a;');
+xmlwriter_end_pi($xw);
+xmlwriter_end_document($xw);
+
+// Force to write and empty the buffer
+$output_bytes = xmlwriter_flush($xw, true);
+$md5_out = md5_file($doc_dest);
+$md5_res = md5('<?xml version="1.0" encoding="utf8"?>
+<tag1><?PHP echo $a;?></tag1>
+');
+unlink('001.xml');
+if ($md5_out != $md5_res) {
+ echo "failed: $md5_res != $md5_out\n";
+} else {
+ echo "ok.\n";
+}
+echo "---Done---\n";
+?>
+--EXPECT--
+ok.
+---Done---
--- /dev/null
+--TEST--
+XMLWriter: libxml2 XML Writer, comments
+--SKIPIF--
+<?php if (!extension_loaded("xmlwriter")) print "skip"; ?>
+--FILE--
+<?php
+/* $Id$ */
+
+$doc_dest = '001.xml';
+$xw = xmlwriter_open_uri($doc_dest);
+xmlwriter_start_document($xw, '1.0', 'utf8');
+xmlwriter_start_element($xw, "tag1");
+
+xmlwriter_start_comment($xw);
+xmlwriter_text($xw, 'comment');
+xmlwriter_end_comment($xw);
+xmlwriter_write_comment($xw, "comment #2");
+xmlwriter_end_document($xw);
+
+// Force to write and empty the buffer
+$output_bytes = xmlwriter_flush($xw, true);
+echo file_get_contents($doc_dest);
+unlink('001.xml');
+echo "---Done---\n";
+?>
+--EXPECT--
+<?xml version="1.0" encoding="utf8"?>
+<tag1><!--comment--><!--comment #2--></tag1>
+---Done---
--- /dev/null
+--TEST--
+XMLWriter: libxml2 XML Writer, file buffer, flush
+--SKIPIF--
+<?php if (!extension_loaded("xmlwriter")) print "skip"; ?>
+--FILE--
+<?php
+/* $Id$ */
+
+$doc_dest = '001.xml';
+$xw = new XMLWriter();
+$xw->openUri($doc_dest);
+$xw->startDocument('1.0', 'utf8', 'standalonearg');
+$xw->startElement("tag1");
+$xw->endDocument();
+
+// Force to write and empty the buffer
+$output_bytes = $xw->flush(true);
+echo file_get_contents($doc_dest);
+unlink('001.xml');
+echo "---Done---\n";
+?>
+--EXPECT--
+<?xml version="1.0" encoding="utf8" standalone="standalonearg"?>
+<tag1/>
+---Done---
--- /dev/null
+--TEST--
+XMLWriter: libxml2 XML Writer, membuffer, flush
+--SKIPIF--
+<?php if (!extension_loaded("xmlwriter")) print "skip"; ?>
+--FILE--
+<?php
+/* $Id$ */
+
+$xw = new XMLWriter();
+$xw->openMemory();
+$xw->startDocument('1.0', 'utf8', 'standalone');
+$xw->startElement("tag1");
+$xw->endDocument();
+
+// Force to write and empty the buffer
+echo $xw->flush(true);
+echo "---Done---\n";
+?>
+--EXPECT--
+<?xml version="1.0" encoding="utf8" standalone="standalone"?>
+<tag1/>
+---Done---
--- /dev/null
+--TEST--
+XMLWriter: libxml2 XML Writer, membuffer, flush, text, attribute
+--SKIPIF--
+<?php if (!extension_loaded("xmlwriter")) print "skip"; ?>
+--FILE--
+<?php
+/* $Id$ */
+
+$xw = new XMLWriter();
+$xw->openMemory();
+$xw->startDocument('1.0', 'utf8');
+$xw->startElement("tag1");
+
+$res = $xw->startAttribute('attr1');
+$xw->text("attr1_value");
+$xw->endAttribute();
+
+$res = $xw->startAttribute('attr2');
+$xw->text("attr2_value");
+$xw->endAttribute();
+
+$xw->text("Test text for tag1");
+$res = $xw->startElement('tag2');
+if ($res < 1) {
+ echo "StartElement context validation failed\n";
+ exit();
+}
+$xw->endDocument();
+
+// Force to write and empty the buffer
+echo $xw->flush(true);
+echo "---Done---\n";
+?>
+--EXPECT--
+<?xml version="1.0" encoding="utf8"?>
+<tag1 attr1="attr1_value" attr2="attr2_value">Test text for tag1<tag2/></tag1>
+---Done---
--- /dev/null
+--TEST--
+XMLWriter: libxml2 XML Writer, file buffer, flush
+--SKIPIF--
+<?php if (!extension_loaded("xmlwriter")) print "skip"; ?>
+--FILE--
+<?php
+/* $Id$ */
+
+$doc_dest = '001.xml';
+$xw = new XMLWriter();
+$xw->openUri($doc_dest);
+$xw->startDocument('1.0', 'utf8');
+$xw->startElement("tag1");
+
+$xw->startPi("PHP");
+$xw->text('echo $a;');
+$xw->endPi();
+$xw->endDocument();
+
+// Force to write and empty the buffer
+$xw->flush(true);
+$md5_out = md5_file($doc_dest);
+$md5_res = md5('<?xml version="1.0" encoding="utf8"?>
+<tag1><?PHP echo $a;?></tag1>
+');
+unlink('001.xml');
+if ($md5_out != $md5_res) {
+ echo "failed: $md5_res != $md5_out\n";
+} else {
+ echo "ok.\n";
+}
+echo "---Done---\n";
+?>
+--EXPECT--
+ok.
+---Done---
--- /dev/null
+--TEST--
+XMLWriter: libxml2 XML Writer, comments
+--SKIPIF--
+<?php if (!extension_loaded("xmlwriter")) print "skip"; ?>
+--FILE--
+<?php
+/* $Id$ */
+
+$doc_dest = '001.xml';
+$xw = new XMLWriter();
+$xw->openUri($doc_dest);
+$xw->startDocument('1.0', 'utf8');
+$xw->startElement("tag1");
+$xw->startComment();
+$xw->text('comment');
+$xw->endComment();
+$xw->writeComment("comment #2");
+$xw->endDocument();
+
+// Force to write and empty the buffer
+$output_bytes = $xw->flush(true);
+echo file_get_contents($doc_dest);
+unlink('001.xml');
+echo "---Done---\n";
+?>
+--EXPECT--
+<?xml version="1.0" encoding="utf8"?>
+<tag1><!--comment--><!--comment #2--></tag1>
+---Done---