FEDRA emulsion software from the OPERA Collaboration
TiXmlDocument Class Reference

#include <tinyxml.h>

Inheritance diagram for TiXmlDocument:
Collaboration diagram for TiXmlDocument:

Public Member Functions

virtual bool Accept (TiXmlVisitor *content) const
 
void ClearError ()
 
bool Error () const
 
int ErrorCol () const
 The column where the error occured. See ErrorRow() More...
 
const char * ErrorDesc () const
 Contains a textual (english) description of the error if one occurs. More...
 
int ErrorId () const
 
int ErrorRow () const
 
bool LoadFile (const char *filename, TiXmlEncoding encoding=TIXML_DEFAULT_ENCODING)
 Load a file using the given filename. Returns true if successful. More...
 
bool LoadFile (FILE *, TiXmlEncoding encoding=TIXML_DEFAULT_ENCODING)
 
bool LoadFile (TiXmlEncoding encoding=TIXML_DEFAULT_ENCODING)
 
TiXmlDocumentoperator= (const TiXmlDocument &copy)
 
virtual const char * Parse (const char *p, TiXmlParsingData *data=0, TiXmlEncoding encoding=TIXML_DEFAULT_ENCODING)
 
void Print () const
 
virtual void Print (FILE *cfile, int depth=0) const
 Print this Document to a FILE stream. More...
 
TiXmlElementRootElement ()
 
const TiXmlElementRootElement () const
 
bool SaveFile () const
 Save a file using the current document value. Returns true if successful. More...
 
bool SaveFile (const char *filename) const
 Save a file using the given filename. Returns true if successful. More...
 
bool SaveFile (FILE *) const
 Save a file using the given FILE*. Returns true if successful. More...
 
void SetError (int err, const char *errorLocation, TiXmlParsingData *prevData, TiXmlEncoding encoding)
 
void SetTabSize (int _tabsize)
 
int TabSize () const
 
 TiXmlDocument ()
 Create an empty document, that has no name. More...
 
 TiXmlDocument (const char *documentName)
 Create a document with a name. The name of the document is also the filename of the xml. More...
 
 TiXmlDocument (const TiXmlDocument &copy)
 
virtual TiXmlDocumentToDocument ()
 Cast to a more defined type. Will return null not of the requested type. More...
 
virtual const TiXmlDocumentToDocument () const
 Cast to a more defined type. Will return null not of the requested type. More...
 
virtual ~TiXmlDocument ()
 
- Public Member Functions inherited from TiXmlNode
void Clear ()
 Delete all the children of this node. Does not affect 'this'. More...
 
TiXmlNodeFirstChild ()
 
const TiXmlNodeFirstChild () const
 The first child of this node. Will be null if there are no children. More...
 
TiXmlNodeFirstChild (const char *_value)
 The first child of this node with the matching 'value'. Will be null if none found. More...
 
const TiXmlNodeFirstChild (const char *value) const
 
TiXmlElementFirstChildElement ()
 
const TiXmlElementFirstChildElement () const
 Convenience function to get through elements. More...
 
TiXmlElementFirstChildElement (const char *_value)
 
const TiXmlElementFirstChildElement (const char *_value) const
 Convenience function to get through elements. More...
 
TiXmlDocumentGetDocument ()
 
const TiXmlDocumentGetDocument () const
 
TiXmlNodeInsertAfterChild (TiXmlNode *afterThis, const TiXmlNode &addThis)
 
TiXmlNodeInsertBeforeChild (TiXmlNode *beforeThis, const TiXmlNode &addThis)
 
TiXmlNodeInsertEndChild (const TiXmlNode &addThis)
 
TiXmlNodeIterateChildren (const char *_value, const TiXmlNode *previous)
 
const TiXmlNodeIterateChildren (const char *value, const TiXmlNode *previous) const
 This flavor of IterateChildren searches for children with a particular 'value'. More...
 
TiXmlNodeIterateChildren (const TiXmlNode *previous)
 
const TiXmlNodeIterateChildren (const TiXmlNode *previous) const
 
TiXmlNodeLastChild ()
 The last child of this node. Will be null if there are no children. More...
 
const TiXmlNodeLastChild () const
 
TiXmlNodeLastChild (const char *_value)
 The last child of this node matching 'value'. Will be null if there are no children. More...
 
const TiXmlNodeLastChild (const char *value) const
 
TiXmlNodeLinkEndChild (TiXmlNode *addThis)
 
TiXmlNodeNextSibling ()
 
const TiXmlNodeNextSibling () const
 Navigate to a sibling node. More...
 
const TiXmlNodeNextSibling (const char *) const
 Navigate to a sibling node with the given 'value'. More...
 
TiXmlNodeNextSibling (const char *_next)
 
TiXmlElementNextSiblingElement ()
 
const TiXmlElementNextSiblingElement () const
 
const TiXmlElementNextSiblingElement (const char *) const
 
TiXmlElementNextSiblingElement (const char *_next)
 
bool NoChildren () const
 Returns true if this node has no children. More...
 
TiXmlNodeParent ()
 One step up the DOM. More...
 
const TiXmlNodeParent () const
 
TiXmlNodePreviousSibling ()
 
const TiXmlNodePreviousSibling () const
 Navigate to a sibling node. More...
 
const TiXmlNodePreviousSibling (const char *) const
 Navigate to a sibling node. More...
 
TiXmlNodePreviousSibling (const char *_prev)
 
bool RemoveChild (TiXmlNode *removeThis)
 Delete a child of this node. More...
 
TiXmlNodeReplaceChild (TiXmlNode *replaceThis, const TiXmlNode &withThis)
 
void SetValue (const char *_value)
 
virtual TiXmlCommentToComment ()
 Cast to a more defined type. Will return null if not of the requested type. More...
 
virtual const TiXmlCommentToComment () const
 Cast to a more defined type. Will return null if not of the requested type. More...
 
virtual TiXmlDeclarationToDeclaration ()
 Cast to a more defined type. Will return null if not of the requested type. More...
 
virtual const TiXmlDeclarationToDeclaration () const
 Cast to a more defined type. Will return null if not of the requested type. More...
 
virtual TiXmlElementToElement ()
 Cast to a more defined type. Will return null if not of the requested type. More...
 
virtual const TiXmlElementToElement () const
 Cast to a more defined type. Will return null if not of the requested type. More...
 
virtual TiXmlTextToText ()
 Cast to a more defined type. Will return null if not of the requested type. More...
 
virtual const TiXmlTextToText () const
 Cast to a more defined type. Will return null if not of the requested type. More...
 
virtual TiXmlUnknownToUnknown ()
 Cast to a more defined type. Will return null if not of the requested type. More...
 
virtual const TiXmlUnknownToUnknown () const
 Cast to a more defined type. Will return null if not of the requested type. More...
 
int Type () const
 
const char * Value () const
 
const TIXML_STRINGValueTStr () const
 
virtual ~TiXmlNode ()
 
- Public Member Functions inherited from TiXmlBase
int Column () const
 See Row() More...
 
voidGetUserData ()
 Get a pointer to arbitrary user data. More...
 
const voidGetUserData () const
 Get a pointer to arbitrary user data. More...
 
int Row () const
 
void SetUserData (void *user)
 Set a pointer to arbitrary user data. More...
 
 TiXmlBase ()
 
virtual ~TiXmlBase ()
 

Protected Member Functions

virtual TiXmlNodeClone () const
 
- Protected Member Functions inherited from TiXmlNode
void CopyTo (TiXmlNode *target) const
 
TiXmlNodeIdentify (const char *start, TiXmlEncoding encoding)
 
 TiXmlNode (NodeType _type)
 

Private Member Functions

void CopyTo (TiXmlDocument *target) const
 

Private Attributes

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

Additional Inherited Members

- Public Types inherited from TiXmlNode
enum  NodeType {
  TINYXML_DOCUMENT , TINYXML_ELEMENT , TINYXML_COMMENT , TINYXML_UNKNOWN ,
  TINYXML_TEXT , TINYXML_DECLARATION , TINYXML_TYPECOUNT
}
 
