TiXmlDocument Class Reference

#include <tinyxml.h>

Inheritance diagram for TiXmlDocument:
TiXmlNode TiXmlBase

List of all members.

Public Member Functions

 TiXmlDocument ()
 Create an empty document, that has no name.
 TiXmlDocument (const char *documentName)
 Create a document with a name. The name of the document is also the filename of the xml.
 TiXmlDocument (const std::string &documentName)
 Constructor.
 TiXmlDocument (const TiXmlDocument &copy)
void operator= (const TiXmlDocument &copy)
virtual ~TiXmlDocument ()
bool LoadFile (TiXmlEncoding encoding=TIXML_DEFAULT_ENCODING)
bool SaveFile () const
 Save a file using the current document value. Returns true if successful.
bool LoadFile (const char *filename, TiXmlEncoding encoding=TIXML_DEFAULT_ENCODING)
 Load a file using the given filename. Returns true if successful.
bool SaveFile (const char *filename) const
 Save a file using the given filename. Returns true if successful.
bool LoadFile (FILE *, TiXmlEncoding encoding=TIXML_DEFAULT_ENCODING)
bool SaveFile (FILE *) const
 Save a file using the given FILE*. Returns true if successful.
bool LoadFile (const std::string &filename, TiXmlEncoding encoding=TIXML_DEFAULT_ENCODING)
bool SaveFile (const std::string &filename) const
 < STL std::string version.
virtual const char * Parse (const char *p, TiXmlParsingData *data=0, TiXmlEncoding encoding=TIXML_DEFAULT_ENCODING)
const TiXmlElementRootElement () const
TiXmlElementRootElement ()
bool Error () const
const char * ErrorDesc () const
 Contains a textual (english) description of the error if one occurs.
int ErrorId () const
int ErrorRow () const
int ErrorCol () const
 The column where the error occured. See ErrorRow().
void SetTabSize (int _tabsize)
int TabSize () const
void ClearError ()
void Print () const
virtual void Print (FILE *cfile, int depth=0) const
 Print this Document to a FILE stream.
void SetError (int err, const char *errorLocation, TiXmlParsingData *prevData, TiXmlEncoding encoding)
virtual const TiXmlDocumentToDocument () const
 Cast to a more defined type. Will return null not of the requested type.
virtual TiXmlDocumentToDocument ()
 Cast to a more defined type. Will return null not of the requested type.
virtual bool Accept (TiXmlVisitor *content) const

Protected Member Functions

virtual TiXmlNodeClone () const
virtual void StreamIn (std::istream *in, TIXML_STRING *tag)

Private Member Functions

void CopyTo (TiXmlDocument *target) const

Private Attributes

bool error
int errorId
TIXML_STRING errorDesc
int tabsize
TiXmlCursor errorLocation
bool useMicrosoftBOM

Detailed Description

Always the top level node. A document binds together all the XML pieces. It can be saved, loaded, and printed to the screen. The 'value' of a document node is the xml file name.

Definition at line 1364 of file tinyxml.h.


Constructor & Destructor Documentation

TiXmlDocument::TiXmlDocument (  ) 

Create an empty document, that has no name.

Definition at line 870 of file tinyxml.cpp.

References ClearError(), tabsize, and useMicrosoftBOM.

Referenced by Clone().

00870                              : TiXmlNode( TiXmlNode::DOCUMENT )
00871 {
00872         tabsize = 4;
00873         useMicrosoftBOM = false;
00874         ClearError();
00875 }

TiXmlDocument::TiXmlDocument ( const char *  documentName  ) 

Create a document with a name. The name of the document is also the filename of the xml.

Definition at line 877 of file tinyxml.cpp.

References ClearError(), tabsize, useMicrosoftBOM, and TiXmlNode::value.

00877                                                         : TiXmlNode( TiXmlNode::DOCUMENT )
00878 {
00879         tabsize = 4;
00880         useMicrosoftBOM = false;
00881         value = documentName;
00882         ClearError();
00883 }

TiXmlDocument::TiXmlDocument ( const std::string &  documentName  ) 

Constructor.

TiXmlDocument::TiXmlDocument ( const TiXmlDocument copy  ) 

Definition at line 897 of file tinyxml.cpp.

References CopyTo().

00897                                                         : TiXmlNode( TiXmlNode::DOCUMENT )
00898 {
00899         copy.CopyTo( this );
00900 }

virtual TiXmlDocument::~TiXmlDocument (  )  [inline, virtual]

Definition at line 1380 of file tinyxml.h.

01380 {}


Member Function Documentation

bool TiXmlDocument::Accept ( TiXmlVisitor content  )  const [virtual]

Walk the XML tree visiting this node and all of its children.

Implements TiXmlNode.

Definition at line 1142 of file tinyxml.cpp.

References TiXmlNode::FirstChild(), TiXmlVisitor::VisitEnter(), and TiXmlVisitor::VisitExit().

01143 {
01144         if ( visitor->VisitEnter( *this ) )
01145         {
01146                 for ( const TiXmlNode* node=FirstChild(); node; node=node->NextSibling() )
01147                 {
01148                         if ( !node->Accept( visitor ) )
01149                                 break;
01150                 }
01151         }
01152         return visitor->VisitExit( *this );
01153 }

void TiXmlDocument::ClearError (  )  [inline]

If you have handled the error, it can be reset with this call. The error state is automatically cleared if you Parse a new XML block.

Definition at line 1486 of file tinyxml.h.

References TiXmlCursor::col, error, errorDesc, errorId, errorLocation, and TiXmlCursor::row.

Referenced by Parse(), and TiXmlDocument().

01486                                                                         {       error = false; 
01487                                                                                                 errorId = 0; 
01488                                                                                                 errorDesc = ""; 
01489                                                                                                 errorLocation.row = errorLocation.col = 0; 
01490                                                                                                 //errorLocation.last = 0; 
01491                                                                                         }

TiXmlNode * TiXmlDocument::Clone (  )  const [protected, virtual]

Create an exact duplicate of this node and return it. The memory must be deleted by the caller.

Implements TiXmlNode.

Definition at line 1120 of file tinyxml.cpp.

References CopyTo(), and TiXmlDocument().

01121 {
01122         TiXmlDocument* clone = new TiXmlDocument();
01123         if ( !clone )
01124                 return 0;
01125 
01126         CopyTo( clone );
01127         return clone;
01128 }

void TiXmlDocument::CopyTo ( TiXmlDocument target  )  const [private]

Reimplemented from TiXmlNode.

Definition at line 1105 of file tinyxml.cpp.

References TiXmlNode::Clone(), error, errorDesc, TiXmlNode::firstChild, TiXmlNode::LinkEndChild(), and TiXmlNode::NextSibling().

Referenced by Clone(), operator=(), and TiXmlDocument().

01106 {
01107         TiXmlNode::CopyTo( target );
01108 
01109         target->error = error;
01110         target->errorDesc = errorDesc.c_str ();
01111 
01112         TiXmlNode* node = 0;
01113         for ( node = firstChild; node; node = node->NextSibling() )
01114         {
01115                 target->LinkEndChild( node->Clone() );
01116         }       
01117 }

bool TiXmlDocument::Error (  )  const [inline]

If an error occurs, Error will be set to true. Also,

  • The ErrorId() will contain the integer identifier of the error (not generally useful)
  • The ErrorDesc() method will return the name of the error. (very useful)
  • The ErrorRow() and ErrorCol() will return the location of the error (if known)

Definition at line 1435 of file tinyxml.h.

References error.

Referenced by LoadFile().

01435 { return error; }

int TiXmlDocument::ErrorCol (  )  const [inline]

The column where the error occured. See ErrorRow().

Definition at line 1453 of file tinyxml.h.

References TiXmlCursor::col, and errorLocation.

const char* TiXmlDocument::ErrorDesc (  )  const [inline]

Contains a textual (english) description of the error if one occurs.

Definition at line 1438 of file tinyxml.h.

References errorDesc.

01438 { return errorDesc.c_str (); }

int TiXmlDocument::ErrorId (  )  const [inline]

Generally, you probably want the error string ( ErrorDesc() ). But if you prefer the ErrorId, this function will fetch it.

Definition at line 1443 of file tinyxml.h.

References errorId.

01443 { return errorId; }

int TiXmlDocument::ErrorRow (  )  const [inline]

Returns the location (if known) of the error. The first column is column 1, and the first row is row 1. A value of 0 means the row and column wasn't applicable (memory errors, for example, have no row/column) or the parser lost the error. (An error in the error reporting, in that case.)

See also:
SetTabSize, Row, Column

Definition at line 1452 of file tinyxml.h.

References errorLocation, and TiXmlCursor::row.

