#include <OBTtinyxml.h>
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 ©) | |
void | operator= (const TiXmlDocument ©) |
virtual | ~TiXmlDocument () |
bool | LoadFile (TiXmlEncoding encoding=TIXML_DEFAULT_ENCODING) |
Load a file using the current document value. | |
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) |
Load a file using the given FILE*. | |
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) |
Parse the given null terminated block of xml data. | |
const TiXmlElement * | RootElement () const |
Get the root element -- the only top level element -- of the document. | |
TiXmlElement * | RootElement () |
bool | Error () const |
If an error occurs, Error will be set to true. | |
const char * | ErrorDesc () const |
Contains a textual (english) description of the error if one occurs. | |
int | ErrorId () const |
Generally, you probably want the error string ( ErrorDesc() ). | |
int | ErrorRow () const |
Returns the location (if known) of the error. | |
int | ErrorCol () const |
The column where the error occured. See ErrorRow(). | |
void | SetTabSize (int _tabsize) |
SetTabSize() allows the error reporting functions (ErrorRow() and ErrorCol()) to report the correct values for row and column. | |
int | TabSize () const |
void | ClearError () |
If you have handled the error, it can be reset with this call. | |
void | Print () const |
Write the document to standard out using formatted printing ("pretty print"). | |
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 TiXmlDocument * | ToDocument () const |
Cast to a more defined type. Will return null not of the requested type. | |
virtual TiXmlDocument * | ToDocument () |
Cast to a more defined type. Will return null not of the requested type. | |
virtual bool | Accept (TiXmlVisitor *content) const |
Walk the XML tree visiting this node and all of its children. | |
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 ©) | |
void | operator= (const TiXmlDocument ©) |
virtual | ~TiXmlDocument () |
bool | LoadFile (TiXmlEncoding encoding=TIXML_DEFAULT_ENCODING) |
Load a file using the current document value. | |
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) |
Load a file using the given FILE*. | |
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) |
Parse the given null terminated block of xml data. | |
const TiXmlElement * | RootElement () const |
Get the root element -- the only top level element -- of the document. | |
TiXmlElement * | RootElement () |
bool | Error () const |
If an error occurs, Error will be set to true. | |
const char * | ErrorDesc () const |
Contains a textual (english) description of the error if one occurs. | |
int | ErrorId () const |
Generally, you probably want the error string ( ErrorDesc() ). | |
int | ErrorRow () const |
Returns the location (if known) of the error. | |
int | ErrorCol () const |
The column where the error occured. See ErrorRow(). | |
void | SetTabSize (int _tabsize) |
SetTabSize() allows the error reporting functions (ErrorRow() and ErrorCol()) to report the correct values for row and column. | |
int | TabSize () const |
void | ClearError () |
If you have handled the error, it can be reset with this call. | |
void | Print () const |
Write the document to standard out using formatted printing ("pretty print"). | |
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 TiXmlDocument * | ToDocument () const |
Cast to a more defined type. Will return null not of the requested type. | |
virtual TiXmlDocument * | ToDocument () |
Cast to a more defined type. Will return null not of the requested type. | |
virtual bool | Accept (TiXmlVisitor *content) const |
Walk the XML tree visiting this node and all of its children. | |
Protected Member Functions | |
virtual TiXmlNode * | Clone () const |
Create an exact duplicate of this node and return it. | |
virtual void | StreamIn (std::istream *in, TIXML_STRING *tag) |
virtual TiXmlNode * | Clone () const |
Create an exact duplicate of this node and return it. | |
virtual void | StreamIn (std::istream *in, TIXML_STRING *tag) |
Private Member Functions | |
void | CopyTo (TiXmlDocument *target) const |
void | CopyTo (TiXmlDocument *target) const |
Private Attributes | |
bool | error |
int | errorId |
TIXML_STRING | errorDesc |
int | tabsize |
TiXmlCursor | errorLocation |
bool | useMicrosoftBOM |
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 1392 of file OBTtinyxml.h.
OBT::TiXmlDocument::TiXmlDocument | ( | ) |
Create an empty document, that has no name.
Definition at line 886 of file OBTtinyxml.cpp.
References ClearError(), tabsize, and useMicrosoftBOM.
Referenced by Clone().
00886 : TiXmlNode( TiXmlNode::DOCUMENT ) 00887 { 00888 tabsize = 4; 00889 useMicrosoftBOM = false; 00890 ClearError(); 00891 }
OBT::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 893 of file OBTtinyxml.cpp.
References ClearError(), tabsize, useMicrosoftBOM, and OBT::TiXmlNode::value.
00893 : TiXmlNode( TiXmlNode::DOCUMENT ) 00894 { 00895 tabsize = 4; 00896 useMicrosoftBOM = false; 00897 value = documentName; 00898 ClearError(); 00899 }
OBT::TiXmlDocument::TiXmlDocument | ( | const std::string & | documentName | ) |
Constructor.
Definition at line 903 of file OBTtinyxml.cpp.
References ClearError(), tabsize, useMicrosoftBOM, and OBT::TiXmlNode::value.
00903 : TiXmlNode( TiXmlNode::DOCUMENT ) 00904 { 00905 tabsize = 4; 00906 useMicrosoftBOM = false; 00907 value = documentName; 00908 ClearError(); 00909 }
OBT::TiXmlDocument::TiXmlDocument | ( | const TiXmlDocument & | copy | ) |
Definition at line 913 of file OBTtinyxml.cpp.
References CopyTo().
00913 : TiXmlNode( TiXmlNode::DOCUMENT ) 00914 { 00915 copy.CopyTo( this ); 00916 }
virtual OBT::TiXmlDocument::~TiXmlDocument | ( | ) | [inline, virtual] |
OBT::TiXmlDocument::TiXmlDocument | ( | ) |
Create an empty document, that has no name.
OBT::TiXmlDocument::TiXmlDocument | ( | const char * | documentName | ) |
Create a document with a name. The name of the document is also the filename of the xml.
OBT::TiXmlDocument::TiXmlDocument | ( | const std::string & | documentName | ) |
Constructor.
OBT::TiXmlDocument::TiXmlDocument | ( | const TiXmlDocument & | copy | ) |
virtual OBT::TiXmlDocument::~TiXmlDocument | ( | ) | [inline, virtual] |
void OBT::TiXmlDocument::operator= | ( | const TiXmlDocument & | copy | ) |
Definition at line 919 of file OBTtinyxml.cpp.
References OBT::TiXmlNode::Clear(), and CopyTo().
00920 { 00921 Clear(); 00922 copy.CopyTo( this ); 00923 }
bool OBT::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 926 of file OBTtinyxml.cpp.
References OBT::TiXmlNode::Value().
Referenced by LoadFile(), and OBT::XMLConfigurationFileParser::XMLConfigurationFileParser().
00927 { 00928 // See STL_STRING_BUG below. 00929 //StringToBuffer buf( value ); 00930 00931 return LoadFile( Value(), encoding ); 00932 }
bool OBT::TiXmlDocument::SaveFile | ( | ) | const |
Save a file using the current document value. Returns true if successful.
Definition at line 935 of file OBTtinyxml.cpp.
References OBT::TiXmlNode::Value().
Referenced by SaveFile().
00936 { 00937 // See STL_STRING_BUG below. 00938 // StringToBuffer buf( value ); 00939 // 00940 // if ( buf.buffer && SaveFile( buf.buffer ) ) 00941 // return true; 00942 // 00943 // return false; 00944 return SaveFile( Value() ); 00945 }
bool OBT::TiXmlDocument::LoadFile | ( | const char * | filename, | |
TiXmlEncoding | encoding = TIXML_DEFAULT_ENCODING | |||
) |
Load a file using the given filename. Returns true if successful.
Definition at line 947 of file OBTtinyxml.cpp.
References LoadFile(), SetError(), OBT::TIXML_ENCODING_UNKNOWN, OBT::TiXmlBase::TIXML_ERROR_OPENING_FILE, TIXML_STRING, OBT::TiXmlFOpen(), and OBT::TiXmlNode::value.
00948 { 00949 // There was a really terrifying little bug here. The code: 00950 // value = filename 00951 // in the STL case, cause the assignment method of the std::string to 00952 // be called. What is strange, is that the std::string had the same 00953 // address as it's c_str() method, and so bad things happen. Looks 00954 // like a bug in the Microsoft STL implementation. 00955 // Add an extra string to avoid the crash. 00956 TIXML_STRING filename( _filename ); 00957 value = filename; 00958 00959 // reading in binary mode so that tinyxml can normalize the EOL 00960 FILE* file = TiXmlFOpen( value.c_str (), "rb" ); 00961 00962 if ( file ) 00963 { 00964 bool result = LoadFile( file, encoding ); 00965 fclose( file ); 00966 return result; 00967 } 00968 else 00969 { 00970 SetError( TIXML_ERROR_OPENING_FILE, 0, 0, TIXML_ENCODING_UNKNOWN ); 00971 return false; 00972 } 00973 }
bool OBT::TiXmlDocument::SaveFile | ( | const char * | filename | ) | const |
Save a file using the given filename. Returns true if successful.
Definition at line 1090 of file OBTtinyxml.cpp.
References SaveFile(), and OBT::TiXmlFOpen().
01091 { 01092 // The old c stuff lives on... 01093 FILE* fp = TiXmlFOpen( filename, "w" ); 01094 if ( fp ) 01095 { 01096 bool result = SaveFile( fp ); 01097 fclose( fp ); 01098 return result; 01099 } 01100 return false; 01101 }
bool OBT::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 975 of file OBTtinyxml.cpp.
References OBT::TiXmlCursor::Clear(), OBT::TiXmlNode::Clear(), Error(), OBT::TiXmlBase::location, Parse(), SetError(), OBT::TIXML_ENCODING_UNKNOWN, OBT::TiXmlBase::TIXML_ERROR_DOCUMENT_EMPTY, OBT::TiXmlBase::TIXML_ERROR_OPENING_FILE, and TIXML_STRING.
00976 { 00977 if ( !file ) 00978 { 00979 SetError( TIXML_ERROR_OPENING_FILE, 0, 0, TIXML_ENCODING_UNKNOWN ); 00980 return false; 00981 } 00982 00983 // Delete the existing data: 00984 Clear(); 00985 location.Clear(); 00986 00987 // Get the file size, so we can pre-allocate the string. HUGE speed impact. 00988 long length = 0; 00989 fseek( file, 0, SEEK_END ); 00990 length = ftell( file ); 00991 fseek( file, 0, SEEK_SET ); 00992 00993 // Strange case, but good to handle up front. 00994 if ( length <= 0 ) 00995 { 00996 SetError( TIXML_ERROR_DOCUMENT_EMPTY, 0, 0, TIXML_ENCODING_UNKNOWN ); 00997 return false; 00998 } 00999 01000 // If we have a file, assume it is all one big XML file, and read it in. 01001 // The document parser may decide the document ends sooner than the entire file, however. 01002 TIXML_STRING data; 01003 data.reserve( length ); 01004 01005 // Subtle bug here. TinyXml did use fgets. But from the XML spec: 01006 // 2.11 End-of-Line Handling 01007 // <snip> 01008 // <quote> 01009 // ...the XML processor MUST behave as if it normalized all line breaks in external 01010 // parsed entities (including the document entity) on input, before parsing, by translating 01011 // both the two-character sequence #xD #xA and any #xD that is not followed by #xA to 01012 // a single #xA character. 01013 // </quote> 01014 // 01015 // It is not clear fgets does that, and certainly isn't clear it works cross platform. 01016 // Generally, you expect fgets to translate from the convention of the OS to the c/unix 01017 // convention, and not work generally. 01018 01019 /* 01020 while( fgets( buf, sizeof(buf), file ) ) 01021 { 01022 data += buf; 01023 } 01024 */ 01025 01026 char* buf = new char[ length+1 ]; 01027 buf[0] = 0; 01028 01029 if ( fread( buf, length, 1, file ) != 1 ) { 01030 delete [] buf; 01031 SetError( TIXML_ERROR_OPENING_FILE, 0, 0, TIXML_ENCODING_UNKNOWN ); 01032 return false; 01033 } 01034 01035 const char* lastPos = buf; 01036 const char* p = buf; 01037 01038 buf[length] = 0; 01039 while( *p ) { 01040 assert( p < (buf+length) ); 01041 if ( *p == 0xa ) { 01042 // Newline character. No special rules for this. Append all the characters 01043 // since the last string, and include the newline. 01044 data.append( lastPos, (p-lastPos+1) ); // append, include the newline 01045 ++p; // move past the newline 01046 lastPos = p; // and point to the new buffer (may be 0) 01047 assert( p <= (buf+length) ); 01048 } 01049 else if ( *p == 0xd ) { 01050 // Carriage return. Append what we have so far, then 01051 // handle moving forward in the buffer. 01052 if ( (p-lastPos) > 0 ) { 01053 data.append( lastPos, p-lastPos ); // do not add the CR 01054 } 01055 data += (char)0xa; // a proper newline 01056 01057 if ( *(p+1) == 0xa ) { 01058 // Carriage return - new line sequence 01059 p += 2; 01060 lastPos = p; 01061 assert( p <= (buf+length) ); 01062 } 01063 else { 01064 // it was followed by something else...that is presumably characters again. 01065 ++p; 01066 lastPos = p; 01067 assert( p <= (buf+length) ); 01068 } 01069 } 01070 else { 01071 ++p; 01072 } 01073 } 01074 // Handle any left over characters. 01075 if ( p-lastPos ) { 01076 data.append( lastPos, p-lastPos ); 01077 } 01078 delete [] buf; 01079 buf = 0; 01080 01081 Parse( data.c_str(), 0, encoding ); 01082 01083 if ( Error() ) 01084 return false; 01085 else 01086 return true; 01087 }
bool OBT::TiXmlDocument::SaveFile | ( | FILE * | fp | ) | const |
Save a file using the given FILE*. Returns true if successful.
Definition at line 1104 of file OBTtinyxml.cpp.
References Print(), OBT::TIXML_UTF_LEAD_0, OBT::TIXML_UTF_LEAD_1, OBT::TIXML_UTF_LEAD_2, and useMicrosoftBOM.
01105 { 01106 if ( useMicrosoftBOM ) 01107 { 01108 const unsigned char TIXML_UTF_LEAD_0 = 0xefU; 01109 const unsigned char TIXML_UTF_LEAD_1 = 0xbbU; 01110 const unsigned char TIXML_UTF_LEAD_2 = 0xbfU; 01111 01112 fputc( TIXML_UTF_LEAD_0, fp ); 01113 fputc( TIXML_UTF_LEAD_1, fp ); 01114 fputc( TIXML_UTF_LEAD_2, fp ); 01115 } 01116 Print( fp, 0 ); 01117 return (ferror(fp) == 0); 01118 }
bool OBT::TiXmlDocument::LoadFile | ( | const std::string & | filename, | |
TiXmlEncoding | encoding = TIXML_DEFAULT_ENCODING | |||
) | [inline] |
encoding | STL std::string version. |
Definition at line 1431 of file OBTtinyxml.h.
01432 { 01433 // StringToBuffer f( filename ); 01434 // return ( f.buffer && LoadFile( f.buffer, encoding )); 01435 return LoadFile( filename.c_str(), encoding ); 01436 }
bool OBT::TiXmlDocument::SaveFile | ( | const std::string & | filename | ) | const [inline] |
< STL std::string version.
Definition at line 1437 of file OBTtinyxml.h.
01438 { 01439 // StringToBuffer f( filename ); 01440 // return ( f.buffer && SaveFile( f.buffer )); 01441 return SaveFile( filename.c_str() ); 01442 }
const char * OBT::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 OBT::TiXmlBase.
Definition at line 706 of file OBTtinyxmlparser.cpp.
References OBT::TiXmlCursor::Clear(), ClearError(), OBT::TiXmlCursor::col, OBT::TiXmlParsingData::Cursor(), OBT::TiXmlParsingData::cursor, OBT::TiXmlDeclaration::Encoding(), OBT::TiXmlNode::firstChild, OBT::TiXmlNode::Identify(), OBT::TiXmlNode::LinkEndChild(), OBT::TiXmlBase::location, OBT::TiXmlBase::Parse(), OBT::TiXmlCursor::row, SetError(), OBT::TiXmlBase::SkipWhiteSpace(), OBT::TiXmlBase::StringEqual(), TabSize(), OBT::TIXML_ENCODING_LEGACY, OBT::TIXML_ENCODING_UNKNOWN, OBT::TIXML_ENCODING_UTF8, OBT::TiXmlBase::TIXML_ERROR_DOCUMENT_EMPTY, OBT::TIXML_UTF_LEAD_0, OBT::TIXML_UTF_LEAD_1, OBT::TIXML_UTF_LEAD_2, OBT::TiXmlNode::ToDeclaration(), and useMicrosoftBOM.
Referenced by LoadFile().
00707 { 00708 ClearError(); 00709 00710 // Parse away, at the document level. Since a document 00711 // contains nothing but other tags, most of what happens 00712 // here is skipping white space. 00713 if ( !p || !*p ) 00714 { 00715 SetError( TIXML_ERROR_DOCUMENT_EMPTY, 0, 0, TIXML_ENCODING_UNKNOWN ); 00716 return 0; 00717 } 00718 00719 // Note that, for a document, this needs to come 00720 // before the while space skip, so that parsing 00721 // starts from the pointer we are given. 00722 location.Clear(); 00723 if ( prevData ) 00724 { 00725 location.row = prevData->cursor.row; 00726 location.col = prevData->cursor.col; 00727 } 00728 else 00729 { 00730 location.row = 0; 00731 location.col = 0; 00732 } 00733 TiXmlParsingData data( p, TabSize(), location.row, location.col ); 00734 location = data.Cursor(); 00735 00736 if ( encoding == TIXML_ENCODING_UNKNOWN ) 00737 { 00738 // Check for the Microsoft UTF-8 lead bytes. 00739 const unsigned char* pU = (const unsigned char*)p; 00740 if ( *(pU+0) && *(pU+0) == TIXML_UTF_LEAD_0 00741 && *(pU+1) && *(pU+1) == TIXML_UTF_LEAD_1 00742 && *(pU+2) && *(pU+2) == TIXML_UTF_LEAD_2 ) 00743 { 00744 encoding = TIXML_ENCODING_UTF8; 00745 useMicrosoftBOM = true; 00746 } 00747 } 00748 00749 p = SkipWhiteSpace( p, encoding ); 00750 if ( !p ) 00751 { 00752 SetError( TIXML_ERROR_DOCUMENT_EMPTY, 0, 0, TIXML_ENCODING_UNKNOWN ); 00753 return 0; 00754 } 00755 00756 while ( p && *p ) 00757 { 00758 TiXmlNode* node = Identify( p, encoding ); 00759 if ( node ) 00760 { 00761 p = node->Parse( p, &data, encoding ); 00762 LinkEndChild( node ); 00763 } 00764 else 00765 { 00766 break; 00767 } 00768 00769 // Did we get encoding info? 00770 if ( encoding == TIXML_ENCODING_UNKNOWN 00771 && node->ToDeclaration() ) 00772 { 00773 TiXmlDeclaration* dec = node->ToDeclaration(); 00774 const char* enc = dec->Encoding(); 00775 assert( enc ); 00776 00777 if ( *enc == 0 ) 00778 encoding = TIXML_ENCODING_UTF8; 00779 else if ( StringEqual( enc, "UTF-8", true, TIXML_ENCODING_UNKNOWN ) ) 00780 encoding = TIXML_ENCODING_UTF8; 00781 else if ( StringEqual( enc, "UTF8", true, TIXML_ENCODING_UNKNOWN ) ) 00782 encoding = TIXML_ENCODING_UTF8; // incorrect, but be nice 00783 else 00784 encoding = TIXML_ENCODING_LEGACY; 00785 } 00786 00787 p = SkipWhiteSpace( p, encoding ); 00788 } 00789 00790 // Was this empty? 00791 if ( !firstChild ) { 00792 SetError( TIXML_ERROR_DOCUMENT_EMPTY, 0, 0, encoding ); 00793 return 0; 00794 } 00795 00796 // All is well. 00797 return p; 00798 }
const TiXmlElement* OBT::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 1455 of file OBTtinyxml.h.
Referenced by OBT::XMLConfigurationFileParser::XMLConfigurationFileParser().
01455 { return FirstChildElement(); }
TiXmlElement* OBT::TiXmlDocument::RootElement | ( | ) | [inline] |
bool OBT::TiXmlDocument::Error | ( | ) | const [inline] |
If an error occurs, Error will be set to true.
Also,
Definition at line 1463 of file OBTtinyxml.h.
Referenced by LoadFile().
01463 { return error; }
const char* OBT::TiXmlDocument::ErrorDesc | ( | ) | const [inline] |
Contains a textual (english) description of the error if one occurs.
Definition at line 1466 of file OBTtinyxml.h.
01466 { return errorDesc.c_str (); }
int OBT::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 1471 of file OBTtinyxml.h.
01471 { return errorId; }
int OBT::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.)
Definition at line 1480 of file OBTtinyxml.h.
01480 { return errorLocation.row+1; }
int OBT::TiXmlDocument::ErrorCol | ( | ) | const [inline] |
void OBT::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" );
Definition at line 1507 of file OBTtinyxml.h.
01507 { tabsize = _tabsize; }
int OBT::TiXmlDocument::TabSize | ( | ) | const [inline] |
void OBT::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 1514 of file OBTtinyxml.h.
Referenced by Parse(), and TiXmlDocument().
01514 { error = false; 01515 errorId = 0; 01516 errorDesc = ""; 01517 errorLocation.row = errorLocation.col = 0; 01518 //errorLocation.last = 0; 01519 }
void OBT::TiXmlDocument::Print | ( | ) | const [inline] |
Write the document to standard out using formatted printing ("pretty print").
Definition at line 1522 of file OBTtinyxml.h.
Referenced by Print(), and SaveFile().
01522 { Print( stdout, 0 ); }
void OBT::TiXmlDocument::Print | ( | FILE * | cfile, | |
int | depth = 0 | |||
) | const [virtual] |
Print this Document to a FILE stream.
Implements OBT::TiXmlBase.
Definition at line 1151 of file OBTtinyxml.cpp.
References OBT::TiXmlNode::FirstChild(), and OBT::TiXmlNode::NextSibling().
01152 { 01153 assert( cfile ); 01154 for ( const TiXmlNode* node=FirstChild(); node; node=node->NextSibling() ) 01155 { 01156 node->Print( cfile, depth ); 01157 fprintf( cfile, "\n" ); 01158 } 01159 }
void OBT::TiXmlDocument::SetError | ( | int | err, | |
const char * | errorLocation, | |||
TiXmlParsingData * | prevData, | |||
TiXmlEncoding | encoding | |||
) |
Definition at line 800 of file OBTtinyxmlparser.cpp.
References OBT::TiXmlCursor::Clear(), OBT::TiXmlParsingData::Cursor(), error, errorDesc, errorId, errorLocation, OBT::TiXmlBase::errorString, OBT::TiXmlParsingData::Stamp(), and OBT::TiXmlBase::TIXML_ERROR_STRING_COUNT.
Referenced by OBT::TiXmlNode::Identify(), OBT::TiXmlNode::InsertAfterChild(), OBT::TiXmlNode::InsertBeforeChild(), OBT::TiXmlNode::InsertEndChild(), OBT::TiXmlNode::LinkEndChild(), LoadFile(), OBT::TiXmlDeclaration::Parse(), OBT::TiXmlText::Parse(), OBT::TiXmlAttribute::Parse(), OBT::TiXmlComment::Parse(), OBT::TiXmlUnknown::Parse(), OBT::TiXmlElement::Parse(), Parse(), OBT::TiXmlElement::ReadValue(), OBT::TiXmlElement::SetAttribute(), OBT::TiXmlDeclaration::StreamIn(), OBT::TiXmlText::StreamIn(), OBT::TiXmlComment::StreamIn(), OBT::TiXmlUnknown::StreamIn(), OBT::TiXmlElement::StreamIn(), and StreamIn().
00801 { 00802 // The first error in a chain is more accurate - don't set again! 00803 if ( error ) 00804 return; 00805 00806 assert( err > 0 && err < TIXML_ERROR_STRING_COUNT ); 00807 error = true; 00808 errorId = err; 00809 errorDesc = errorString[ errorId ]; 00810 00811 errorLocation.Clear(); 00812 if ( pError && data ) 00813 { 00814 data->Stamp( pError, encoding ); 00815 errorLocation = data->Cursor(); 00816 } 00817 }
virtual const TiXmlDocument* OBT::TiXmlDocument::ToDocument | ( | ) | const [inline, virtual] |
Cast to a more defined type. Will return null not of the requested type.
Reimplemented from OBT::TiXmlNode.
Definition at line 1535 of file OBTtinyxml.h.
virtual TiXmlDocument* OBT::TiXmlDocument::ToDocument | ( | ) | [inline, virtual] |
Cast to a more defined type. Will return null not of the requested type.
Reimplemented from OBT::TiXmlNode.
Definition at line 1536 of file OBTtinyxml.h.
bool OBT::TiXmlDocument::Accept | ( | TiXmlVisitor * | content | ) | const [virtual] |
Walk the XML tree visiting this node and all of its children.
Implements OBT::TiXmlNode.
Definition at line 1162 of file OBTtinyxml.cpp.
References OBT::TiXmlNode::FirstChild(), OBT::TiXmlNode::NextSibling(), OBT::TiXmlVisitor::VisitEnter(), and OBT::TiXmlVisitor::VisitExit().
01163 { 01164 if ( visitor->VisitEnter( *this ) ) 01165 { 01166 for ( const TiXmlNode* node=FirstChild(); node; node=node->NextSibling() ) 01167 { 01168 if ( !node->Accept( visitor ) ) 01169 break; 01170 } 01171 } 01172 return visitor->VisitExit( *this ); 01173 }
TiXmlNode * OBT::TiXmlDocument::Clone | ( | ) | const [protected, virtual] |
Create an exact duplicate of this node and return it.
The memory must be deleted by the caller.
Implements OBT::TiXmlNode.
Definition at line 1140 of file OBTtinyxml.cpp.
References CopyTo(), and TiXmlDocument().
01141 { 01142 TiXmlDocument* clone = new TiXmlDocument(); 01143 if ( !clone ) 01144 return 0; 01145 01146 CopyTo( clone ); 01147 return clone; 01148 }
void OBT::TiXmlDocument::StreamIn | ( | std::istream * | in, | |
TIXML_STRING * | tag | |||
) | [protected, virtual] |
Implements OBT::TiXmlNode.
Definition at line 643 of file OBTtinyxmlparser.cpp.
References OBT::TiXmlNode::Identify(), SetError(), OBT::TiXmlNode::StreamIn(), OBT::TiXmlBase::StreamTo(), OBT::TIXML_DEFAULT_ENCODING, OBT::TIXML_ENCODING_UNKNOWN, OBT::TiXmlBase::TIXML_ERROR, OBT::TiXmlBase::TIXML_ERROR_EMBEDDED_NULL, OBT::TiXmlBase::TIXML_ERROR_PARSING_EMPTY, and OBT::TiXmlNode::ToElement().
00644 { 00645 // The basic issue with a document is that we don't know what we're 00646 // streaming. Read something presumed to be a tag (and hope), then 00647 // identify it, and call the appropriate stream method on the tag. 00648 // 00649 // This "pre-streaming" will never read the closing ">" so the 00650 // sub-tag can orient itself. 00651 00652 if ( !StreamTo( in, '<', tag ) ) 00653 { 00654 SetError( TIXML_ERROR_PARSING_EMPTY, 0, 0, TIXML_ENCODING_UNKNOWN ); 00655 return; 00656 } 00657 00658 while ( in->good() ) 00659 { 00660 int tagIndex = (int) tag->length(); 00661 while ( in->good() && in->peek() != '>' ) 00662 { 00663 int c = in->get(); 00664 if ( c <= 0 ) 00665 { 00666 SetError( TIXML_ERROR_EMBEDDED_NULL, 0, 0, TIXML_ENCODING_UNKNOWN ); 00667 break; 00668 } 00669 (*tag) += (char) c; 00670 } 00671 00672 if ( in->good() ) 00673 { 00674 // We now have something we presume to be a node of 00675 // some sort. Identify it, and call the node to 00676 // continue streaming. 00677 TiXmlNode* node = Identify( tag->c_str() + tagIndex, TIXML_DEFAULT_ENCODING ); 00678 00679 if ( node ) 00680 { 00681 node->StreamIn( in, tag ); 00682 bool isElement = node->ToElement() != 0; 00683 delete node; 00684 node = 0; 00685 00686 // If this is the root element, we're done. Parsing will be 00687 // done by the >> operator. 00688 if ( isElement ) 00689 { 00690 return; 00691 } 00692 } 00693 else 00694 { 00695 SetError( TIXML_ERROR, 0, 0, TIXML_ENCODING_UNKNOWN ); 00696 return; 00697 } 00698 } 00699 } 00700 // We should have returned sooner. 00701 SetError( TIXML_ERROR, 0, 0, TIXML_ENCODING_UNKNOWN ); 00702 }
void OBT::TiXmlDocument::CopyTo | ( | TiXmlDocument * | target | ) | const [private] |
Definition at line 1121 of file OBTtinyxml.cpp.
References OBT::TiXmlNode::Clone(), OBT::TiXmlNode::CopyTo(), error, errorDesc, errorId, errorLocation, OBT::TiXmlNode::firstChild, OBT::TiXmlNode::LinkEndChild(), OBT::TiXmlNode::NextSibling(), tabsize, and useMicrosoftBOM.
Referenced by Clone(), operator=(), and TiXmlDocument().
01122 { 01123 TiXmlNode::CopyTo( target ); 01124 01125 target->error = error; 01126 target->errorId = errorId; 01127 target->errorDesc = errorDesc; 01128 target->tabsize = tabsize; 01129 target->errorLocation = errorLocation; 01130 target->useMicrosoftBOM = useMicrosoftBOM; 01131 01132 TiXmlNode* node = 0; 01133 for ( node = firstChild; node; node = node->NextSibling() ) 01134 { 01135 target->LinkEndChild( node->Clone() ); 01136 } 01137 }
void OBT::TiXmlDocument::operator= | ( | const TiXmlDocument & | copy | ) |
bool OBT::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.
bool OBT::TiXmlDocument::SaveFile | ( | ) | const |
Save a file using the current document value. Returns true if successful.
bool OBT::TiXmlDocument::LoadFile | ( | const char * | filename, | |
TiXmlEncoding | encoding = TIXML_DEFAULT_ENCODING | |||
) |
Load a file using the given filename. Returns true if successful.
bool OBT::TiXmlDocument::SaveFile | ( | const char * | filename | ) | const |
Save a file using the given filename. Returns true if successful.
bool OBT::TiXmlDocument::LoadFile | ( | 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.
bool OBT::TiXmlDocument::SaveFile | ( | FILE * | ) | const |
Save a file using the given FILE*. Returns true if successful.
bool OBT::TiXmlDocument::LoadFile | ( | const std::string & | filename, | |
TiXmlEncoding | encoding = TIXML_DEFAULT_ENCODING | |||
) | [inline] |
encoding | STL std::string version. |
Definition at line 1430 of file tiny/OBTtinyxml.h.
References LoadFile().
01431 { 01432 // StringToBuffer f( filename ); 01433 // return ( f.buffer && LoadFile( f.buffer, encoding )); 01434 return LoadFile( filename.c_str(), encoding ); 01435 }
bool OBT::TiXmlDocument::SaveFile | ( | const std::string & | filename | ) | const [inline] |
< STL std::string version.
Definition at line 1436 of file tiny/OBTtinyxml.h.
References SaveFile().
01437 { 01438 // StringToBuffer f( filename ); 01439 // return ( f.buffer && SaveFile( f.buffer )); 01440 return SaveFile( filename.c_str() ); 01441 }
virtual const char* OBT::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 OBT::TiXmlBase.
const TiXmlElement* OBT::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 1454 of file tiny/OBTtinyxml.h.
References OBT::TiXmlNode::FirstChildElement().
01454 { return FirstChildElement(); }
TiXmlElement* OBT::TiXmlDocument::RootElement | ( | ) | [inline] |
Definition at line 1455 of file tiny/OBTtinyxml.h.
References OBT::TiXmlNode::FirstChildElement().
01455 { return FirstChildElement(); }
bool OBT::TiXmlDocument::Error | ( | ) | const [inline] |
If an error occurs, Error will be set to true.
Also,
Definition at line 1462 of file tiny/OBTtinyxml.h.
References error.
01462 { return error; }
const char* OBT::TiXmlDocument::ErrorDesc | ( | ) | const [inline] |
Contains a textual (english) description of the error if one occurs.
Definition at line 1465 of file tiny/OBTtinyxml.h.
References errorDesc.
01465 { return errorDesc.c_str (); }
int OBT::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 1470 of file tiny/OBTtinyxml.h.
References errorId.
01470 { return errorId; }
int OBT::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.)
Definition at line 1479 of file tiny/OBTtinyxml.h.
References errorLocation, and OBT::TiXmlCursor::row.
01479 { return errorLocation.row+1; }
int OBT::TiXmlDocument::ErrorCol | ( | ) | const [inline] |
The column where the error occured. See ErrorRow().
Definition at line 1480 of file tiny/OBTtinyxml.h.
References OBT::TiXmlCursor::col, and errorLocation.
void OBT::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" );
Definition at line 1506 of file tiny/OBTtinyxml.h.
References tabsize.
01506 { tabsize = _tabsize; }
int OBT::TiXmlDocument::TabSize | ( | ) | const [inline] |
void OBT::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 1513 of file tiny/OBTtinyxml.h.
References OBT::TiXmlCursor::col, error, errorDesc, errorId, errorLocation, and OBT::TiXmlCursor::row.
01513 { error = false; 01514 errorId = 0; 01515 errorDesc = ""; 01516 errorLocation.row = errorLocation.col = 0; 01517 //errorLocation.last = 0; 01518 }
void OBT::TiXmlDocument::Print | ( | ) | const [inline] |
Write the document to standard out using formatted printing ("pretty print").
Definition at line 1521 of file tiny/OBTtinyxml.h.
References Print().
01521 { Print( stdout, 0 ); }
virtual void OBT::TiXmlDocument::Print | ( | FILE * | cfile, | |
int | depth = 0 | |||
) | const [virtual] |
void OBT::TiXmlDocument::SetError | ( | int | err, | |
const char * | errorLocation, | |||
TiXmlParsingData * | prevData, | |||
TiXmlEncoding | encoding | |||
) |
virtual const TiXmlDocument* OBT::TiXmlDocument::ToDocument | ( | ) | const [inline, virtual] |
Cast to a more defined type. Will return null not of the requested type.
Reimplemented from OBT::TiXmlNode.
Definition at line 1534 of file tiny/OBTtinyxml.h.
virtual TiXmlDocument* OBT::TiXmlDocument::ToDocument | ( | ) | [inline, virtual] |
Cast to a more defined type. Will return null not of the requested type.
Reimplemented from OBT::TiXmlNode.
Definition at line 1535 of file tiny/OBTtinyxml.h.
virtual bool OBT::TiXmlDocument::Accept | ( | TiXmlVisitor * | content | ) | const [virtual] |
virtual TiXmlNode* OBT::TiXmlDocument::Clone | ( | ) | const [protected, virtual] |
Create an exact duplicate of this node and return it.
The memory must be deleted by the caller.
Implements OBT::TiXmlNode.
virtual void OBT::TiXmlDocument::StreamIn | ( | std::istream * | in, | |
TIXML_STRING * | tag | |||
) | [protected, virtual] |
Implements OBT::TiXmlNode.
void OBT::TiXmlDocument::CopyTo | ( | TiXmlDocument * | target | ) | const [private] |
bool OBT::TiXmlDocument::error [private] |
Definition at line 1552 of file OBTtinyxml.h.
Referenced by ClearError(), CopyTo(), Error(), and SetError().
int OBT::TiXmlDocument::errorId [private] |
Definition at line 1553 of file OBTtinyxml.h.
Referenced by ClearError(), CopyTo(), ErrorId(), and SetError().
TIXML_STRING OBT::TiXmlDocument::errorDesc [private] |
Definition at line 1554 of file OBTtinyxml.h.
Referenced by ClearError(), CopyTo(), ErrorDesc(), and SetError().
int OBT::TiXmlDocument::tabsize [private] |
Definition at line 1555 of file OBTtinyxml.h.
Referenced by CopyTo(), SetTabSize(), TabSize(), and TiXmlDocument().
TiXmlCursor OBT::TiXmlDocument::errorLocation [private] |
Definition at line 1556 of file OBTtinyxml.h.
Referenced by ClearError(), CopyTo(), ErrorCol(), ErrorRow(), and SetError().
bool OBT::TiXmlDocument::useMicrosoftBOM [private] |
Definition at line 1557 of file OBTtinyxml.h.
Referenced by CopyTo(), Parse(), SaveFile(), and TiXmlDocument().