Bitstream Interpretation Library (BIL)  0.1
Public Member Functions
bil::XMLWriter Class Reference

A simple XML stream writer. More...

#include <util/XMLWriter.hpp>

List of all members.

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.

Detailed Description

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.


Constructor & Destructor Documentation

XMLWriter::XMLWriter ( std::ostream &  os,
size_t  baseIndent = 0,
size_t  levelIndent = 2 
)
explicit

Creates a new XMLWriter instance.

Parameters:
osThe stream to use for XML output.
baseIndentNumber of space chars to prepend every line.
levelIndentNumber of space chars to insert for every level.

Definition at line 25 of file XMLWriter.cpp.


Member Function Documentation

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.

Parameters:
nameName of element to begin.
newLineSpecifies 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.

Exceptions:
.

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().

Parameters:
nameThe attribute name.
valueThe attribute value.
Exceptions:
.

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().

Parameters:
nameThe attribute name.
valueThe attribute value.
Exceptions:
.

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.

Parameters:
dataThe data.
newLineSpecifies if a line break should be inserted before.
Exceptions:
.

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.

Parameters:
targetTarget of the processing instruction.
newLineSpecifies if a line break should be inserted before.
instructionThe instruction.

Definition at line 116 of file XMLWriter.cpp.

size_t XMLWriter::depth ( ) const

Gets the current element depth.

Returns:
The element depth.

Definition at line 130 of file XMLWriter.cpp.

std::string XMLWriter::element ( ) const

Gets the current element name.

Returns:
The element name.

Definition at line 136 of file XMLWriter.cpp.


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