#include <tinyxml.h>
Inheritance diagram for TiXmlPrinter:

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) |
| const char * | Indent () |
| Query the indention string. | |
| void | SetLineBreak (const char *_lineBreak) |
| const char * | LineBreak () |
| Query the current line breaking string. | |
| void | SetStreamPrinting () |
| 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 () |
Private Attributes | |
| int | depth |
| bool | simpleTextPrint |
| TIXML_STRING | buffer |
| TIXML_STRING | indent |
| TIXML_STRING | lineBreak |
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 1712 of file tinyxml.h.
|
|
Definition at line 1715 of file tinyxml.h. References buffer, depth, indent, lineBreak, and simpleTextPrint. 01715 : depth( 0 ), simpleTextPrint( false ), 01716 buffer(), indent( " " ), lineBreak( "\n" ) {}
|
|
|
Return the result.
Definition at line 1750 of file tinyxml.h. References buffer. 01750 { return buffer.c_str(); }
|
|
|
Definition at line 1760 of file tinyxml.h. References buffer. Referenced by Visit(), VisitEnter(), and VisitExit(). 01760 {
01761 for( int i=0; i<depth; ++i )
01762 buffer += indent;
01763 }
|
|
|
Definition at line 1764 of file tinyxml.h. References buffer. Referenced by Visit(), VisitEnter(), and VisitExit(). 01764 {
01765 buffer += lineBreak;
01766 }
|
|
|
Query the indention string.
Definition at line 1734 of file tinyxml.h. References indent. 01734 { return indent.c_str(); }
|
|
|
Query the current line breaking string.
Definition at line 1741 of file tinyxml.h. References lineBreak. 01741 { return lineBreak.c_str(); }
|
|
|
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 1732 of file tinyxml.h. References indent. 01732 { indent = _indent ? _indent : "" ; }
|
|
|
Set the line breaking string. By default set to newline ( Definition at line 1739 of file tinyxml.h. References lineBreak. 01739 { lineBreak = _lineBreak ? _lineBreak : ""; }
|
|
|
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 1746 of file tinyxml.h. References indent, and lineBreak. Referenced by operator<<().
|
|
|
Return the length of the result string.
Definition at line 1752 of file tinyxml.h. References buffer. 01752 { return buffer.size(); }
|
|
|
Return the result.
Definition at line 1756 of file tinyxml.h. Referenced by operator<<(). 01756 { return buffer; }
|
|
|
Visit an unknow node.
Reimplemented from TiXmlVisitor. Definition at line 1857 of file tinyxml.cpp. References buffer, DoIndent(), DoLineBreak(), and TiXmlNode::Value(). 01858 {
01859 DoIndent();
01860 buffer += "<";
01861 buffer += unknown.Value();
01862 buffer += ">";
01863 DoLineBreak();
01864 return true;
01865 }
|
|
|
Visit a comment node.
Reimplemented from TiXmlVisitor. Definition at line 1846 of file tinyxml.cpp. References buffer, DoIndent(), DoLineBreak(), and TiXmlNode::Value(). 01847 {
01848 DoIndent();
01849 buffer += "<!--";
01850 buffer += comment.Value();
01851 buffer += "-->";
01852 DoLineBreak();
01853 return true;
01854 }
|
|
|
Visit a text node.
Reimplemented from TiXmlVisitor. Definition at line 1813 of file tinyxml.cpp. References buffer, TiXmlText::CDATA(), DoIndent(), DoLineBreak(), and TiXmlNode::Value(). 01814 {
01815 if ( text.CDATA() )
01816 {
01817 DoIndent();
01818 buffer += "<![CDATA[";
01819 buffer += text.Value();
01820 buffer += "]]>";
01821 DoLineBreak();
01822 }
01823 else if ( simpleTextPrint )
01824 {
01825 buffer += text.Value();
01826 }
01827 else
01828 {
01829 DoIndent();
01830 buffer += text.Value();
01831 DoLineBreak();
01832 }
01833 return true;
01834 }
|
|
|
Visit a declaration.
Reimplemented from TiXmlVisitor. Definition at line 1837 of file tinyxml.cpp. References buffer, DoIndent(), DoLineBreak(), and TiXmlDeclaration::Print(). 01838 {
01839 DoIndent();
01840 declaration.Print( 0, 0, &buffer );
01841 DoLineBreak();
01842 return true;
01843 }
|
|
||||||||||||
|
Visit an element.
Reimplemented from TiXmlVisitor. Definition at line 1750 of file tinyxml.cpp. References buffer, TiXmlText::CDATA(), DoIndent(), DoLineBreak(), TiXmlNode::FirstChild(), TiXmlNode::LastChild(), TiXmlAttribute::Next(), TiXmlAttribute::Print(), simpleTextPrint, TiXmlNode::ToText(), and TiXmlNode::Value(). 01751 {
01752 DoIndent();
01753 buffer += "<";
01754 buffer += element.Value();
01755
01756 for( const TiXmlAttribute* attrib = firstAttribute; attrib; attrib = attrib->Next() )
01757 {
01758 buffer += " ";
01759 attrib->Print( 0, 0, &buffer );
01760 }
01761
01762 if ( !element.FirstChild() )
01763 {
01764 buffer += " />";
01765 DoLineBreak();
01766 }
01767 else
01768 {
01769 buffer += ">";
01770 if ( element.FirstChild()->ToText()
01771 && element.LastChild() == element.FirstChild()
01772 && element.FirstChild()->ToText()->CDATA() == false )
01773 {
01774 simpleTextPrint = true;
01775 // no DoLineBreak()!
01776 }
01777 else
01778 {
01779 DoLineBreak();
01780 }
01781 }
01782 ++depth;
01783 return true;
01784 }
|
|
|
Visit a document.
Reimplemented from TiXmlVisitor. Definition at line 1740 of file tinyxml.cpp. 01741 {
01742 return true;
01743 }
|
|
|
Visit an element.
Reimplemented from TiXmlVisitor. Definition at line 1787 of file tinyxml.cpp. References buffer, DoIndent(), DoLineBreak(), TiXmlNode::FirstChild(), simpleTextPrint, and TiXmlNode::Value(). 01788 {
01789 --depth;
01790 if ( !element.FirstChild() )
01791 {
01792 // nothing.
01793 }
01794 else
01795 {
01796 if ( simpleTextPrint )
01797 {
01798 simpleTextPrint = false;
01799 }
01800 else
01801 {
01802 DoIndent();
01803 }
01804 buffer += "</";
01805 buffer += element.Value();
01806 buffer += ">";
01807 DoLineBreak();
01808 }
01809 return true;
01810 }
|
|
|
Visit a document.
Reimplemented from TiXmlVisitor. Definition at line 1745 of file tinyxml.cpp. 01746 {
01747 return true;
01748 }
|
|
|
Definition at line 1770 of file tinyxml.h. Referenced by CStr(), DoIndent(), DoLineBreak(), Size(), TiXmlPrinter(), Visit(), VisitEnter(), and VisitExit(). |
|
|
Definition at line 1768 of file tinyxml.h. Referenced by TiXmlPrinter(). |
|
|
Definition at line 1771 of file tinyxml.h. Referenced by Indent(), SetIndent(), SetStreamPrinting(), and TiXmlPrinter(). |
|
|
Definition at line 1772 of file tinyxml.h. Referenced by LineBreak(), SetLineBreak(), SetStreamPrinting(), and TiXmlPrinter(). |
|
|
Definition at line 1769 of file tinyxml.h. Referenced by TiXmlPrinter(), VisitEnter(), and VisitExit(). |
1.3.9.1