*
* Initializes the wrapped XMLWriter.
*
- * @param string $output URL for outputting, defaults to stdout
+ * @param string $output URL for outputting, if null it defaults to stdout ('php://output')
* @param boolean $indent Whether to indent output, default true
*/
- function __construct($output='php://output', $indent=true)
+ function __construct($output=null, $indent=null)
{
+ if (is_null($output)) {
+ $output = 'php://output';
+ }
$this->xw = new XMLWriter();
$this->xw->openURI($output);
+ if(is_null($indent)) {
+ $indent = common_config('site', 'indent');
+ }
$this->xw->setIndent($indent);
}
*
* Utility for outputting an XML element. A convenient wrapper
* for a bunch of longer XMLWriter calls. This is best for
- * when an element does not have any sub-elements; if that's the
+ * when an element doesn't have any sub-elements; if that's the
* case, use elementStart() and elementEnd() instead.
*
* The $content element will be escaped for XML. If you need
$this->elementEnd($tag);
}
+ function elementNS(array $ns, $tag, $attrs=null, $content=null)
+ {
+ $this->elementStartNS($ns, $tag, $attrs);
+ if (!is_null($content)) {
+ $this->xw->text($content);
+ }
+ $this->elementEnd($tag);
+ }
+
/**
* output a start tag for an element
*
}
}
+ function elementStartNS(array $ns, $tag, $attrs=null)
+ {
+ reset($ns); // array pointer to 0
+ $uri = key($ns);
+ $this->xw->startElementNS($ns[$uri], $tag, $uri);
+ if (is_array($attrs)) {
+ foreach ($attrs as $name => $value) {
+ $this->xw->writeAttribute($name, $value);
+ }
+ } else if (is_string($attrs)) {
+ $this->xw->writeAttribute('class', $attrs);
+ }
+ }
+
/**
* output an end tag for an element
*
{
static $empty_tag = array('base', 'meta', 'link', 'hr',
'br', 'param', 'img', 'area',
- 'input', 'col');
+ 'input', 'col', 'source');
// XXX: check namespace
if (in_array($tag, $empty_tag)) {
$this->xw->endElement();
{
$this->xw->writeComment($txt);
}
+
+ /**
+ * Flush output buffers
+ *
+ * @return void
+ */
+
+ function flush()
+ {
+ $this->xw->flush();
+ }
}