![]() |
Virtual Belgium
2.0
A micro-simulation platform for the Belgian population
|
#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 |
Printing functionality. The XMLPrinter gives you more options than the XMLDocument::Print() method.
It can:
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();
| 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.
|
inline |
| void XMLPrinter::closeElement | ( | ) |
If streaming, close the Element.
|
inline |
If in print to memory mode, return a pointer to the XML file in memory.
|
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()
|
private |
|
private |
|
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 | ) |
|
private |
|
virtual |
Visit a text node.
Reimplemented from tinyxml2::XMLVisitor.
|
virtual |
Visit a comment node.
Reimplemented from tinyxml2::XMLVisitor.
|
virtual |
Visit a declaration.
Reimplemented from tinyxml2::XMLVisitor.
|
virtual |
Visit an unknown node.
Reimplemented from tinyxml2::XMLVisitor.
|
virtual |
Visit a document.
Reimplemented from tinyxml2::XMLVisitor.
|
virtual |
Visit an element.
Reimplemented from tinyxml2::XMLVisitor.
|
inlinevirtual |
Visit a document.
Reimplemented from tinyxml2::XMLVisitor.
|
virtual |
Visit an element.
Reimplemented from tinyxml2::XMLVisitor.
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |