1--TEST-- 2XMLWriter: libxml2 XML Writer, membuffer, flush, text, attribute 3--SKIPIF-- 4<?php if (!extension_loaded("xmlwriter")) print "skip"; ?> 5--FILE-- 6<?php 7 8$xw = new XMLWriter(); 9$xw->openMemory(); 10$xw->startDocument('1.0', 'UTF-8'); 11$xw->startElement("tag1"); 12 13$res = $xw->startAttribute('attr1'); 14$xw->text("attr1_value"); 15$xw->endAttribute(); 16 17$res = $xw->startAttribute('attr2'); 18$xw->text("attr2_value"); 19$xw->endAttribute(); 20 21$xw->text("Test text for tag1"); 22$res = $xw->startElement('tag2'); 23if ($res < 1) { 24 echo "StartElement context validation failed\n"; 25 exit(); 26} 27$xw->endDocument(); 28 29// Force to write and empty the buffer 30echo $xw->flush(true); 31?> 32--EXPECT-- 33<?xml version="1.0" encoding="UTF-8"?> 34<tag1 attr1="attr1_value" attr2="attr2_value">Test text for tag1<tag2/></tag1> 35