- Public Types inherited from TiXmlBase
enum  {
  TIXML_NO_ERROR = 0 , TIXML_ERROR , TIXML_ERROR_OPENING_FILE , TIXML_ERROR_PARSING_ELEMENT ,
  TIXML_ERROR_FAILED_TO_READ_ELEMENT_NAME , TIXML_ERROR_READING_ELEMENT_VALUE , TIXML_ERROR_READING_ATTRIBUTES , TIXML_ERROR_PARSING_EMPTY ,
  TIXML_ERROR_READING_END_TAG , TIXML_ERROR_PARSING_UNKNOWN , TIXML_ERROR_PARSING_COMMENT , TIXML_ERROR_PARSING_DECLARATION ,
  TIXML_ERROR_DOCUMENT_EMPTY , TIXML_ERROR_EMBEDDED_NULL , TIXML_ERROR_PARSING_CDATA , TIXML_ERROR_DOCUMENT_TOP_ONLY ,
  TIXML_ERROR_STRING_COUNT
}
 
- Static Public Member Functions inherited from TiXmlBase
static void EncodeString (const TIXML_STRING &str, TIXML_STRING *out)
 
static bool IsWhiteSpaceCondensed ()
 Return the current white space setting. More...
 
static void SetCondenseWhiteSpace (bool condense)
 
- Static Public Attributes inherited from TiXmlBase
static const int utf8ByteTable [256]
 
- Static Protected Member Functions inherited from TiXmlBase
static void ConvertUTF32ToUTF8 (unsigned long input, char *output, int *length)
 
static const char * GetChar (const char *p, char *_value, int *length, TiXmlEncoding encoding)
 
static const char * GetEntity (const char *in, char *value, int *length, TiXmlEncoding encoding)
 
static int IsAlpha (unsigned char anyByte, TiXmlEncoding encoding)
 
static int IsAlphaNum (unsigned char anyByte, TiXmlEncoding encoding)
 
static bool IsWhiteSpace (char c)
 
static bool IsWhiteSpace (int c)
 
static const char * ReadName (const char *p, TIXML_STRING *name, TiXmlEncoding encoding)
 
static const char * ReadText (const char *in, TIXML_STRING *text, bool ignoreWhiteSpace, const char *endTag, bool ignoreCase, TiXmlEncoding encoding)
 
static const char * SkipWhiteSpace (const char *, TiXmlEncoding encoding)
 
static bool StringEqual (const char *p, const char *endTag, bool ignoreCase, TiXmlEncoding encoding)
 
static int ToLower (int v, TiXmlEncoding encoding)
 
- Protected Attributes inherited from TiXmlNode
TiXmlNodefirstChild
 
TiXmlNodelastChild
 
TiXmlNodenext
 
TiXmlNodeparent
 
TiXmlNodeprev
 
NodeType type
 
TIXML_STRING value
 
- Protected Attributes inherited from TiXmlBase
TiXmlCursor location
 
voiduserData
 Field containing a generic user pointer. More...
 
- Static Protected Attributes inherited from TiXmlBase
static const char * errorString [TIXML_ERROR_STRING_COUNT]
 

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.

Constructor & Destructor Documentation

◆ TiXmlDocument() [1/3]

TiXmlDocument::TiXmlDocument ( )

Create an empty document, that has no name.

914 {
915  tabsize = 4;
916  useMicrosoftBOM = false;
917  ClearError();
918 }
friend class TiXmlNode
Definition: tinyxml.h:196
bool useMicrosoftBOM
Definition: tinyxml.h:1554
void ClearError()
Definition: tinyxml.h:1511
int tabsize
Definition: tinyxml.h:1552
@ TINYXML_DOCUMENT
Definition: tinyxml.h:464

◆ TiXmlDocument() [2/3]

TiXmlDocument::TiXmlDocument ( const char *  documentName)

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

921 {
922  tabsize = 4;
923  useMicrosoftBOM = false;
924  value = documentName;
925  ClearError();
926 }
TIXML_STRING value
Definition: tinyxml.h:761

◆ TiXmlDocument() [3/3]

TiXmlDocument::TiXmlDocument ( const TiXmlDocument copy)
941 {
942  copy.CopyTo( this );
943 }
void CopyTo(TiXmlDocument *target) const
Definition: tinyxml.cpp:1115

◆ ~TiXmlDocument()

virtual TiXmlDocument::~TiXmlDocument ( )
inlinevirtual
1409 {}

Member Function Documentation

◆ Accept()

bool TiXmlDocument::Accept ( TiXmlVisitor content) const
virtual

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

Implements TiXmlNode.

