test
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

std::string buffer
 
int depth
 
std::string indent
 
std::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 1736 of file tinyxml.h.

Constructor & Destructor Documentation

TiXmlPrinter::TiXmlPrinter ( )
inline

Definition at line 1739 of file tinyxml.h.

1739  : depth( 0 ), simpleTextPrint( false ),
1740  buffer(), indent( " " ), lineBreak( "\n" ) {}
std::string buffer
Definition: tinyxml.h:1794
std::string indent
Definition: tinyxml.h:1795
std::string lineBreak
Definition: tinyxml.h:1796
bool simpleTextPrint
Definition: tinyxml.h:1793

Member Function Documentation

const char* TiXmlPrinter::CStr ( )
inline

Return the result.

Definition at line 1774 of file tinyxml.h.

References buffer.

1774 { return buffer.c_str(); }
std::string buffer
Definition: tinyxml.h:1794
void TiXmlPrinter::DoIndent ( )
inlineprivate

Definition at line 1784 of file tinyxml.h.

References buffer, depth, i, and indent.

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

1784  {
1785  for( int i=0; i<depth; ++i )
1786  buffer += indent;
1787  }
int i
Definition: DBlmapReader.cc:9
std::string buffer
Definition: tinyxml.h:1794
std::string indent
Definition: tinyxml.h:1795
void TiXmlPrinter::DoLineBreak ( )
inlineprivate

Definition at line 1788 of file tinyxml.h.

References buffer, and lineBreak.

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

1788  {
1789  buffer += lineBreak;
1790  }
std::string buffer
Definition: tinyxml.h:1794
std::string lineBreak
Definition: tinyxml.h:1796
const char* TiXmlPrinter::Indent ( )
inline

Query the indention string.

Definition at line 1758 of file tinyxml.h.

References indent.

1758 { return indent.c_str(); }
std::string indent
Definition: tinyxml.h:1795
const char* TiXmlPrinter::LineBreak ( )
inline

Query the current line breaking string.

Definition at line 1765 of file tinyxml.h.

References lineBreak.

1765 { return lineBreak.c_str(); }
std::string lineBreak
Definition: tinyxml.h:1796
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 1756 of file tinyxml.h.

References indent.

1756 { indent = _indent ? _indent : "" ; }
std::string indent
Definition: tinyxml.h:1795
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 1763 of file tinyxml.h.

References lineBreak.

1763 { lineBreak = _lineBreak ? _lineBreak : ""; }
std::string lineBreak
Definition: tinyxml.h:1796
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 1770 of file tinyxml.h.

References indent, and lineBreak.

Referenced by operator<<().

1770  { indent = "";
1771  lineBreak = "";
1772  }
std::string indent
Definition: tinyxml.h:1795
std::string lineBreak
Definition: tinyxml.h:1796
size_t TiXmlPrinter::Size ( )
inline

Return the length of the result string.

Definition at line 1776 of file tinyxml.h.

References buffer.

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

Return the result.

Definition at line 1780 of file tinyxml.h.

Referenced by operator<<().

1780 { return buffer; }
std::string buffer
Definition: tinyxml.h:1794
bool TiXmlPrinter::Visit ( const TiXmlDeclaration )
virtual

Visit a declaration.

Reimplemented from TiXmlVisitor.

Definition at line 1877 of file tinyxml.cc.

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

1878 {
1879  DoIndent();
1880  declaration.Print( 0, 0, &buffer );
1881  DoLineBreak();
1882  return true;
1883 }
void DoLineBreak()
Definition: tinyxml.h:1788
void DoIndent()
Definition: tinyxml.h:1784
std::string buffer
Definition: tinyxml.h:1794
bool TiXmlPrinter::Visit ( const TiXmlText )
virtual

Visit a text node.

Reimplemented from TiXmlVisitor.

Definition at line 1849 of file tinyxml.cc.

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

1850 {
1851  if ( text.CDATA() )
1852  {
1853  DoIndent();
1854  buffer += "<![CDATA[";
1855  buffer += text.Value();
1856  buffer += "]]>";
1857  DoLineBreak();
1858  }
1859  else if ( simpleTextPrint )
1860  {
1861  TIXML_STRING str;
1862  TiXmlBase::EncodeString( text.ValueTStr(), &str );
1863  buffer += str;
1864  }
1865  else
1866  {
1867  DoIndent();
1868  TIXML_STRING str;
1869  TiXmlBase::EncodeString( text.ValueTStr(), &str );
1870  buffer += str;
1871  DoLineBreak();
1872  }
1873  return true;
1874 }
void DoLineBreak()
Definition: tinyxml.h:1788
static void EncodeString(const std::string &str, std::string *out)
Definition: tinyxml.cc:59
void DoIndent()
Definition: tinyxml.h:1784
std::string buffer
Definition: tinyxml.h:1794
tuple text
Definition: runonSM.py:42
#define TIXML_STRING
Definition: tinyxml.h:57
bool simpleTextPrint
Definition: tinyxml.h:1793
bool TiXmlPrinter::Visit ( const TiXmlComment )
virtual

