\ XMLWriter

Enough of libxml's writer to generate a sitemap, and no more.

Not final: it exists so a contrib class can extend it.

Summary

Methods
Properties
Constants
openMemory
openUri
writeRaw
setIndent
setIndentString
startDocument
writePI
writeComment
startElement
writeAttribute
text
writeElement
endElement
endDocument
outputMemory
flush
__call
__destruct
No public properties found
No public constants found
No protected methods found
No protected properties found
No protected constants found
cfwReset
cfwCloseStart
cfwNewline
cfwEscape
cfwBuf
cfwStack
cfwOpen
cfwIndent
cfwIndentString
cfwHandle
No private constants found

Properties

$cfwBuf

$cfwBuf : string

Type

string — the document built so far

$cfwStack

$cfwStack : array

Type

array<int, array{name: string, children: bool, text: bool}> — open elements, innermost last

$cfwOpen

$cfwOpen : bool

Type

bool — whether the innermost start tag is still open and can still take attributes

$cfwIndent

$cfwIndent : bool

Type

bool — whether to pretty-print

$cfwIndentString

$cfwIndentString : string

Type

string — what one indent level is

$cfwHandle

$cfwHandle : resource|null

Type

resource|null — the stream openUri() opened, or null when this writer builds in memory

Methods

openMemory()

openMemory() : bool

Returns

bool —

openUri()

openUri(string  $uri) : bool

Parameters

string $uri

Returns

bool —

writeRaw()

writeRaw(string  $content) : bool

Content written through verbatim, which is what separates this from text().

It still counts as content: the enclosing element has been given something, so its end tag stays on the same line the way it does after text().

Parameters

string $content

Returns

bool —

setIndent()

setIndent(bool  $enable) : bool

Parameters

bool $enable

Returns

bool —

setIndentString()

setIndentString(string  $indent) : bool

Parameters

string $indent

Returns

bool —

startDocument()

startDocument(?string  $version = '1.0', ?string  $encoding = null, ?string  $standalone = null) : bool

Parameters

?string $version
?string $encoding
?string $standalone

Returns

bool —

writePI()

writePI(string  $target, string  $content) : bool

Parameters

string $target
string $content

Returns

bool —

writeComment()

writeComment(string  $content) : bool

Parameters

string $content

Returns

bool —

startElement()

startElement(string  $name) : bool

Parameters

string $name

Returns

bool —

writeAttribute()

writeAttribute(string  $name, string  $value) : bool

Parameters

string $name
string $value

Returns

bool —

text()

text(string  $content) : bool

Parameters

string $content

Returns

bool —

writeElement()

writeElement(string  $name, ?string  $content = null) : bool

Parameters

string $name
?string $content

Returns

bool —

endElement()

endElement() : bool

Returns

bool —

endDocument()

endDocument() : bool

Returns

bool —

outputMemory()

outputMemory(bool  $flush = true) : string

Parameters

bool $flush

Returns

string —

flush()

flush(bool  $empty = true) : mixed

BYTES for a uri writer and the DOCUMENT for a memory one, which is libxml own split.

Returning the string in both cases would read as working: xmlsitemap ignores the return of its periodic flushes, so the file would simply stay empty until something read it.

Parameters

bool $empty

Returns

mixed —

__call()

__call(string  $method, array  $args) : bool

A method this writer does not implement degrades with a reason and answers false.

Parameters

string $method
array $args

The arguments the caller passed.

Returns

bool —

__destruct()

__destruct() : mixed

Returns

mixed —

cfwReset()

cfwReset() : void

shared by openMemory() and openUri(); a reopen abandons whatever was in flight

Returns

void —

cfwCloseStart()

cfwCloseStart() : void

finishes an open start tag, which is what makes attributes order-sensitive

Returns

void —

cfwNewline()

cfwNewline() : void

A newline plus one indent per open element, never before the very first node, and never doubled after the declaration -- which already ends its own line.

Returns

void —

cfwEscape()

cfwEscape(string  $s) : string

ONE escaper for both text and attributes, which is what libxml does.

The obvious split -- ampersand and angle brackets in text, plus the double quote only in attributes -- is wrong, measured: libxml escapes a double quote in TEXT content as well, and leaves a single quote alone in both. Guessing produced exactly that split and the oracle rejected it.

Parameters

string $s

Returns

string —