01452 { return errorLocation.row+1; }

bool TiXmlDocument::LoadFile ( const std::string &  filename,
TiXmlEncoding  encoding = TIXML_DEFAULT_ENCODING 
) [inline]
Parameters:
encoding STL std::string version.

Definition at line 1403 of file tinyxml.h.

References LoadFile().

01404         {
01405 //              StringToBuffer f( filename );
01406 //              return ( f.buffer && LoadFile( f.buffer, encoding ));
01407                 return LoadFile( filename.c_str(), encoding );
01408         }

bool TiXmlDocument::LoadFile ( FILE *  file,
TiXmlEncoding  encoding = TIXML_DEFAULT_ENCODING 
)

Load a file using the given FILE*. Returns true if successful. Note that this method doesn't stream - the entire object pointed at by the FILE* will be interpreted as an XML file. TinyXML doesn't stream in XML from the current file location. Streaming may be added in the future.

Definition at line 959 of file tinyxml.cpp.

References TiXmlNode::Clear(), TiXmlCursor::Clear(), Error(), TiXmlBase::location, Parse(), SetError(), TIXML_ENCODING_UNKNOWN, TiXmlBase::TIXML_ERROR_DOCUMENT_EMPTY, TiXmlBase::TIXML_ERROR_OPENING_FILE, and TIXML_STRING.

00960 {
00961         if ( !file ) 
00962         {
00963                 SetError( TIXML_ERROR_OPENING_FILE, 0, 0, TIXML_ENCODING_UNKNOWN );
00964                 return false;
00965         }
00966 
00967         // Delete the existing data:
00968         Clear();
00969         location.Clear();
00970 
00971         // Get the file size, so we can pre-allocate the string. HUGE speed impact.
00972         long length = 0;
00973         fseek( file, 0, SEEK_END );
00974         length = ftell( file );
00975         fseek( file, 0, SEEK_SET );
00976 
00977         // Strange case, but good to handle up front.
00978         if ( length == 0 )
00979         {
00980                 SetError( TIXML_ERROR_DOCUMENT_EMPTY, 0, 0, TIXML_ENCODING_UNKNOWN );
00981                 return false;
00982         }
00983 
00984         // If we have a file, assume it is all one big XML file, and read it in.
00985         // The document parser may decide the document ends sooner than the entire file, however.
00986         TIXML_STRING data;
00987         data.reserve( length );
00988 
00989         // Subtle bug here. TinyXml did use fgets. But from the XML spec:
00990         // 2.11 End-of-Line Handling
00991         // <snip>
00992         // <quote>
00993         // ...the XML processor MUST behave as if it normalized all line breaks in external 
00994         // parsed entities (including the document entity) on input, before parsing, by translating 
00995         // both the two-character sequence #xD #xA and any #xD that is not followed by #xA to 
00996         // a single #xA character.
00997         // </quote>
00998         //
00999         // It is not clear fgets does that, and certainly isn't clear it works cross platform. 
01000         // Generally, you expect fgets to translate from the convention of the OS to the c/unix
01001         // convention, and not work generally.
01002 
01003         /*
01004         while( fgets( buf, sizeof(buf), file ) )
01005         {
01006                 data += buf;
01007         }
01008         */
01009 
01010         char* buf = new char[ length+1 ];
01011         buf[0] = 0;
01012 
01013         if ( fread( buf, length, 1, file ) != 1 ) {
01014                 delete [] buf;
01015                 SetError( TIXML_ERROR_OPENING_FILE, 0, 0, TIXML_ENCODING_UNKNOWN );
01016                 return false;
01017         }
01018 
01019         const char* lastPos = buf;
01020         const char* p = buf;
01021 
01022         buf[length] = 0;
01023         while( *p ) {
01024                 assert( p < (buf+length) );
01025                 if ( *p == 0xa ) {
01026                         // Newline character. No special rules for this. Append all the characters
01027                         // since the last string, and include the newline.
01028                         data.append( lastPos, (p-lastPos+1) );  // append, include the newline
01029                         ++p;                                                                    // move past the newline
01030                         lastPos = p;                                                    // and point to the new buffer (may be 0)
01031                         assert( p <= (buf+length) );
01032                 }
01033                 else if ( *p == 0xd ) {
01034                         // Carriage return. Append what we have so far, then
01035                         // handle moving forward in the buffer.
01036                         if ( (p-lastPos) > 0 ) {
01037                                 data.append( lastPos, p-lastPos );      // do not add the CR
01038                         }
01039                         data += (char)0xa;                                              // a proper newline
01040 
01041                         if ( *(p+1) == 0xa ) {
01042                                 // Carriage return - new line sequence
01043                                 p += 2;
01044                                 lastPos = p;
01045                                 assert( p <= (buf+length) );
01046                         }
01047                         else {
01048                                 // it was followed by something else...that is presumably characters again.
01049                                 ++p;
01050                                 lastPos = p;
01051                                 assert( p <= (buf+length) );
01052                         }
01053                 }
01054                 else {
01055                         ++p;
01056                 }
01057         }
01058         // Handle any left over characters.
01059         if ( p-lastPos ) {
01060                 data.append( lastPos, p-lastPos );
01061         }               
01062         delete [] buf;
01063         buf = 0;
01064 
01065         Parse( data.c_str(), 0, encoding );
01066 
01067         if (  Error() )
01068         return false;
01069     else
01070                 return true;
01071 }