Visit a comment node.

Reimplemented from TiXmlVisitor.

Definition at line 1886 of file tinyxml.cc.

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

1887 {
1888  DoIndent();
1889  buffer += "<!--";
1890  buffer += comment.Value();
1891  buffer += "-->";
1892  DoLineBreak();
1893  return true;
1894 }
void DoLineBreak()
Definition: tinyxml.h:1788
void DoIndent()
Definition: tinyxml.h:1784
std::string buffer
Definition: tinyxml.h:1794
#define comment(par)
Definition: vmac.h:161
bool TiXmlPrinter::Visit ( const TiXmlUnknown )
virtual

Visit an unknow node.

Reimplemented from TiXmlVisitor.

Definition at line 1897 of file tinyxml.cc.

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

1898 {
1899  DoIndent();
1900  buffer += "<";
1901  buffer += unknown.Value();
1902  buffer += ">";
1903  DoLineBreak();
1904  return true;
1905 }
void DoLineBreak()
Definition: tinyxml.h:1788
void DoIndent()
Definition: tinyxml.h:1784
std::string buffer
Definition: tinyxml.h:1794
bool TiXmlPrinter::VisitEnter ( const TiXmlDocument )
virtual

Visit a document.

Reimplemented from TiXmlVisitor.

Definition at line 1776 of file tinyxml.cc.

1777 {
1778  return true;
1779 }
bool TiXmlPrinter::VisitEnter ( const TiXmlElement ,
const TiXmlAttribute  
)
virtual

Visit an element.

Reimplemented from TiXmlVisitor.

Definition at line 1786 of file tinyxml.cc.

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

1787 {
1788  DoIndent();
1789  buffer += "<";
1790  buffer += element.Value();
1791 
1792  for( const TiXmlAttribute* attrib = firstAttribute; attrib; attrib = attrib->Next() )
1793  {
1794  buffer += " ";
1795  attrib->Print( 0, 0, &buffer );
1796  }
1797 
1798  if ( !element.FirstChild() )
1799  {
1800  buffer += " />";
1801  DoLineBreak();
1802  }
1803  else
1804  {
1805  buffer += ">";
1806  if ( element.FirstChild()->ToText()
1807  && element.LastChild() == element.FirstChild()
1808  && element.FirstChild()->ToText()->CDATA() == false )
1809  {
1810  simpleTextPrint = true;
1811  // no DoLineBreak()!
1812  }
1813  else
1814  {
1815  DoLineBreak();
1816  }
1817  }
1818  ++depth;
1819  return true;
1820 }
void DoLineBreak()
Definition: tinyxml.h:1788
void DoIndent()
Definition: tinyxml.h:1784
std::string buffer
Definition: tinyxml.h:1794
const TiXmlAttribute * Next() const
Get the next sibling attribute in the DOM. Returns null at end.
Definition: tinyxml.cc:1184
volatile std::atomic< bool > shutdown_flag false
bool simpleTextPrint
Definition: tinyxml.h:1793
bool TiXmlPrinter::VisitExit ( const TiXmlDocument )
virtual

Visit a document.

Reimplemented from TiXmlVisitor.

Definition at line 1781 of file tinyxml.cc.

1782 {
1783  return true;
1784 }
bool TiXmlPrinter::VisitExit ( const TiXmlElement )
virtual

Visit an element.

Reimplemented from TiXmlVisitor.

Definition at line 1823 of file tinyxml.cc.

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

1824 {
1825  --depth;
1826  if ( !element.FirstChild() )
1827  {
1828  // nothing.
1829  }
1830  else
1831  {
1832  if ( simpleTextPrint )
1833  {
1834  simpleTextPrint = false;
1835  }
1836  else
1837  {
1838  DoIndent();
1839  }
1840  buffer += "</";
1841  buffer += element.Value();
1842  buffer += ">";
1843  DoLineBreak();
1844  }
1845  return true;
1846 }
void DoLineBreak()
Definition: tinyxml.h:1788
void DoIndent()
Definition: tinyxml.h:1784
std::string buffer
Definition: tinyxml.h:1794
bool simpleTextPrint
Definition: tinyxml.h:1793

Member Data Documentation

std::string TiXmlPrinter::buffer
private

Definition at line 1794 of file tinyxml.h.

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

int TiXmlPrinter::depth
private
std::string TiXmlPrinter::indent
private

Definition at line 1795 of file tinyxml.h.

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

std::string TiXmlPrinter::lineBreak
private

Definition at line 1796 of file tinyxml.h.

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

bool TiXmlPrinter::simpleTextPrint
private

Definition at line 1793 of file tinyxml.h.

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