CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
List of all members | Public Member Functions | Private Member Functions | Private Attributes
TiXmlPrinter Class Reference

#include <tinyxml.h>

Inheritance diagram for TiXmlPrinter:
TiXmlVisitor

Public Member Functions

const char * CStr ()
 Return the result. More...
 
const char * Indent ()
 Query the indention string. More...
 
const char * LineBreak ()
 Query the current line breaking string. More...
 
void SetIndent (const char *_indent)
 
void SetLineBreak (const char *_lineBreak)
 
void SetStreamPrinting ()
 
size_t Size ()
 Return the length of the result string. More...
 
const std::string & Str ()
 Return the result. More...
 
 TiXmlPrinter ()
 
virtual bool Visit (const TiXmlDeclaration &declaration)
 Visit a declaration. More...
 
virtual bool Visit (const TiXmlText &text)
 Visit a text node. More...
 
virtual bool Visit (const TiXmlComment &comment)
 Visit a comment node. More...
 
virtual bool Visit (const TiXmlUnknown &unknown)
 Visit an unknow node. More...
 
virtual bool VisitEnter (const TiXmlDocument &doc)
 Visit a document. More...
 
virtual bool VisitEnter (const TiXmlElement &element, const TiXmlAttribute *firstAttribute)
 Visit an element. More...
 
virtual bool VisitExit (const TiXmlDocument &doc)
 Visit a document. More...
 
virtual bool VisitExit (const TiXmlElement &element)
 Visit an element. More...
 
- Public Member Functions inherited from TiXmlVisitor
virtual ~TiXmlVisitor ()
 

Private Member Functions

void DoIndent ()
 
void DoLineBreak ()
 

Private Attributes

TIXML_STRING buffer
 
int depth
 
TIXML_STRING indent
 
TIXML_STRING lineBreak
 
bool simpleTextPrint
 

Detailed Description

Print to memory functionality. The TiXmlPrinter is useful when you need to:

  1. Print to memory (especially in non-STL mode)
  2. Control formatting (line endings, etc.)

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 1734 of file tinyxml.h.

Constructor & Destructor Documentation

TiXmlPrinter::TiXmlPrinter ( )
inline

Definition at line 1737 of file tinyxml.h.

1737  : depth( 0 ), simpleTextPrint( false ),
1738  buffer(), indent( " " ), lineBreak( "\n" ) {}
TIXML_STRING lineBreak
Definition: tinyxml.h:1794
TIXML_STRING buffer
Definition: tinyxml.h:1792
TIXML_STRING indent
Definition: tinyxml.h:1793
bool simpleTextPrint
Definition: tinyxml.h:1791

Member Function Documentation

const char* TiXmlPrinter::CStr ( )
inline

Return the result.

Definition at line 1772 of file tinyxml.h.

References buffer.

1772 { return buffer.c_str(); }
TIXML_STRING buffer
Definition: tinyxml.h:1792
void TiXmlPrinter::DoIndent ( )
inlineprivate

Definition at line 1782 of file tinyxml.h.

References buffer, depth, i, and indent.

Referenced by Visit(), VisitEnter(), and VisitExit().

1782  {
1783  for( int i=0; i<depth; ++i )
1784  buffer += indent;
1785  }
int i
Definition: DBlmapReader.cc:9
TIXML_STRING buffer
Definition: tinyxml.h:1792
TIXML_STRING indent
Definition: tinyxml.h:1793
void TiXmlPrinter::DoLineBreak ( )
inlineprivate

Definition at line 1786 of file tinyxml.h.

References buffer, and lineBreak.

Referenced by Visit(), VisitEnter(), and VisitExit().

1786  {
1787  buffer += lineBreak;
1788  }
TIXML_STRING lineBreak
Definition: tinyxml.h:1794
TIXML_STRING buffer
Definition: tinyxml.h:1792
const char* TiXmlPrinter::Indent ( )
inline

Query the indention string.

Definition at line 1756 of file tinyxml.h.

References indent.

1756 { return indent.c_str(); }
TIXML_STRING indent
Definition: tinyxml.h:1793
const char* TiXmlPrinter::LineBreak ( )
inline

Query the current line breaking string.

Definition at line 1763 of file tinyxml.h.

References lineBreak.

1763 { return lineBreak.c_str(); }
TIXML_STRING lineBreak
Definition: tinyxml.h:1794
void 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 1754 of file tinyxml.h.

References indent.

1754 { indent = _indent ? _indent : "" ; }
TIXML_STRING indent
Definition: tinyxml.h:1793
void 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 1761 of file tinyxml.h.