bool TiXmlDocument::LoadFile ( const char *  filename,
TiXmlEncoding  encoding = TIXML_DEFAULT_ENCODING 
)

Load a file using the given filename. Returns true if successful.

Definition at line 931 of file tinyxml.cpp.

References LoadFile(), SetError(), TIXML_ENCODING_UNKNOWN, TiXmlBase::TIXML_ERROR_OPENING_FILE, TIXML_STRING, and TiXmlNode::value.

00932 {
00933         // There was a really terrifying little bug here. The code:
00934         //              value = filename
00935         // in the STL case, cause the assignment method of the std::string to
00936         // be called. What is strange, is that the std::string had the same
00937         // address as it's c_str() method, and so bad things happen. Looks
00938         // like a bug in the Microsoft STL implementation.
00939         // Add an extra string to avoid the crash.
00940         TIXML_STRING filename( _filename );
00941         value = filename;
00942 
00943         // reading in binary mode so that tinyxml can normalize the EOL
00944         FILE* file = fopen( value.c_str (), "rb" );     
00945 
00946         if ( file )
00947         {
00948                 bool result = LoadFile( file, encoding );
00949                 fclose( file );
00950                 return result;
00951         }
00952         else
00953         {
00954                 SetError( TIXML_ERROR_OPENING_FILE, 0, 0, TIXML_ENCODING_UNKNOWN );
00955                 return false;
00956         }
00957 }

bool TiXmlDocument::LoadFile ( TiXmlEncoding  encoding = TIXML_DEFAULT_ENCODING  ) 

Load a file using the current document value. Returns true if successful. Will delete any existing document data before loading.

Definition at line 910 of file tinyxml.cpp.

References TiXmlNode::Value().

Referenced by LoadFile().

00911 {
00912         // See STL_STRING_BUG below.
00913         //StringToBuffer buf( value );
00914 
00915         return LoadFile( Value(), encoding );
00916 }

void TiXmlDocument::operator= ( const TiXmlDocument copy  ) 

Reimplemented from TiXmlNode.

Definition at line 903 of file tinyxml.cpp.

References TiXmlNode::Clear(), and CopyTo().

00904 {
00905         Clear();
00906         copy.CopyTo( this );
00907 }

const char * TiXmlDocument::Parse ( const char *  p,
TiXmlParsingData data = 0,
TiXmlEncoding  encoding = TIXML_DEFAULT_ENCODING 
) [virtual]

Parse the given null terminated block of xml data. Passing in an encoding to this method (either TIXML_ENCODING_LEGACY or TIXML_ENCODING_UTF8 will force TinyXml to use that encoding, regardless of what TinyXml might otherwise try to detect.

Implements TiXmlBase.

Definition at line 704 of file tinyxmlparser.cpp.

References TiXmlCursor::Clear(), ClearError(), TiXmlCursor::col, TiXmlParsingData::cursor, TiXmlParsingData::Cursor(), TiXmlDeclaration::Encoding(), TiXmlNode::firstChild, TiXmlNode::Identify(), TiXmlNode::LinkEndChild(), TiXmlBase::location, TiXmlBase::Parse(), TiXmlCursor::row, SetError(), TiXmlBase::SkipWhiteSpace(), TiXmlBase::StringEqual(), TabSize(), TIXML_ENCODING_LEGACY, TIXML_ENCODING_UNKNOWN, TIXML_ENCODING_UTF8, TiXmlBase::TIXML_ERROR_DOCUMENT_EMPTY, TIXML_UTF_LEAD_0, TIXML_UTF_LEAD_1, TIXML_UTF_LEAD_2, TiXmlNode::ToDeclaration(), and useMicrosoftBOM.

Referenced by LoadFile().

00705 {
00706         ClearError();
00707 
00708         // Parse away, at the document level. Since a document
00709         // contains nothing but other tags, most of what happens
00710         // here is skipping white space.
00711         if ( !p || !*p )
00712         {
00713                 SetError( TIXML_ERROR_DOCUMENT_EMPTY, 0, 0, TIXML_ENCODING_UNKNOWN );
00714                 return 0;
00715         }
00716 
00717         // Note that, for a document, this needs to come
00718         // before the while space skip, so that parsing
00719         // starts from the pointer we are given.
00720         location.Clear();
00721         if ( prevData )
00722         {
00723                 location.row = prevData->cursor.row;
00724                 location.col = prevData->cursor.col;
00725         }
00726         else
00727         {
00728                 location.row = 0;
00729                 location.col = 0;
00730         }
00731         TiXmlParsingData data( p, TabSize(), location.row, location.col );
00732         location = data.Cursor();
00733 
00734         if ( encoding == TIXML_ENCODING_UNKNOWN )
00735         {
00736                 // Check for the Microsoft UTF-8 lead bytes.
00737                 const unsigned char* pU = (const unsigned char*)p;
00738                 if (    *(pU+0) && *(pU+0) == TIXML_UTF_LEAD_0
00739                          && *(pU+1) && *(pU+1) == TIXML_UTF_LEAD_1
00740                          && *(pU+2) && *(pU+2) == TIXML_UTF_LEAD_2 )
00741                 {
00742                         encoding = TIXML_ENCODING_UTF8;
00743                         useMicrosoftBOM = true;
00744                 }
00745         }
00746 
00747     p = SkipWhiteSpace( p, encoding );
00748         if ( !p )
00749         {
00750                 SetError( TIXML_ERROR_DOCUMENT_EMPTY, 0, 0, TIXML_ENCODING_UNKNOWN );
00751                 return 0;
00752         }
00753 
00754         while ( p && *p )
00755         {
00756                 TiXmlNode* node = Identify( p, encoding );
00757                 if ( node )
00758                 {
00759                         p = node->Parse( p, &data, encoding );
00760                         LinkEndChild( node );
00761                 }
00762                 else
00763                 {
00764                         break;
00765                 }
00766 
00767                 // Did we get encoding info?
00768                 if (    encoding == TIXML_ENCODING_UNKNOWN
00769                          && node->ToDeclaration() )
00770                 {
00771                         TiXmlDeclaration* dec = node->ToDeclaration();
00772                         const char* enc = dec->Encoding();
00773                         assert( enc );
00774 
00775                         if ( *enc == 0 )
00776                                 encoding = TIXML_ENCODING_UTF8;
00777                         else if ( StringEqual( enc, "UTF-8", true, TIXML_ENCODING_UNKNOWN ) )
00778                                 encoding = TIXML_ENCODING_UTF8;
00779                         else if ( StringEqual( enc, "UTF8", true, TIXML_ENCODING_UNKNOWN ) )
00780                                 encoding = TIXML_ENCODING_UTF8; // incorrect, but be nice
00781                         else 
00782                                 encoding = TIXML_ENCODING_LEGACY;
00783                 }
00784 
00785                 p = SkipWhiteSpace( p, encoding );
00786         }
00787 
00788         // Was this empty?
00789         if ( !firstChild ) {
00790                 SetError( TIXML_ERROR_DOCUMENT_EMPTY, 0, 0, encoding );
00791                 return 0;
00792         }
00793 
00794         // All is well.
00795         return p;
00796 }

void TiXmlDocument::Print ( FILE *  cfile,
int  depth = 0 
) const [virtual]

Print this Document to a FILE stream.

Implements TiXmlBase.

Definition at line 1131 of file tinyxml.cpp.

References TiXmlNode::FirstChild(), and TiXmlAttribute::Print().

01132 {
01133         assert( cfile );
01134         for ( const TiXmlNode* node=FirstChild(); node; node=node->NextSibling() )
01135         {
01136                 node->Print( cfile, depth );
01137                 fprintf( cfile, "\n" );
01138         }
01139 }

void TiXmlDocument::Print ( void   )  const [inline]

Write the document to standard out using formatted printing ("pretty print").

Definition at line 1494 of file tinyxml.h.

References Print().

Referenced by Print(), and SaveFile().

01494 { Print( stdout, 0 ); }

TiXmlElement* TiXmlDocument::RootElement (  )  [inline]

Definition at line 1428 of file tinyxml.h.

References TiXmlNode::FirstChildElement().

01428 { return FirstChildElement(); }

const TiXmlElement* TiXmlDocument::RootElement (  )  const [inline]

Get the root element -- the only top level element -- of the document. In well formed XML, there should only be one. TinyXml is tolerant of multiple elements at the document level.

Definition at line 1427 of file tinyxml.h.

References TiXmlNode::FirstChildElement().

01427 { return FirstChildElement(); }

bool TiXmlDocument::SaveFile ( const std::string &  filename  )  const [inline]

< STL std::string version.

Definition at line 1409 of file tinyxml.h.

References SaveFile().

01410         {
01411 //              StringToBuffer f( filename );
01412 //              return ( f.buffer && SaveFile( f.buffer ));
01413                 return SaveFile( filename.c_str() );
01414         }

bool TiXmlDocument::SaveFile ( FILE *  fp  )  const

Save a file using the given FILE*. Returns true if successful.

Definition at line 1088 of file tinyxml.cpp.

References Print(), TIXML_UTF_LEAD_0, TIXML_UTF_LEAD_1, TIXML_UTF_LEAD_2, and useMicrosoftBOM.

01089 {
01090         if ( useMicrosoftBOM ) 
01091         {
01092                 const unsigned char TIXML_UTF_LEAD_0 = 0xefU;
01093                 const unsigned char TIXML_UTF_LEAD_1 = 0xbbU;
01094                 const unsigned char TIXML_UTF_LEAD_2 = 0xbfU;
01095 
01096                 fputc( TIXML_UTF_LEAD_0, fp );
01097                 fputc( TIXML_UTF_LEAD_1, fp );
01098                 fputc( TIXML_UTF_LEAD_2, fp );
01099         }
01100         Print( fp, 0 );
01101         return (ferror(fp) == 0);
01102 }

bool TiXmlDocument::SaveFile ( const char *  filename  )  const

Save a file using the given filename. Returns true if successful.

Definition at line 1074 of file tinyxml.cpp.

References SaveFile().

01075 {
01076         // The old c stuff lives on...
01077         FILE* fp = fopen( filename, "w" );
01078         if ( fp )
01079         {
01080                 bool result = SaveFile( fp );
01081                 fclose( fp );
01082                 return result;
01083         }
01084         return false;
01085 }

bool TiXmlDocument::SaveFile (  )  const

Save a file using the current document value. Returns true if successful.

Definition at line 919 of file tinyxml.cpp.

References TiXmlNode::Value().

Referenced by SaveFile().

00920 {
00921         // See STL_STRING_BUG below.
00922 //      StringToBuffer buf( value );
00923 //
00924 //      if ( buf.buffer && SaveFile( buf.buffer ) )
00925 //              return true;
00926 //
00927 //      return false;
00928         return SaveFile( Value() );
00929 }

void TiXmlDocument::SetError ( int  err,
const char *  errorLocation,
TiXmlParsingData prevData,
TiXmlEncoding  encoding 
)
void TiXmlDocument::SetTabSize ( int  _tabsize  )  [inline]

SetTabSize() allows the error reporting functions (ErrorRow() and ErrorCol()) to report the correct values for row and column. It does not change the output or input in any way.

By calling this method, with a tab size greater than 0, the row and column of each node and attribute is stored when the file is loaded. Very useful for tracking the DOM back in to the source file.

The tab size is required for calculating the location of nodes. If not set, the default of 4 is used. The tabsize is set per document. Setting the tabsize to 0 disables row/column tracking.

Note that row and column tracking is not supported when using operator>>.

The tab size needs to be enabled before the parse or load. Correct usage:

		TiXmlDocument doc;
		doc.SetTabSize( 8 );
		doc.Load( "myfile.xml" );
		
See also:
Row, Column

Definition at line 1479 of file tinyxml.h.

References tabsize.

01479 { tabsize = _tabsize; }

void TiXmlDocument::StreamIn ( std::istream *  in,
TIXML_STRING *  tag 
) [protected, virtual]

Implements TiXmlNode.

Definition at line 641 of file tinyxmlparser.cpp.

References TiXmlNode::Identify(), SetError(), TiXmlNode::StreamIn(), TiXmlBase::StreamTo(), TIXML_DEFAULT_ENCODING, TIXML_ENCODING_UNKNOWN, TiXmlBase::TIXML_ERROR, TiXmlBase::TIXML_ERROR_EMBEDDED_NULL, TiXmlBase::TIXML_ERROR_PARSING_EMPTY, and TiXmlNode::ToElement().

00642 {
00643         // The basic issue with a document is that we don't know what we're
00644         // streaming. Read something presumed to be a tag (and hope), then
00645         // identify it, and call the appropriate stream method on the tag.
00646         //
00647         // This "pre-streaming" will never read the closing ">" so the
00648         // sub-tag can orient itself.
00649 
00650         if ( !StreamTo( in, '<', tag ) ) 
00651         {
00652                 SetError( TIXML_ERROR_PARSING_EMPTY, 0, 0, TIXML_ENCODING_UNKNOWN );
00653                 return;
00654         }
00655 
00656         while ( in->good() )
00657         {
00658                 int tagIndex = (int) tag->length();
00659                 while ( in->good() && in->peek() != '>' )
00660                 {
00661                         int c = in->get();
00662                         if ( c <= 0 )
00663                         {
00664                                 SetError( TIXML_ERROR_EMBEDDED_NULL, 0, 0, TIXML_ENCODING_UNKNOWN );
00665                                 break;
00666                         }
00667                         (*tag) += (char) c;
00668                 }
00669 
00670                 if ( in->good() )
00671                 {
00672                         // We now have something we presume to be a node of 
00673                         // some sort. Identify it, and call the node to
00674                         // continue streaming.
00675                         TiXmlNode* node = Identify( tag->c_str() + tagIndex, TIXML_DEFAULT_ENCODING );
00676 
00677                         if ( node )
00678                         {
00679                                 node->StreamIn( in, tag );
00680                                 bool isElement = node->ToElement() != 0;
00681                                 delete node;
00682                                 node = 0;
00683 
00684                                 // If this is the root element, we're done. Parsing will be
00685                                 // done by the >> operator.
00686                                 if ( isElement )
00687                                 {
00688                                         return;
00689                                 }
00690                         }
00691                         else
00692                         {
00693                                 SetError( TIXML_ERROR, 0, 0, TIXML_ENCODING_UNKNOWN );
00694                                 return;
00695                         }
00696                 }
00697         }
00698         // We should have returned sooner.
00699         SetError( TIXML_ERROR, 0, 0, TIXML_ENCODING_UNKNOWN );
00700 }

int TiXmlDocument::TabSize (  )  const [inline]

Definition at line 1481 of file tinyxml.h.

References tabsize.

Referenced by Parse().

01481 { return tabsize; }

virtual TiXmlDocument* TiXmlDocument::ToDocument (  )  [inline, virtual]

Cast to a more defined type. Will return null not of the requested type.

Reimplemented from TiXmlNode.

Definition at line 1508 of file tinyxml.h.

virtual const TiXmlDocument* TiXmlDocument::ToDocument (  )  const [inline, virtual]

Cast to a more defined type. Will return null not of the requested type.

Reimplemented from TiXmlNode.

Definition at line 1507 of file tinyxml.h.


Member Data Documentation

bool TiXmlDocument::error [private]

Definition at line 1524 of file tinyxml.h.

Referenced by ClearError(), CopyTo(), Error(), and SetError().

TIXML_STRING TiXmlDocument::errorDesc [private]

Definition at line 1526 of file tinyxml.h.

Referenced by ClearError(), CopyTo(), ErrorDesc(), and SetError().

int TiXmlDocument::errorId [private]

Definition at line 1525 of file tinyxml.h.

Referenced by ClearError(), ErrorId(), and SetError().

Definition at line 1528 of file tinyxml.h.

Referenced by ClearError(), ErrorCol(), ErrorRow(), and SetError().

int TiXmlDocument::tabsize [private]

Definition at line 1527 of file tinyxml.h.

Referenced by SetTabSize(), TabSize(), and TiXmlDocument().

Definition at line 1529 of file tinyxml.h.

Referenced by Parse(), SaveFile(), and TiXmlDocument().


The documentation for this class was generated from the following files:

Generated on 3 Dec 2018 for loon by  doxygen 1.6.1