1157 {
1158  if ( visitor->VisitEnter( *this ) )
1159  {
1160  for ( const TiXmlNode* node=FirstChild(); node; node=node->NextSibling() )
1161  {
1162  if ( !node->Accept( visitor ) )
1163  break;
1164  }
1165  }
1166  return visitor->VisitExit( *this );
1167 }
Definition: tinyxml.h:424
const TiXmlNode * FirstChild() const
The first child of this node. Will be null if there are no children.
Definition: tinyxml.h:522
const TiXmlNode * NextSibling() const
Navigate to a sibling node.
Definition: tinyxml.h:631

◆ ClearError()

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.

1511  { error = false;
1512  errorId = 0;
1513  errorDesc = "";
1515  //errorLocation.last = 0;
1516  }
bool error
Definition: tinyxml.h:1549
TIXML_STRING errorDesc
Definition: tinyxml.h:1551
TiXmlCursor errorLocation
Definition: tinyxml.h:1553
int errorId
Definition: tinyxml.h:1550
int col
Definition: tinyxml.h:105
int row
Definition: tinyxml.h:104

◆ Clone()

TiXmlNode * TiXmlDocument::Clone ( ) const
protectedvirtual

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

Implements TiXmlNode.

1135 {
1136  TiXmlDocument* clone = new TiXmlDocument();
1137  if ( !clone )
1138  return 0;
1139 
1140  CopyTo( clone );
1141  return clone;
1142 }
Definition: tinyxml.h:1394
TiXmlDocument()
Create an empty document, that has no name.
Definition: tinyxml.cpp:913

◆ CopyTo()

void TiXmlDocument::CopyTo ( TiXmlDocument target) const
private
1116 {
1117  TiXmlNode::CopyTo( target );
1118 
1119  target->error = error;
1120  target->errorId = errorId;
1121  target->errorDesc = errorDesc;
1122  target->tabsize = tabsize;
1123  target->errorLocation = errorLocation;
1124  target->useMicrosoftBOM = useMicrosoftBOM;
1125 
1126  TiXmlNode* node = 0;
1127  for ( node = firstChild; node; node = node->NextSibling() )
1128  {
1129  target->LinkEndChild( node->Clone() );
1130  }
1131 }
TiXmlNode * LinkEndChild(TiXmlNode *addThis)
Definition: tinyxml.cpp:186
virtual TiXmlNode * Clone() const =0
void CopyTo(TiXmlNode *target) const
Definition: tinyxml.cpp:161
TiXmlNode * firstChild
Definition: tinyxml.h:758

◆ Error()

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)
1460 { return error; }

◆ ErrorCol()

int TiXmlDocument::ErrorCol ( ) const
inline

The column where the error occured. See ErrorRow()

◆ ErrorDesc()

const char* TiXmlDocument::ErrorDesc ( ) const
inline

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

1463 { return errorDesc.c_str (); }

◆ ErrorId()

int TiXmlDocument::ErrorId ( ) const
inline

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

1468 { return errorId; }

◆ ErrorRow()

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
1477 { return errorLocation.row+1; }

◆ LoadFile() [1/3]

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

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

966 {
967  TIXML_STRING filename( _filename );
968  value = filename;
969 
970  // reading in binary mode so that tinyxml can normalize the EOL
971  FILE* file = TiXmlFOpen( value.c_str (), "rb" );
972 
973  if ( file )
974  {
975  bool result = LoadFile( file, encoding );
976  fclose( file );
977  return result;
978  }
979  else
980  {
982  return false;
983  }
984 }
@ TIXML_ERROR_OPENING_FILE
Definition: tinyxml.h:268
bool LoadFile(TiXmlEncoding encoding=TIXML_DEFAULT_ENCODING)
Definition: tinyxml.cpp:954
void SetError(int err, const char *errorLocation, TiXmlParsingData *prevData, TiXmlEncoding encoding)
Definition: tinyxmlparser.cpp:798
string filename
Definition: emthickness.cpp:34
fclose(pFile)
FILE * TiXmlFOpen(const char *filename, const char *mode)
Definition: tinyxml.cpp:39
@ TIXML_ENCODING_UNKNOWN
Definition: tinyxml.h:165
#define TIXML_STRING
Definition: tinyxml.h:53
TFile * file
Definition: write_pvr.C:3

◆ LoadFile() [2/3]

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.

987 {
988  if ( !file )
989  {
991  return false;
992  }
993 
994  // Delete the existing data:
995  Clear();
996  location.Clear();
997 
998  // Get the file size, so we can pre-allocate the string. HUGE speed impact.
999  long length = 0;
1000  fseek( file, 0, SEEK_END );
1001  length = ftell( file );
1002  fseek( file, 0, SEEK_SET );
1003 
1004  // Strange case, but good to handle up front.
1005  if ( length <= 0 )
1006  {
1008  return false;
1009  }
1010 
1011  // Subtle bug here. TinyXml did use fgets. But from the XML spec:
1012  // 2.11 End-of-Line Handling
1013  // <snip>
1014  // <quote>
1015  // ...the XML processor MUST behave as if it normalized all line breaks in external
1016  // parsed entities (including the document entity) on input, before parsing, by translating
1017  // both the two-character sequence #xD #xA and any #xD that is not followed by #xA to
1018  // a single #xA character.
1019  // </quote>
1020  //
1021  // It is not clear fgets does that, and certainly isn't clear it works cross platform.
1022  // Generally, you expect fgets to translate from the convention of the OS to the c/unix
1023  // convention, and not work generally.
1024 
1025  /*
1026  while( fgets( buf, sizeof(buf), file ) )
1027  {
1028  data += buf;
1029  }
1030  */
1031 
1032  char* buf = new char[ length+1 ];
1033  buf[0] = 0;
1034 
1035  if ( fread( buf, length, 1, file ) != 1 ) {
1036  delete [] buf;
1038  return false;
1039  }
1040 
1041  // Process the buffer in place to normalize new lines. (See comment above.)
1042  // Copies from the 'p' to 'q' pointer, where p can advance faster if
1043  // a newline-carriage return is hit.
1044  //
1045  // Wikipedia:
1046  // Systems based on ASCII or a compatible character set use either LF (Line feed, '\n', 0x0A, 10 in decimal) or
1047  // CR (Carriage return, '\r', 0x0D, 13 in decimal) individually, or CR followed by LF (CR+LF, 0x0D 0x0A)...
1048  // * LF: Multics, Unix and Unix-like systems (GNU/Linux, AIX, Xenix, Mac OS X, FreeBSD, etc.), BeOS, Amiga, RISC OS, and others
1049  // * CR+LF: DEC RT-11 and most other early non-Unix, non-IBM OSes, CP/M, MP/M, DOS, OS/2, Microsoft Windows, Symbian OS
1050  // * CR: Commodore 8-bit machines, Apple II family, Mac OS up to version 9 and OS-9
1051 
1052  const char* p = buf; // the read head
1053  char* q = buf; // the write head
1054  const char CR = 0x0d;
1055  const char LF = 0x0a;
1056 
1057  buf[length] = 0;
1058  while( *p ) {
1059  assert( p < (buf+length) );
1060  assert( q <= (buf+length) );
1061  assert( q <= p );
1062 
1063  if ( *p == CR ) {
1064  *q++ = LF;
1065  p++;
1066  if ( *p == LF ) { // check for CR+LF (and skip LF)
1067  p++;
1068  }
1069  }
1070  else {
1071  *q++ = *p++;
1072  }
1073  }
1074  assert( q <= (buf+length) );
1075  *q = 0;
1076 
1077  Parse( buf, 0, encoding );
1078 
1079  delete [] buf;
1080  return !Error();
1081 }
TiXmlCursor location
Definition: tinyxml.h:373
@ TIXML_ERROR_DOCUMENT_EMPTY
Definition: tinyxml.h:278
bool Error() const
Definition: tinyxml.h:1460
virtual const char * Parse(const char *p, TiXmlParsingData *data=0, TiXmlEncoding encoding=TIXML_DEFAULT_ENCODING)
Definition: tinyxmlparser.cpp:704
void Clear()
Delete all the children of this node. Does not affect 'this'.
Definition: tinyxml.cpp:169
void Clear()
Definition: tinyxml.h:102
q
Definition: testBGReduction_AllMethods.C:55
p
Definition: testBGReduction_AllMethods.C:8

◆ LoadFile() [3/3]

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.

955 {
956  return LoadFile( Value(), encoding );
957 }
const char * Value() const
Definition: tinyxml.h:487

◆ operator=()

TiXmlDocument & TiXmlDocument::operator= ( const TiXmlDocument copy)
947 {
948  Clear();
949  copy.CopyTo( this );
950  return *this;
951 }

◆ Parse()

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.

705 {
706  ClearError();
707 
708  // Parse away, at the document level. Since a document
709  // contains nothing but other tags, most of what happens
710  // here is skipping white space.
711  if ( !p || !*p )
712  {
714  return 0;
715  }
716 
717  // Note that, for a document, this needs to come
718  // before the while space skip, so that parsing
719  // starts from the pointer we are given.
720  location.Clear();
721  if ( prevData )
722  {
723  location.row = prevData->cursor.row;
724  location.col = prevData->cursor.col;
725  }
726  else
727  {
728  location.row = 0;
729  location.col = 0;
730  }
732  location = data.Cursor();
733 
734  if ( encoding == TIXML_ENCODING_UNKNOWN )
735  {
736  // Check for the Microsoft UTF-8 lead bytes.
737  const unsigned char* pU = (const unsigned char*)p;
738  if ( *(pU+0) && *(pU+0) == TIXML_UTF_LEAD_0
739  && *(pU+1) && *(pU+1) == TIXML_UTF_LEAD_1
740  && *(pU+2) && *(pU+2) == TIXML_UTF_LEAD_2 )
741  {
742  encoding = TIXML_ENCODING_UTF8;
743  useMicrosoftBOM = true;
744  }
745  }
746 
747  p = SkipWhiteSpace( p, encoding );
748  if ( !p )
749  {
751  return 0;
752  }
753 
754  while ( p && *p )
755  {
756  TiXmlNode* node = Identify( p, encoding );
757  if ( node )
758  {
759  p = node->Parse( p, &data, encoding );
760  LinkEndChild( node );
761  }
762  else
763  {
764  break;
765  }
766 
767  // Did we get encoding info?
768  if ( encoding == TIXML_ENCODING_UNKNOWN
769  && node->ToDeclaration() )
770  {
771  TiXmlDeclaration* dec = node->ToDeclaration();
772  const char* enc = dec->Encoding();
773  assert( enc );
774 
775  if ( *enc == 0 )
776  encoding = TIXML_ENCODING_UTF8;
777  else if ( StringEqual( enc, "UTF-8", true, TIXML_ENCODING_UNKNOWN ) )
778  encoding = TIXML_ENCODING_UTF8;
779  else if ( StringEqual( enc, "UTF8", true, TIXML_ENCODING_UNKNOWN ) )
780  encoding = TIXML_ENCODING_UTF8; // incorrect, but be nice
781  else
782  encoding = TIXML_ENCODING_LEGACY;
783  }
784 
785  p = SkipWhiteSpace( p, encoding );
786  }
787 
788  // Was this empty?
789  if ( !firstChild ) {
790  SetError( TIXML_ERROR_DOCUMENT_EMPTY, 0, 0, encoding );
791  return 0;
792  }
793 
794  // All is well.
795  return p;
796 }
virtual const char * Parse(const char *p, TiXmlParsingData *data, TiXmlEncoding encoding)=0
static bool StringEqual(const char *p, const char *endTag, bool ignoreCase, TiXmlEncoding encoding)
Definition: tinyxmlparser.cpp:534
static const char * SkipWhiteSpace(const char *, TiXmlEncoding encoding)
Definition: tinyxmlparser.cpp:314
Definition: tinyxml.h:1286
const char * Encoding() const
Encoding. Will return an empty string if none was found.
Definition: tinyxml.h:1311
int TabSize() const
Definition: tinyxml.h:1506
virtual const TiXmlDeclaration * ToDeclaration() const
Cast to a more defined type. Will return null if not of the requested type.
Definition: tinyxml.h:702
TiXmlNode * Identify(const char *start, TiXmlEncoding encoding)
Definition: tinyxmlparser.cpp:818
Definition: tinyxmlparser.cpp:172
const TiXmlCursor & Cursor() const
Definition: tinyxmlparser.cpp:177
@ TIXML_ENCODING_LEGACY
Definition: tinyxml.h:167
@ TIXML_ENCODING_UTF8
Definition: tinyxml.h:166
const unsigned char TIXML_UTF_LEAD_0
Definition: tinyxmlparser.cpp:62
const unsigned char TIXML_UTF_LEAD_1
Definition: tinyxmlparser.cpp:63
const unsigned char TIXML_UTF_LEAD_2
Definition: tinyxmlparser.cpp:64