References lineBreak.

1761 { lineBreak = _lineBreak ? _lineBreak : ""; }
TIXML_STRING lineBreak
Definition: tinyxml.h:1794
void 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 1768 of file tinyxml.h.

References indent, and lineBreak.

Referenced by operator<<().

1768  { indent = "";
1769  lineBreak = "";
1770  }
TIXML_STRING lineBreak
Definition: tinyxml.h:1794
TIXML_STRING indent
Definition: tinyxml.h:1793
size_t TiXmlPrinter::Size ( )
inline

Return the length of the result string.

Definition at line 1774 of file tinyxml.h.

References buffer.

1774 { return buffer.size(); }
TIXML_STRING buffer
Definition: tinyxml.h:1792
const std::string& TiXmlPrinter::Str ( )
inline

Return the result.

Definition at line 1778 of file tinyxml.h.

Referenced by operator<<().

1778 { return buffer; }
TIXML_STRING buffer
Definition: tinyxml.h:1792
bool TiXmlPrinter::Visit ( const TiXmlDeclaration )
virtual

Visit a declaration.

Reimplemented from TiXmlVisitor.

Definition at line 1861 of file tinyxml.cc.

References buffer, DoIndent(), DoLineBreak(), and TiXmlDeclaration::Print().

1862 {
1863  DoIndent();
1864  declaration.Print( 0, 0, &buffer );
1865  DoLineBreak();
1866  return true;
1867 }
void DoLineBreak()
Definition: tinyxml.h:1786
void DoIndent()
Definition: tinyxml.h:1782
TIXML_STRING buffer
Definition: tinyxml.h:1792
bool TiXmlPrinter::Visit ( const TiXmlText )
virtual

Visit a text node.

Reimplemented from TiXmlVisitor.

Definition at line 1833 of file tinyxml.cc.

References buffer, TiXmlText::CDATA(), DoIndent(), DoLineBreak(), TiXmlBase::EncodeString(), simpleTextPrint, TIXML_STRING, TiXmlNode::Value(), and TiXmlNode::ValueTStr().

1834 {
1835  if ( text.CDATA() )
1836  {
1837  DoIndent();
1838  buffer += "<![CDATA[";
1839  buffer += text.Value();
1840  buffer += "]]>";
1841  DoLineBreak();
1842  }
1843  else if ( simpleTextPrint )
1844  {
1845  TIXML_STRING str;
1846  TiXmlBase::EncodeString( text.ValueTStr(), &str );
1847  buffer += str;
1848  }
1849  else
1850  {
1851  DoIndent();
1852  TIXML_STRING str;
1853  TiXmlBase::EncodeString( text.ValueTStr(), &str );
1854  buffer += str;
1855  DoLineBreak();
1856  }
1857  return true;
1858 }
void DoLineBreak()
Definition: tinyxml.h:1786
void DoIndent()
Definition: tinyxml.h:1782
TIXML_STRING buffer
Definition: tinyxml.h:1792
tuple text
Definition: runonSM.py:42
static void EncodeString(const TIXML_STRING &str, TIXML_STRING *out)
Definition: tinyxml.cc:53
#define TIXML_STRING
Definition: tinyxml.h:51
bool simpleTextPrint
Definition: tinyxml.h:1791
bool TiXmlPrinter::Visit ( const TiXmlComment )
virtual

Visit a comment node.

Reimplemented from TiXmlVisitor.

Definition at line 1870 of file tinyxml.cc.

References buffer, DoIndent(), DoLineBreak(), and TiXmlNode::Value().

1871 {
1872  DoIndent();
1873  buffer += "<!--";
1874  buffer += comment.Value();
1875  buffer += "-->";
1876  DoLineBreak();
1877  return true;
1878 }
void DoLineBreak()
Definition: tinyxml.h:1786
void DoIndent()
Definition: tinyxml.h:1782
TIXML_STRING buffer
Definition: tinyxml.h:1792
#define comment(par)
Definition: vmac.h:162
bool TiXmlPrinter::Visit ( const TiXmlUnknown )
virtual

Visit an unknow node.

Reimplemented from TiXmlVisitor.

Definition at line 1881 of file tinyxml.cc.

References buffer, DoIndent(), DoLineBreak(), and TiXmlNode::Value().

1882 {
1883  DoIndent();
1884  buffer += "<";
1885  buffer += unknown.Value();
1886  buffer += ">";
1887  DoLineBreak();
1888  return true;
1889 }
void DoLineBreak()
Definition: tinyxml.h:1786
void DoIndent()
Definition: tinyxml.h:1782
TIXML_STRING buffer
Definition: tinyxml.h:1792
bool TiXmlPrinter::VisitEnter ( const TiXmlDocument )
virtual

