BPS Script API  2.24.4
bps::XmlWriter Class Reference

A wrapper for QXmlStreamWriter. More...

Public Member Functions

void writeAttribute (String aName, String aValue)
 Writes an attribute with name and value. More...
 
void writeBytes (ByteArray aData)
 Writes characters with name and binary data converted to text by Base64. More...
 
void writeBytesElement (String aName, ByteArray aData)
 Writes a text element with name and binary data converted to text by Base64. More...
 
void writeCDATA (String aText)
 Writes text as CDATA section. More...
 
void writeCharacters (String aText)
 Writes text. More...
 
void writeDTD (String aDtd)
 Writes a DTD section. More...
 
void writeEmptyElement (String aName)
 Writes an empty element with name. More...
 
void writeEndDocument ()
 Writes a document end, and closes the file in case the file constructor was used.
 
void writeEndElement ()
 Writes a element end and closes the currently open element.
 
void writeStartDocument (String aVersion=undefined)
 Writes a document start with the XML version number version. More...
 
void writeStartElement (String aName)
 Writes a start element. More...
 
void writeTextElement (String aName, String aText)
 Writes a text element with name and text. More...
 
 XmlWriter ()
 Constructor to create the XML in memory. More...
 
 XmlWriter (String aFileName)
 Constructor to write directly in a file. More...
 

Properties

Boolean autoFormatting
 The auto-formatting flag of the writer. More...
 
String autoFormattingIndent
 Autoformat indentation level. More...
 
String string
 The created XML as string. More...
 

Detailed Description

A wrapper for QXmlStreamWriter.

Example usage:

var xml = new bps.XmlWriter('myfile.xml');
xml.writeStartElement('elem');
xml.writeAttribute('name', 'Some name');
xml.writeTextElement('mytext', 'Some text to store.');
xml.writeEndElement();
xml.writeEndDocument();
void importExtension(String aExtensionName)
Imports the named extension into the script engine.
A wrapper for QXmlStreamWriter.
Definition: bps.XmlWriter.js:20
void writeStartDocument(String aVersion=undefined)
Writes a document start with the XML version number version.
The bps extension is a namespace assembling general BPS properties and functions.
Definition: bps.AsyncIO.js:1

Constructor & Destructor Documentation

◆ XmlWriter() [1/2]

bps::XmlWriter::XmlWriter ( )

Constructor to create the XML in memory.

Get the data with property string at the end.

◆ XmlWriter() [2/2]

bps::XmlWriter::XmlWriter ( String  aFileName)

Constructor to write directly in a file.

Parameters
aFileNameThe file name to write the XML.

Member Function Documentation

◆ writeAttribute()

void bps::XmlWriter::writeAttribute ( String  aName,
String  aValue 
)

Writes an attribute with name and value.

This function can only be called after writeStartElement() before any content is written, or after writeEmptyElement().

Parameters
[in]aNameThe qualified attribute name.
[in]aValueThe attribute value.

◆ writeBytes()

void bps::XmlWriter::writeBytes ( ByteArray  aData)

Writes characters with name and binary data converted to text by Base64.

The characters '<', '&', and double quote are escaped as entity references "&lt;", "&amp;", and "&quot;". To avoid the forbidden sequence "]]>", ">" is also escaped as "&gt;".

Parameters
[in]aDataThe binary data to write, for example a BLOB from the database.

◆ writeBytesElement()

void bps::XmlWriter::writeBytesElement ( String  aName,
ByteArray  aData 
)

Writes a text element with name and binary data converted to text by Base64.

Parameters
[in]aNameThe qualified attribute name.
[in]aDataThe binary data to write, for example a BLOB from the database.

◆ writeCDATA()

void bps::XmlWriter::writeCDATA ( String  aText)

Writes text as CDATA section.

If text contains the forbidden character sequence "]]>", it is split into different CDATA sections. This function mainly exists for completeness. Normally you should not need use it, because writeCharacters() automatically escapes all non-content characters.

Parameters
[in]aTextThe text to write.

◆ writeCharacters()

void bps::XmlWriter::writeCharacters ( String  aText)

Writes text.

The characters '<', '&', and double quote are escaped as entity references "&lt;", "&amp;", and "&quot;". To avoid the forbidden sequence "]]>", ">" is also escaped as "&gt;".

Parameters
[in]aTextThe text to write.

◆ writeDTD()

void bps::XmlWriter::writeDTD ( String  aDtd)

Writes a DTD section.

Parameters
[in]aDtdRepresents the entire doctypedecl production from the XML 1.0 specification.

◆ writeEmptyElement()

void bps::XmlWriter::writeEmptyElement ( String  aName)

Writes an empty element with name.

Subsequent calls to writeAttribute() will add attributes to this element.

Parameters
[in]aNameThe qualified element name.

◆ writeStartDocument()

void bps::XmlWriter::writeStartDocument ( String  aVersion = undefined)

Writes a document start with the XML version number version.

When aVersion is omitted, "1.0" will be used.

Parameters
[in]aVersionThe version string.

◆ writeStartElement()

void bps::XmlWriter::writeStartElement ( String  aName)

Writes a start element.

Subsequent calls to writeAttribute() will add attributes to this element.

Parameters
[in]aNameThe qualified element name.

◆ writeTextElement()

void bps::XmlWriter::writeTextElement ( String  aName,
String  aText 
)

Writes a text element with name and text.

This is a convenience function equivalent to:

xml.writeStartElement(name);
xml.writeCharacters(text);
xml.writeEndElement();
Parameters
[in]aNameThe qualified attribute name.
[in]aTextThe text to write.

Property Documentation

◆ autoFormatting

Boolean bps::XmlWriter::autoFormatting
readwrite

The auto-formatting flag of the writer.

Controls whether or not the writer automatically formats the generated XML data. If enabled, the writer automatically adds line-breaks and indentation to empty sections between elements (ignorable whitespace). The main purpose of auto-formatting is to split the data into several lines, and to increase readability for a human reader.

The indentation depth can be controlled through the autoFormattingIndent property.

By default, auto-formatting is disabled.

◆ autoFormattingIndent

String bps::XmlWriter::autoFormattingIndent
readwrite

Autoformat indentation level.

The number of spaces or tabs used for indentation when auto-formatting is enabled. Positive numbers indicate spaces, negative numbers tabs.

The default indentation is 4.

◆ string

String bps::XmlWriter::string
read

The created XML as string.

Only when using the default constructor, when using the file constructor this property always returns an empty string.


The documentation for this class was generated from the following file: