Virtual Belgium  2.0
A micro-simulation platform for the Belgian population
 All Classes Namespaces Files Functions Variables Typedefs Enumerator Friends Macros Pages
tinyxml2::XMLPrinter Class Reference

#include <tinyxml2.hpp>

Public Member Functions

 XMLPrinter (FILE *file=0, bool compact=false)
 
 ~XMLPrinter ()
 
void pushHeader (bool writeBOM, bool writeDeclaration)
 
void openElement (const char *name)
 
void pushAttribute (const char *name, const char *value)
 If streaming, add an attribute to an open element. More...
 
void pushAttribute (const char *name, int value)
 
void pushAttribute (const char *name, unsigned value)
 
void pushAttribute (const char *name, bool value)
 
void pushAttribute (const char *name, double value)
 
void closeElement ()
 If streaming, close the Element. More...
 
void pushText (const char *text, bool cdata=false)
 Add a text node. More...
 
void pushText (int value)
 Add a text node from an integer. More...
 
void pushText (unsigned value)
 Add a text node from an unsigned. More...
 
void pushText (bool value)
 Add a text node from a bool. More...
 
void pushText (float value)
 Add a text node from a float. More...
 
void pushText (double value)
 Add a text node from a double. More...
 
void pushComment (const char *comment)
 Add a comment. More...
 
void pushDeclaration (const char *value)
 
void pushUnknown (const char *value)
 
virtual bool visitEnter (const XMLDocument &)
 Visit a document. More...
 
virtual bool VisitExit (const XMLDocument &)
 Visit a document. More...
 
virtual bool visitEnter (const XMLElement &element, const XMLAttribute *attribute)
 Visit an element. More...
 
virtual bool visitExit (const XMLElement &element)
 Visit an element. More...
 
virtual bool visit (const XMLText &text)
 Visit a text node. More...
 
virtual bool visit (const XMLComment &comment)
 Visit a comment node. More...
 
virtual bool visit (const XMLDeclaration &declaration)
 Visit a declaration. More...
 
virtual bool visit (const XMLUnknown &unknown)
 Visit an unknown node. More...
 
const char * CStr () const
 
int CStrSize () const
 
- Public Member Functions inherited from tinyxml2::XMLVisitor
virtual ~XMLVisitor ()
 

Private Types

enum  { ENTITY_RANGE = 64, BUF_SIZE = 200 }
 

Private Member Functions

void sealElement ()
 
void printSpace (int depth)
 
void printString (const char *, bool restrictedEntitySet)
 
void print (const char *format,...)
 

Private Attributes

bool elementJustOpened
 
bool firstElement
 
FILE * fp
 
int depth
 
int textDepth
 
bool processEntities
 
bool compactMode
 
bool entityFlag [ENTITY_RANGE]
 
bool restrictedEntityFlag [ENTITY_RANGE]
 
DynArray< const char *, 10 > stack
 
DynArray< char, 20 > buffer
 

Detailed Description

Printing functionality. The XMLPrinter gives you more options than the XMLDocument::Print() method.

It can:

  1. Print to memory.
  2. Print to a file you provide.
  3. Print XML without a XMLDocument.

Print to Memory

XMLPrinter printer;
doc->Print( &printer );
SomeFunction( printer.CStr() );

Print to a File

You provide the file pointer.

XMLPrinter printer( fp );
doc.Print( &printer );

Print without a XMLDocument

When loading, an XML parser is very useful. However, sometimes when saving, it just gets in the way. The code is often set up for streaming, and constructing the DOM is just overhead.

The Printer supports the streaming case. The following code prints out a trivially simple XML file without ever creating an XML document.

XMLPrinter printer( fp );
printer.OpenElement( "foo" );
printer.PushAttribute( "foo", "bar" );
printer.CloseElement();

Member Enumeration Documentation

anonymous enum
private
Enumerator
ENTITY_RANGE 
BUF_SIZE 

Constructor & Destructor Documentation

XMLPrinter::XMLPrinter ( FILE *  file = 0,
bool  compact = false 
)

Construct the printer. If the FILE* is specified, this will print to the FILE. Else it will print to memory, and the result is available in CStr(). If 'compact' is set to true, then output is created with only required whitespace and newlines.

tinyxml2::XMLPrinter::~XMLPrinter ( )
inline

Member Function Documentation

void XMLPrinter::closeElement ( )

If streaming, close the Element.

const char* tinyxml2::XMLPrinter::CStr ( ) const
inline

If in print to memory mode, return a pointer to the XML file in memory.

int tinyxml2::XMLPrinter::CStrSize ( ) const
inline

If in print to memory mode, return the size of the XML file in memory. (Note the size returned includes the terminating null.)

void XMLPrinter::openElement ( const char *  name)

If streaming, start writing an element. The element must be closed with CloseElement()

void XMLPrinter::print ( const char *  format,
  ... 
)
private
void XMLPrinter::printSpace ( int  depth)
private
void XMLPrinter::printString ( const char *  p,
bool  restrictedEntitySet 
)
private
void XMLPrinter::pushAttribute ( const char *  name,
const char *  value 
)

If streaming, add an attribute to an open element.

void XMLPrinter::pushAttribute ( const char *  name,
int  value 
)
void XMLPrinter::pushAttribute ( const char *  name,
unsigned  value 
)
void XMLPrinter::pushAttribute ( const char *  name,
bool  value 
)
void XMLPrinter::pushAttribute ( const char *  name,
double  value 
)
void XMLPrinter::pushComment ( const char *  comment)

Add a comment.

void XMLPrinter::pushDeclaration ( const char *  value)
void XMLPrinter::pushHeader ( bool  writeBOM,
bool  writeDeclaration 
)

If streaming, write the BOM and declaration.

void XMLPrinter::pushText ( const char *  text,
bool  cdata = false 
)

Add a text node.

void XMLPrinter::pushText ( int  value)

Add a text node from an integer.

void XMLPrinter::pushText ( unsigned  value)

Add a text node from an unsigned.

void XMLPrinter::pushText ( bool  value)

Add a text node from a bool.

void XMLPrinter::pushText ( float  value)

Add a text node from a float.

void XMLPrinter::pushText ( double  value)

Add a text node from a double.

void XMLPrinter::pushUnknown ( const char *  value)
void XMLPrinter::sealElement ( )
private
bool XMLPrinter::visit ( const XMLText )
virtual

Visit a text node.

Reimplemented from tinyxml2::XMLVisitor.

bool XMLPrinter::visit ( const XMLComment )
virtual

Visit a comment node.

Reimplemented from tinyxml2::XMLVisitor.

bool XMLPrinter::visit ( const XMLDeclaration )
virtual

Visit a declaration.

Reimplemented from tinyxml2::XMLVisitor.

bool XMLPrinter::visit ( const XMLUnknown )
virtual

Visit an unknown node.

Reimplemented from tinyxml2::XMLVisitor.

bool XMLPrinter::visitEnter ( const XMLDocument )
virtual

Visit a document.

Reimplemented from tinyxml2::XMLVisitor.

bool XMLPrinter::visitEnter ( const XMLElement ,
const XMLAttribute  
)
virtual

Visit an element.

Reimplemented from tinyxml2::XMLVisitor.

virtual bool tinyxml2::XMLPrinter::VisitExit ( const XMLDocument )
inlinevirtual

Visit a document.

Reimplemented from tinyxml2::XMLVisitor.

bool XMLPrinter::visitExit ( const XMLElement )
virtual

Visit an element.

Reimplemented from tinyxml2::XMLVisitor.

Member Data Documentation

DynArray< char, 20 > tinyxml2::XMLPrinter::buffer
private
bool tinyxml2::XMLPrinter::compactMode
private
int tinyxml2::XMLPrinter::depth
private
bool tinyxml2::XMLPrinter::elementJustOpened
private
bool tinyxml2::XMLPrinter::entityFlag[ENTITY_RANGE]
private
bool tinyxml2::XMLPrinter::firstElement
private
FILE* tinyxml2::XMLPrinter::fp
private
bool tinyxml2::XMLPrinter::processEntities
private
bool tinyxml2::XMLPrinter::restrictedEntityFlag[ENTITY_RANGE]
private
DynArray< const char*, 10 > tinyxml2::XMLPrinter::stack
private
int tinyxml2::XMLPrinter::textDepth
private

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