Class: XMLWriter

$k. XMLWriter

new $k.XMLWriter(document, options)

Creates a new XML writer

Name Type Description
document $k.AbstractTextDocument optional

Document to write on. A new text document will be created if not specified

options object optional

Options

  • invalidCharacters: {boolean} True if invalid characters should be exported as numeric entities. False if invalid characters should be skipped.
  • indent {boolean} Enable/disable automatic indentation of the XML tags
  • charMap {object} Map of characters (string of length 1) to replacement strings. When writing text, all matching characters will be replaced with these strings.

SAX interface for writing XML. An XMLWriter is created by sending xmlWriter() to a document.

Version:
  • Experimental feature, might be removed at any time
Since:
  • 4.3.1

Methods

attribute(localName, value, prefix)

Writes an attribute of a tag to the document

Name Type Description
localName string

Local name of the attribute

value string

Value of the attribute

prefix string optional

Namespace prefix. The writer does not check if it is bound to a namespace

Throws:
Type Description
$k.exception.XMLError

If writing the attribute is not possible

cdata(characters)

Writes a CDATA section to the document

Name Type Description
characters string
Throws:
Type Description
$k.exception.XMLError

If writing the CData is not possible

characters(characters)

Writes a string to the document

Name Type Description
characters string
Throws:
Type Description
$k.exception.XMLError

If writing the string is not possible

comment(comment)

Writes a comment to the document

Name Type Description
comment string
Throws:
Type Description
$k.exception.XMLError

If writing the comment is not possible

defaultNamespace(namespace)

Write the default namespace of the current tag and its children

Name Type Description
namespace string
Throws:
Type Description
$k.exception.XMLError

If writing the namespace is not possible

Returns the document

Version:
  • Experimental feature, might be removed at any time
Since:
  • 4.3.1
Returns:
Type Description
$k.AbstractTextDocument

endElement()

Closes the currently opened tag

Throws:
Type Description
$k.exception.XMLError

If closing the tag is not possible

print(characters)

Writes a string to the document without any escaping

Name Type Description
characters string
Throws:
Type Description
$k.exception.XMLError

If writing the string is not possible

processingInstruction(target, data)

Writes a processing instruction to the document

Name Type Description
target string
data string
Throws:
Type Description
$k.exception.XMLError

If writing the comment is not possible

setIndent(enableIndentation)

Enable/disable automatic indentation of the XML tags.
Default is true

Name Type Description
enableIndentation boolean

setPrefix(prefix, namespace)

Sets the prefix the uri is bound to

Name Type Description
prefix string
namespace string

startElement(localName, prefix)

Writes a start tag to the document

Name Type Description
localName string

Local name of the tag

prefix string optional

Namespace prefix. The writer does not check if it is bound to a namespace

Throws:
Type Description
$k.exception.XMLError

If writing the tag is not possible