#include <OBTtinyxml.h>
Public Member Functions | |
TiXmlPrinter () | |
virtual bool | VisitEnter (const TiXmlDocument &doc) |
Visit a document. | |
virtual bool | VisitExit (const TiXmlDocument &doc) |
Visit a document. | |
virtual bool | VisitEnter (const TiXmlElement &element, const TiXmlAttribute *firstAttribute) |
Visit an element. | |
virtual bool | VisitExit (const TiXmlElement &element) |
Visit an element. | |
virtual bool | Visit (const TiXmlDeclaration &declaration) |
Visit a declaration. | |
virtual bool | Visit (const TiXmlText &text) |
Visit a text node. | |
virtual bool | Visit (const TiXmlComment &comment) |
Visit a comment node. | |
virtual bool | Visit (const TiXmlUnknown &unknown) |
Visit an unknow node. | |
void | SetIndent (const char *_indent) |
Set the indent characters for printing. | |
const char * | Indent () |
Query the indention string. | |
void | SetLineBreak (const char *_lineBreak) |
Set the line breaking string. | |
const char * | LineBreak () |
Query the current line breaking string. | |
void | SetStreamPrinting () |
Switch over to "stream printing" which is the most dense formatting without linebreaks. | |
const char * | CStr () |
Return the result. | |
size_t | Size () |
Return the length of the result string. | |
const std::string & | Str () |
Return the result. | |
TiXmlPrinter () | |
virtual bool | VisitEnter (const TiXmlDocument &doc) |
Visit a document. | |
virtual bool | VisitExit (const TiXmlDocument &doc) |
Visit a document. | |
virtual bool | VisitEnter (const TiXmlElement &element, const TiXmlAttribute *firstAttribute) |
Visit an element. | |
virtual bool | VisitExit (const TiXmlElement &element) |
Visit an element. | |
virtual bool | Visit (const TiXmlDeclaration &declaration) |
Visit a declaration. | |
virtual bool | Visit (const TiXmlText &text) |
Visit a text node. | |
virtual bool | Visit (const TiXmlComment &comment) |
Visit a comment node. | |
virtual bool | Visit (const TiXmlUnknown &unknown) |
Visit an unknow node. | |
void | SetIndent (const char *_indent) |
Set the indent characters for printing. | |
const char * | Indent () |
Query the indention string. | |
void | SetLineBreak (const char *_lineBreak) |
Set the line breaking string. | |
const char * | LineBreak () |
Query the current line breaking string. | |
void | SetStreamPrinting () |
Switch over to "stream printing" which is the most dense formatting without linebreaks. | |
const char * | CStr () |
Return the result. | |
size_t | Size () |
Return the length of the result string. | |
const std::string & | Str () |
Return the result. | |
Private Member Functions | |
void | DoIndent () |
void | DoLineBreak () |
void | DoIndent () |
void | DoLineBreak () |
Private Attributes | |
int | depth |
bool | simpleTextPrint |
TIXML_STRING | buffer |
TIXML_STRING | indent |
TIXML_STRING | lineBreak |
The TiXmlPrinter is useful when you need to:
When constructed, the TiXmlPrinter is in its default "pretty printing" mode. Before calling Accept() you can call methods to control the printing of the XML document. After TiXmlNode::Accept() is called, the printed document can be accessed via the CStr(), Str(), and Size() methods.
TiXmlPrinter uses the Visitor API.
TiXmlPrinter printer; printer.SetIndent( "\t" ); doc.Accept( &printer ); fprintf( stdout, "%s", printer.CStr() );
Definition at line 1740 of file OBTtinyxml.h.
OBT::TiXmlPrinter::TiXmlPrinter | ( | ) | [inline] |
Definition at line 1743 of file OBTtinyxml.h.
01743 : depth( 0 ), simpleTextPrint( false ), 01744 buffer(), indent( " " ), lineBreak( "\n" ) {}
OBT::TiXmlPrinter::TiXmlPrinter | ( | ) | [inline] |
Definition at line 1742 of file tiny/OBTtinyxml.h.
01742 : depth( 0 ), simpleTextPrint( false ), 01743 buffer(), indent( " " ), lineBreak( "\n" ) {}
bool OBT::TiXmlPrinter::VisitEnter | ( | const TiXmlDocument & | ) | [virtual] |
Visit a document.
Reimplemented from OBT::TiXmlVisitor.
Definition at line 1760 of file OBTtinyxml.cpp.
bool OBT::TiXmlPrinter::VisitExit | ( | const TiXmlDocument & | ) | [virtual] |
Visit a document.
Reimplemented from OBT::TiXmlVisitor.
Definition at line 1765 of file OBTtinyxml.cpp.
bool OBT::TiXmlPrinter::VisitEnter | ( | const TiXmlElement & | , | |
const TiXmlAttribute * | ||||
) | [virtual] |
Visit an element.
Reimplemented from OBT::TiXmlVisitor.
Definition at line 1770 of file OBTtinyxml.cpp.
References buffer, OBT::TiXmlText::CDATA(), depth, DoIndent(), DoLineBreak(), OBT::TiXmlNode::FirstChild(), OBT::TiXmlNode::LastChild(), OBT::TiXmlAttribute::Next(), simpleTextPrint, OBT::TiXmlNode::ToText(), and OBT::TiXmlNode::Value().
01771 { 01772 DoIndent(); 01773 buffer += "<"; 01774 buffer += element.Value(); 01775 01776 for( const TiXmlAttribute* attrib = firstAttribute; attrib; attrib = attrib->Next() ) 01777 { 01778 buffer += " "; 01779 attrib->Print( 0, 0, &buffer ); 01780 } 01781 01782 if ( !element.FirstChild() ) 01783 { 01784 buffer += " />"; 01785 DoLineBreak(); 01786 } 01787 else 01788 { 01789 buffer += ">"; 01790 if ( element.FirstChild()->ToText() 01791 && element.LastChild() == element.FirstChild() 01792 && element.FirstChild()->ToText()->CDATA() == false ) 01793 { 01794 simpleTextPrint = true; 01795 // no DoLineBreak()! 01796 } 01797 else 01798 { 01799 DoLineBreak(); 01800 } 01801 } 01802 ++depth; 01803 return true; 01804 }
bool OBT::TiXmlPrinter::VisitExit | ( | const TiXmlElement & | ) | [virtual] |
Visit an element.
Reimplemented from OBT::TiXmlVisitor.
Definition at line 1807 of file OBTtinyxml.cpp.
References buffer, depth, DoIndent(), DoLineBreak(), OBT::TiXmlNode::FirstChild(), simpleTextPrint, and OBT::TiXmlNode::Value().
01808 { 01809 --depth; 01810 if ( !element.FirstChild() ) 01811 { 01812 // nothing. 01813 } 01814 else 01815 { 01816 if ( simpleTextPrint ) 01817 { 01818 simpleTextPrint = false; 01819 } 01820 else 01821 { 01822 DoIndent(); 01823 } 01824 buffer += "</"; 01825 buffer += element.Value(); 01826 buffer += ">"; 01827 DoLineBreak(); 01828 } 01829 return true; 01830 }
bool OBT::TiXmlPrinter::Visit | ( | const TiXmlDeclaration & | ) | [virtual] |
Visit a declaration.
Reimplemented from OBT::TiXmlVisitor.
Definition at line 1861 of file OBTtinyxml.cpp.
References buffer, DoIndent(), DoLineBreak(), and OBT::TiXmlDeclaration::Print().
01862 { 01863 DoIndent(); 01864 declaration.Print( 0, 0, &buffer ); 01865 DoLineBreak(); 01866 return true; 01867 }
bool OBT::TiXmlPrinter::Visit | ( | const TiXmlText & | ) | [virtual] |
Visit a text node.
Reimplemented from OBT::TiXmlVisitor.
Definition at line 1833 of file OBTtinyxml.cpp.
References buffer, OBT::TiXmlText::CDATA(), DoIndent(), DoLineBreak(), OBT::TiXmlBase::EncodeString(), simpleTextPrint, TIXML_STRING, OBT::TiXmlNode::Value(), and OBT::TiXmlNode::ValueTStr().
01834 { 01835 if ( text.CDATA() ) 01836 { 01837 DoIndent(); 01838 buffer += "<![CDATA["; 01839 buffer += text.Value(); 01840 buffer += "]]>"; 01841 DoLineBreak(); 01842 } 01843 else if ( simpleTextPrint ) 01844 { 01845 TIXML_STRING str; 01846 TiXmlBase::EncodeString( text.ValueTStr(), &str ); 01847 buffer += str; 01848 } 01849 else 01850 { 01851 DoIndent(); 01852 TIXML_STRING str; 01853 TiXmlBase::EncodeString( text.ValueTStr(), &str ); 01854 buffer += str; 01855 DoLineBreak(); 01856 } 01857 return true; 01858 }
bool OBT::TiXmlPrinter::Visit | ( | const TiXmlComment & | ) | [virtual] |
Visit a comment node.
Reimplemented from OBT::TiXmlVisitor.
Definition at line 1870 of file OBTtinyxml.cpp.
References buffer, DoIndent(), DoLineBreak(), and OBT::TiXmlNode::Value().
01871 { 01872 DoIndent(); 01873 buffer += "<!--"; 01874 buffer += comment.Value(); 01875 buffer += "-->"; 01876 DoLineBreak(); 01877 return true; 01878 }
bool OBT::TiXmlPrinter::Visit | ( | const TiXmlUnknown & | ) | [virtual] |
Visit an unknow node.
Reimplemented from OBT::TiXmlVisitor.
Definition at line 1881 of file OBTtinyxml.cpp.
References buffer, DoIndent(), DoLineBreak(), and OBT::TiXmlNode::Value().
01882 { 01883 DoIndent(); 01884 buffer += "<"; 01885 buffer += unknown.Value(); 01886 buffer += ">"; 01887 DoLineBreak(); 01888 return true; 01889 }
void OBT::TiXmlPrinter::SetIndent | ( | const char * | _indent | ) | [inline] |
Set the indent characters for printing.
By default 4 spaces but tab () is also useful, or null/empty string for no indentation.
Definition at line 1760 of file OBTtinyxml.h.
01760 { indent = _indent ? _indent : "" ; }
const char* OBT::TiXmlPrinter::Indent | ( | ) | [inline] |
Query the indention string.
Definition at line 1762 of file OBTtinyxml.h.
01762 { return indent.c_str(); }
void OBT::TiXmlPrinter::SetLineBreak | ( | const char * | _lineBreak | ) | [inline] |
Set the line breaking string.
By default set to newline (
). Some operating systems prefer other characters, or can be set to the null/empty string for no indenation.
Definition at line 1767 of file OBTtinyxml.h.
01767 { lineBreak = _lineBreak ? _lineBreak : ""; }
const char* OBT::TiXmlPrinter::LineBreak | ( | ) | [inline] |
Query the current line breaking string.
Definition at line 1769 of file OBTtinyxml.h.
01769 { return lineBreak.c_str(); }
void OBT::TiXmlPrinter::SetStreamPrinting | ( | ) | [inline] |
Switch over to "stream printing" which is the most dense formatting without linebreaks.
Common when the XML is needed for network transmission.
Definition at line 1774 of file OBTtinyxml.h.
Referenced by OBT::operator<<().
const char* OBT::TiXmlPrinter::CStr | ( | ) | [inline] |
size_t OBT::TiXmlPrinter::Size | ( | ) | [inline] |
Return the length of the result string.
Definition at line 1780 of file OBTtinyxml.h.
01780 { return buffer.size(); }
const std::string& OBT::TiXmlPrinter::Str | ( | ) | [inline] |
Return the result.
Definition at line 1784 of file OBTtinyxml.h.
Referenced by OBT::operator<<().
01784 { return buffer; }
void OBT::TiXmlPrinter::DoIndent | ( | ) | [inline, private] |
void OBT::TiXmlPrinter::DoLineBreak | ( | ) | [inline, private] |
virtual bool OBT::TiXmlPrinter::VisitEnter | ( | const TiXmlDocument & | ) | [virtual] |
virtual bool OBT::TiXmlPrinter::VisitExit | ( | const TiXmlDocument & | ) | [virtual] |
virtual bool OBT::TiXmlPrinter::VisitEnter | ( | const TiXmlElement & | , | |
const TiXmlAttribute * | ||||
) | [virtual] |
virtual bool OBT::TiXmlPrinter::VisitExit | ( | const TiXmlElement & | ) | [virtual] |
virtual bool OBT::TiXmlPrinter::Visit | ( | const TiXmlDeclaration & | ) | [virtual] |
virtual bool OBT::TiXmlPrinter::Visit | ( | const TiXmlText & | ) | [virtual] |
virtual bool OBT::TiXmlPrinter::Visit | ( | const TiXmlComment & | ) | [virtual] |
virtual bool OBT::TiXmlPrinter::Visit | ( | const TiXmlUnknown & | ) | [virtual] |
void OBT::TiXmlPrinter::SetIndent | ( | const char * | _indent | ) | [inline] |
Set the indent characters for printing.
By default 4 spaces but tab () is also useful, or null/empty string for no indentation.
Definition at line 1759 of file tiny/OBTtinyxml.h.
References indent.
01759 { indent = _indent ? _indent : "" ; }
const char* OBT::TiXmlPrinter::Indent | ( | ) | [inline] |
Query the indention string.
Definition at line 1761 of file tiny/OBTtinyxml.h.
References indent.
01761 { return indent.c_str(); }
void OBT::TiXmlPrinter::SetLineBreak | ( | const char * | _lineBreak | ) | [inline] |
Set the line breaking string.
By default set to newline (
). Some operating systems prefer other characters, or can be set to the null/empty string for no indenation.
Definition at line 1766 of file tiny/OBTtinyxml.h.
References lineBreak.
01766 { lineBreak = _lineBreak ? _lineBreak : ""; }
const char* OBT::TiXmlPrinter::LineBreak | ( | ) | [inline] |
Query the current line breaking string.
Definition at line 1768 of file tiny/OBTtinyxml.h.
References lineBreak.
01768 { return lineBreak.c_str(); }
void OBT::TiXmlPrinter::SetStreamPrinting | ( | ) | [inline] |
const char* OBT::TiXmlPrinter::CStr | ( | ) | [inline] |
Return the result.
Definition at line 1777 of file tiny/OBTtinyxml.h.
References buffer.
01777 { return buffer.c_str(); }
size_t OBT::TiXmlPrinter::Size | ( | ) | [inline] |
Return the length of the result string.
Definition at line 1779 of file tiny/OBTtinyxml.h.
References buffer.
01779 { return buffer.size(); }
const std::string& OBT::TiXmlPrinter::Str | ( | ) | [inline] |
void OBT::TiXmlPrinter::DoIndent | ( | ) | [inline, private] |
void OBT::TiXmlPrinter::DoLineBreak | ( | ) | [inline, private] |
int OBT::TiXmlPrinter::depth [private] |
Definition at line 1796 of file OBTtinyxml.h.
Referenced by DoIndent(), VisitEnter(), and VisitExit().
bool OBT::TiXmlPrinter::simpleTextPrint [private] |
TIXML_STRING OBT::TiXmlPrinter::buffer [private] |
Definition at line 1798 of file OBTtinyxml.h.
Referenced by CStr(), DoIndent(), DoLineBreak(), Size(), Visit(), VisitEnter(), and VisitExit().
TIXML_STRING OBT::TiXmlPrinter::indent [private] |
Definition at line 1799 of file OBTtinyxml.h.
Referenced by DoIndent(), Indent(), SetIndent(), and SetStreamPrinting().
TIXML_STRING OBT::TiXmlPrinter::lineBreak [private] |
Definition at line 1800 of file OBTtinyxml.h.
Referenced by DoLineBreak(), LineBreak(), SetLineBreak(), and SetStreamPrinting().