◆ Print() [1/2]

void TiXmlDocument::Print ( ) const
inline

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

1519 { Print( stdout, 0 ); }
FILE * stdout
void Print() const
Definition: tinyxml.h:1519

◆ Print() [2/2]

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

Print this Document to a FILE stream.

Implements TiXmlBase.

1146 {
1147  assert( cfile );
1148  for ( const TiXmlNode* node=FirstChild(); node; node=node->NextSibling() )
1149  {
1150  node->Print( cfile, depth );
1151  fprintf( cfile, "\n" );
1152  }
1153 }

◆ RootElement() [1/2]

TiXmlElement* TiXmlDocument::RootElement ( )
inline
1453 { return FirstChildElement(); }
const TiXmlElement * FirstChildElement() const
Convenience function to get through elements.
Definition: tinyxml.cpp:452

◆ RootElement() [2/2]

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.

1452 { return FirstChildElement(); }

◆ SaveFile() [1/3]

bool TiXmlDocument::SaveFile ( ) const

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

961 {
962  return SaveFile( Value() );
963 }
bool SaveFile() const
Save a file using the current document value. Returns true if successful.
Definition: tinyxml.cpp:960

◆ SaveFile() [2/3]

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

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

1085 {
1086  // The old c stuff lives on...
1087  FILE* fp = TiXmlFOpen( filename, "w" );
1088  if ( fp )
1089  {
1090  bool result = SaveFile( fp );
1091  fclose( fp );
1092  return result;
1093  }
1094  return false;
1095 }

◆ SaveFile() [3/3]

bool TiXmlDocument::SaveFile ( FILE *  fp) const

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

1099 {
1100  if ( useMicrosoftBOM )
1101  {
1102  const unsigned char TIXML_UTF_LEAD_0 = 0xefU;
1103  const unsigned char TIXML_UTF_LEAD_1 = 0xbbU;
1104  const unsigned char TIXML_UTF_LEAD_2 = 0xbfU;
1105 
1106  fputc( TIXML_UTF_LEAD_0, fp );
1107  fputc( TIXML_UTF_LEAD_1, fp );
1108  fputc( TIXML_UTF_LEAD_2, fp );
1109  }
1110  Print( fp, 0 );
1111  return (ferror(fp) == 0);
1112 }

◆ SetError()

void TiXmlDocument::SetError ( int  err,
const char *  errorLocation,
TiXmlParsingData prevData,
TiXmlEncoding  encoding 
)
799 {
800  // The first error in a chain is more accurate - don't set again!
801  if ( error )
802  return;
803 
804  assert( err > 0 && err < TIXML_ERROR_STRING_COUNT );
805  error = true;
806  errorId = err;
808 
810  if ( pError && data )
811  {
812  data->Stamp( pError, encoding );
813  errorLocation = data->Cursor();
814  }
815 }
@ TIXML_ERROR_STRING_COUNT
Definition: tinyxml.h:283
static const char * errorString[TIXML_ERROR_STRING_COUNT]
Definition: tinyxml.h:371

◆ SetTabSize()

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
1504 { tabsize = _tabsize; }

◆ TabSize()

int TiXmlDocument::TabSize ( ) const
inline
1506 { return tabsize; }

◆ ToDocument() [1/2]

virtual TiXmlDocument* TiXmlDocument::ToDocument ( )
inlinevirtual

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

Reimplemented from TiXmlNode.

◆ ToDocument() [2/2]

virtual const TiXmlDocument* TiXmlDocument::ToDocument ( ) const
inlinevirtual

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

Reimplemented from TiXmlNode.

Member Data Documentation

◆ error

bool TiXmlDocument::error
private

◆ errorDesc

TIXML_STRING TiXmlDocument::errorDesc
private

◆ errorId

int TiXmlDocument::errorId
private

◆ errorLocation

TiXmlCursor TiXmlDocument::errorLocation
private

◆ tabsize

int TiXmlDocument::tabsize
private

◆ useMicrosoftBOM

bool TiXmlDocument::useMicrosoftBOM
private

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