Jameo Core Library
Loading...
Searching...
No Matches
Classes | Public Member Functions | List of all members
jm::XMLWriter Class Reference

This class provides methods to write XML data. More...

Inheritance diagram for jm::XMLWriter:
jm::Object

Public Member Functions

 XMLWriter (Stream *output)
 Constructor.
 
 ~XMLWriter () override
 Destructor.
 
bool startDocument ()
 This method must be called at the beginning. It opens the stream if it hasn't been opened yet.
 
bool endDocument ()
 This method must be called at the end. It closes the stream.
 
void startIndent ()
 Increase indentation level.
 
void endIndent ()
 Decrease indentation level.
 
void startElement (const String &name)
 This method opens a new XML element.
 
void writeAttribute (const String &name, const String &content)
 This method writes an XML attribute to the open start element.
 
void writeAttribute (const String &name, int32 content)
 This method writes an XML attribute to the currently open start element.
 
void writeAttribute (const String &name, uint32 content)
 This method writes an XML attribute to the currently open start element.
 
void writeAttribute (const String &name, int64 content)
 This method writes an XML attribute to the currently open start element.
 
void writeAttribute (const String &name, uint64 content)
 This method writes an XML attribute to the currently open start element.
 
void writeAttribute (const String &name, float content)
 This method writes an XML attribute to the currently open start element.
 
void writeAttribute (const String &name, double content)
 This method writes an XML attribute to the currently open start element.
 
void endElement ()
 This method closes the currently open XML element. If the element has no content, a <.../> element is written.
 
void writeCData (const String &cdata, bool xmlencode=true)
 This method writes CDATA to the currently open start element.
 
void WriteBase64 (const uint8 *data, size_t length)
 This method writes data and encodes it using the BASE64 algorithm.
 
- Public Member Functions inherited from jm::Object
 Object () noexcept
 Constructor.
 
virtual ~Object () noexcept
 Destructor.
 
void release () noexcept
 Decreases the reference counter and releases the object immediately when the reference counter becomes 0.
 
Objectretain () noexcept
 Increases the reference counter of this object by 1.
 
Objectautorelease () noexcept
 Same function as release(), but releases the object with a delay if the reference counter is 0. AutoreleasePool::drain() must be called in the to release the object.
 
int32 referenceCount () const noexcept
 Returns the value of the reference counter.
 
virtual bool equals (const Object *other) const
 Comparison of objects.
 
virtual String displayName () const
 Returns the display name of the object intended to present to a user.
 
virtual void printDiffInfo (DiffOperation operation, Object *other) const
 Output method for outputting the diff results for the diff algorithm.
 
void setHighBit (bool status) noexcept
 
bool highBit () const noexcept
 

Detailed Description

This class provides methods to write XML data.

The XMLWriter class allows you to write XML files by providing various methods to handle different aspects of XML writing.

Constructor & Destructor Documentation

◆ XMLWriter()

jm::XMLWriter::XMLWriter ( Stream output)
explicit

Constructor.

Parameters
outputThe Stream where the XML data should be written.

◆ ~XMLWriter()

jm::XMLWriter::~XMLWriter ( )
override

Destructor.

Member Function Documentation

◆ endDocument()

bool jm::XMLWriter::endDocument ( )

This method must be called at the end. It closes the stream.

Returns
true if the stream is successfully closed.

◆ endElement()

void jm::XMLWriter::endElement ( )

This method closes the currently open XML element. If the element has no content, a <.../> element is written.

◆ endIndent()

void jm::XMLWriter::endIndent ( )

Decrease indentation level.

In XML, whitespaces are sometimes significant. The significance of whitespaces depends on the document. This method performs an indentation and decreases the indentation level.

Note
This method is used to decrease the indentation level in XML writing. It is important to maintain proper indentation for readability and to follow XML formatting conventions.

◆ startDocument()

bool jm::XMLWriter::startDocument ( )

This method must be called at the beginning. It opens the stream if it hasn't been opened yet.

Returns
true if everything is fine.

◆ startElement()

void jm::XMLWriter::startElement ( const String name)

This method opens a new XML element.

This method is used to open a new XML element in the XMLWriter class. It should be called before writing any content to the element.

Parameters
nameThe name of the XML element to be opened.

◆ startIndent()

void jm::XMLWriter::startIndent ( )

Increase indentation level.

In XML, whitespaces are sometimes significant. The significance of whitespaces depends on the document. This method performs an indentation and increases the indentation level.

◆ writeAttribute() [1/7]

void jm::XMLWriter::writeAttribute ( const String name,
const String content 
)

This method writes an XML attribute to the open start element.

Parameters
nameThe name of the attribute.
contentThe content of the attribute.
Warning
This method must be called before writing any content to an element.

◆ writeAttribute() [2/7]

void jm::XMLWriter::writeAttribute ( const String name,
double  content 
)

This method writes an XML attribute to the currently open start element.

This method should be called before writing any content to the element.

Parameters
nameThe name of the attribute.
contentThe content of the attribute.
Warning
This method must be called before writing any content to an element.
Note
The content of the attribute should be a string.

◆ writeAttribute() [3/7]

void jm::XMLWriter::writeAttribute ( const String name,
float  content 
)

This method writes an XML attribute to the currently open start element.

This method should be called before writing any content to the element.

Parameters
nameThe name of the attribute.
contentThe content of the attribute.
Warning
This method must be called before writing any content to an element.
Note
The content of the attribute should be a string.

◆ writeAttribute() [4/7]

void jm::XMLWriter::writeAttribute ( const String name,
int32  content 
)

This method writes an XML attribute to the currently open start element.

This method should be called before writing any content to the element.

Parameters
nameThe name of the attribute.
contentThe content of the attribute.
Warning
This method must be called before writing any content to an element.

◆ writeAttribute() [5/7]

void jm::XMLWriter::writeAttribute ( const String name,
int64  content 
)

This method writes an XML attribute to the currently open start element.

This method should be called before writing any content to the element.

Parameters
nameThe name of the attribute.
contentThe content of the attribute.
Warning
This method must be called before writing any content to an element.

◆ writeAttribute() [6/7]

void jm::XMLWriter::writeAttribute ( const String name,
uint32  content 
)

This method writes an XML attribute to the currently open start element.

This method should be called before writing any content to the element.

Parameters
nameThe name of the attribute.
contentThe content of the attribute.
Warning
This method must be called before writing any content to an element.

◆ writeAttribute() [7/7]

void jm::XMLWriter::writeAttribute ( const String name,
uint64  content 
)

This method writes an XML attribute to the currently open start element.

This method should be called before writing any content to the element.

Parameters
nameThe name of the attribute.
contentThe content of the attribute.
Warning
This method must be called before writing any content to an element.

◆ WriteBase64()

void jm::XMLWriter::WriteBase64 ( const uint8 *  data,
size_t  length 
)

This method writes data and encodes it using the BASE64 algorithm.

Parameters
dataThe unencoded data to be written.
lengthThe length of the data.

◆ writeCData()

void jm::XMLWriter::writeCData ( const String cdata,
bool  xmlencode = true 
)

This method writes CDATA to the currently open start element.

CDATA is used to escape blocks of text that contain characters which would otherwise be recognized as markup. This method should be called before writing any content to the element.

Parameters
cdataThe CDATA to be written.
xmlencodeIf true (default), certain characters (e.g. & -> &) will be XML-encoded.