Bitstream Interpretation Library (BIL)
0.1
|
A simple XML stream writer. More...
#include <util/XMLWriter.hpp>
Public Member Functions | |
XMLWriter (std::ostream &os, size_t baseIndent=0, size_t levelIndent=2) | |
Creates a new XMLWriter instance. | |
void | beginElement (const std::string &name, bool newLine=true) |
Begins a new element. | |
void | endElement (bool newLine=true) |
Ends the current element. | |
void | addAttribute (const std::string &name, const std::string &value) |
Adds an string attribute to the current opening tag. | |
void | addAttribute (const std::string &name, unsigned value) |
Adds an unsigned attribute to the current opening tag. | |
void | addData (const std::string &data, bool newLine=true) |
Adds data into the current element. | |
void | addProcessingInstruction (const std::string &target, const std::string &instruction, bool newLine=true) |
Adds a processing instruction element. | |
size_t | depth () const |
Gets the current element depth. | |
std::string | element () const |
Gets the current element name. |
A simple XML stream writer.
This XML writer is for simple and fast writing of XML data. It is initialized over an output stream, which is used for all writing. Because it writes directly to the stream, no data (except the tag hierarchy stack) is cached and it is possible to write even very large files with almost no memory consumption. It also ensures syntactic correctness of generated XML data: When tags are closed, they get the the right tag name (through tracking of the hierarchy levels and names). Every XML element has its own writing functions: If syntactical correct tag/attribute names and data are given, the output will also be correct. Also indentation will be done automatically.
Definition at line 32 of file XMLWriter.hpp.
|
explicit |
Creates a new XMLWriter instance.
os | The stream to use for XML output. |
baseIndent | Number of space chars to prepend every line. |
levelIndent | Number of space chars to insert for every level. |
Definition at line 25 of file XMLWriter.cpp.
void XMLWriter::beginElement | ( | const std::string & | name, |
bool | newLine = true |
||
) |
Begins a new element.
Writes the start of an opening tag. The opening tag is not finished, because attributes (via addAttribute()) may follow. When the methods beginElement(), endElement(), addData(), and addProcessingInstruction() will later be called, the opening tag will automatically be finished.
name | Name of element to begin. |
newLine | Specifies if a line break should be inserted before. |
Definition at line 39 of file XMLWriter.cpp.
void XMLWriter::endElement | ( | bool | newLine = true | ) |
Ends the current element.
If the current element has no content, no separate ending tag is created. Instead, the opening tag is finished with an empty element marker.
. |
Definition at line 58 of file XMLWriter.cpp.
void XMLWriter::addAttribute | ( | const std::string & | name, |
const std::string & | value | ||
) |
Adds an string attribute to the current opening tag.
Because attributes can only be placed inside an opening tag, addAttribute() can only be called directly after beginElement() or addAttribute().
name | The attribute name. |
value | The attribute value. |
. |
Definition at line 84 of file XMLWriter.cpp.
void XMLWriter::addAttribute | ( | const std::string & | name, |
unsigned | value | ||
) |
Adds an unsigned attribute to the current opening tag.
Because attributes can only be placed inside an opening tag, addAttribute() can only be called directly after beginElement() or addAttribute().
name | The attribute name. |
value | The attribute value. |
. |
Definition at line 93 of file XMLWriter.cpp.
void XMLWriter::addData | ( | const std::string & | data, |
bool | newLine = true |
||
) |
Adds data into the current element.
Because data can only be placed inside an element, addData() can be only called directly after beginElement() or addAttribute(), thereby closing the beginning tag.
data | The data. |
newLine | Specifies if a line break should be inserted before. |
. |
Definition at line 102 of file XMLWriter.cpp.
void XMLWriter::addProcessingInstruction | ( | const std::string & | target, |
const std::string & | instruction, | ||
bool | newLine = true |
||
) |
Adds a processing instruction element.
target | Target of the processing instruction. |
newLine | Specifies if a line break should be inserted before. |
instruction | The instruction. |
Definition at line 116 of file XMLWriter.cpp.
size_t XMLWriter::depth | ( | ) | const |
Gets the current element depth.
Definition at line 130 of file XMLWriter.cpp.
std::string XMLWriter::element | ( | ) | const |
Gets the current element name.
Definition at line 136 of file XMLWriter.cpp.