Visit a document.

Reimplemented from TiXmlVisitor.

Definition at line 1760 of file tinyxml.cc.

1761 {
1762  return true;
1763 }
bool TiXmlPrinter::VisitEnter ( const TiXmlElement ,
const TiXmlAttribute  
)
virtual

Visit an element.

Reimplemented from TiXmlVisitor.

Definition at line 1770 of file tinyxml.cc.

References buffer, TiXmlText::CDATA(), depth, DoIndent(), DoLineBreak(), funct::false, TiXmlNode::FirstChild(), TiXmlNode::LastChild(), TiXmlAttribute::Next(), simpleTextPrint, TiXmlNode::ToText(), and TiXmlNode::Value().

1771 {
1772  DoIndent();
1773  buffer += "<";
1774  buffer += element.Value();
1775 
1776  for( const TiXmlAttribute* attrib = firstAttribute; attrib; attrib = attrib->Next() )
1777  {
1778  buffer += " ";
1779  attrib->Print( 0, 0, &buffer );
1780  }
1781 
1782  if ( !element.FirstChild() )
1783  {
1784  buffer += " />";
1785  DoLineBreak();
1786  }
1787  else
1788  {
1789  buffer += ">";
1790  if ( element.FirstChild()->ToText()
1791  && element.LastChild() == element.FirstChild()
1792  && element.FirstChild()->ToText()->CDATA() == false )
1793  {
1794  simpleTextPrint = true;
1795  // no DoLineBreak()!
1796  }
1797  else
1798  {
1799  DoLineBreak();
1800  }
1801  }
1802  ++depth;
1803  return true;
1804 }
void DoLineBreak()
Definition: tinyxml.h:1786
void DoIndent()
Definition: tinyxml.h:1782
TIXML_STRING buffer
Definition: tinyxml.h:1792
const TiXmlAttribute * Next() const
Get the next sibling attribute in the DOM. Returns null at end.
Definition: tinyxml.cc:1176
bool simpleTextPrint
Definition: tinyxml.h:1791
bool TiXmlPrinter::VisitExit ( const TiXmlDocument )
virtual

Visit a document.

Reimplemented from TiXmlVisitor.

Definition at line 1765 of file tinyxml.cc.

1766 {
1767  return true;
1768 }
bool TiXmlPrinter::VisitExit ( const TiXmlElement )
virtual

Visit an element.

Reimplemented from TiXmlVisitor.

Definition at line 1807 of file tinyxml.cc.

References buffer, depth, DoIndent(), DoLineBreak(), TiXmlNode::FirstChild(), simpleTextPrint, and TiXmlNode::Value().

1808 {
1809  --depth;
1810  if ( !element.FirstChild() )
1811  {
1812  // nothing.
1813  }
1814  else
1815  {
1816  if ( simpleTextPrint )
1817  {
1818  simpleTextPrint = false;
1819  }
1820  else
1821  {
1822  DoIndent();
1823  }
1824  buffer += "</";
1825  buffer += element.Value();
1826  buffer += ">";
1827  DoLineBreak();
1828  }
1829  return true;
1830 }
void DoLineBreak()
Definition: tinyxml.h:1786
void DoIndent()
Definition: tinyxml.h:1782
TIXML_STRING buffer
Definition: tinyxml.h:1792
bool simpleTextPrint
Definition: tinyxml.h:1791

Member Data Documentation

TIXML_STRING TiXmlPrinter::buffer
private

Definition at line 1792 of file tinyxml.h.

Referenced by CStr(), DoIndent(), DoLineBreak(), Size(), Visit(), VisitEnter(), and VisitExit().

int TiXmlPrinter::depth
private

Definition at line 1790 of file tinyxml.h.

Referenced by DoIndent(), VisitEnter(), and VisitExit().

TIXML_STRING TiXmlPrinter::indent
private

Definition at line 1793 of file tinyxml.h.

Referenced by DoIndent(), Indent(), SetIndent(), and SetStreamPrinting().

TIXML_STRING TiXmlPrinter::lineBreak
private

Definition at line 1794 of file tinyxml.h.

Referenced by DoLineBreak(), LineBreak(), SetLineBreak(), and SetStreamPrinting().

bool TiXmlPrinter::simpleTextPrint
private

Definition at line 1791 of file tinyxml.h.

Referenced by Visit(), VisitEnter(), and VisitExit().