CMS 3D CMS Logo

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

#include <tinyxml.h>

Inheritance diagram for TiXmlDocument:
TiXmlNode TiXmlBase

Public Member Functions

virtual bool Accept (TiXmlVisitor *content) const
 
void ClearError ()
 
bool Error () const
 
int ErrorCol () const
 The column where the error occurred. 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 (TiXmlEncoding encoding=TIXML_DEFAULT_ENCODING)
 
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 (const std::string &filename, 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...
 
const TiXmlElementRootElement () const
 
TiXmlElementRootElement ()
 
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...
 
bool SaveFile (const std::string &filename) const
 < STL std::string version. 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 std::string &documentName)
 Constructor. More...
 
 TiXmlDocument (const TiXmlDocument &copy)
 
virtual const TiXmlDocumentToDocument () const
 Cast to a more defined type. Will return null not of the requested type. More...
 
virtual TiXmlDocumentToDocument ()
 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...
 
const TiXmlNodeFirstChild () const
 The first child of this node. Will be null if there are no children. More...
 
TiXmlNodeFirstChild ()
 
const TiXmlNodeFirstChild (const char *value) const
 
TiXmlNodeFirstChild (const char *_value)
 The first child of this node with the matching 'value'. Will be null if none found. More...
 
const TiXmlNodeFirstChild (const std::string &_value) const
 STL std::string form. More...
 
TiXmlNodeFirstChild (const std::string &_value)
 STL std::string form. More...
 
const TiXmlElementFirstChildElement () const
 Convenience function to get through elements. More...
 
TiXmlElementFirstChildElement ()
 
const TiXmlElementFirstChildElement (const char *_value) const
 Convenience function to get through elements. More...
 
TiXmlElementFirstChildElement (const char *_value)
 
const TiXmlElementFirstChildElement (const std::string &_value) const
 STL std::string form. More...
 
TiXmlElementFirstChildElement (const std::string &_value)
 STL std::string form. More...
 
const TiXmlDocumentGetDocument () const
 
TiXmlDocumentGetDocument ()
 
TiXmlNodeInsertAfterChild (TiXmlNode *afterThis, const TiXmlNode &addThis)
 
TiXmlNodeInsertBeforeChild (TiXmlNode *beforeThis, const TiXmlNode &addThis)
 
TiXmlNodeInsertEndChild (const TiXmlNode &addThis)
 
const TiXmlNodeIterateChildren (const TiXmlNode *previous) const
 
TiXmlNodeIterateChildren (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 char *_value, const TiXmlNode *previous)
 
const TiXmlNodeIterateChildren (const std::string &_value, const TiXmlNode *previous) const
 STL std::string form. More...
 
TiXmlNodeIterateChildren (const std::string &_value, const TiXmlNode *previous)
 STL std::string form. More...
 
const TiXmlNodeLastChild () const
 
TiXmlNodeLastChild ()
 The last child of this node. Will be null if there are no children. More...
 
const TiXmlNodeLastChild (const char *value) 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 std::string &_value) const
 STL std::string form. More...
 
TiXmlNodeLastChild (const std::string &_value)
 STL std::string form. More...
 
TiXmlNodeLinkEndChild (TiXmlNode *addThis)
 
const TiXmlNodeNextSibling (const std::string &_value) const
 STL std::string form. More...
 
TiXmlNodeNextSibling (const std::string &_value)
 STL std::string form. More...
 
const TiXmlNodeNextSibling () const
 Navigate to a sibling node. More...
 
TiXmlNodeNextSibling ()
 
const TiXmlNodeNextSibling (const char *) const
 Navigate to a sibling node with the given 'value'. More...
 
TiXmlNodeNextSibling (const char *_next)
 
const TiXmlElementNextSiblingElement () const
 
TiXmlElementNextSiblingElement ()
 
const TiXmlElementNextSiblingElement (const char *) const
 
TiXmlElementNextSiblingElement (const char *_next)
 
const TiXmlElementNextSiblingElement (const std::string &_value) const
 STL std::string form. More...
 
TiXmlElementNextSiblingElement (const std::string &_value)
 STL std::string form. More...
 
bool NoChildren () const
 Returns true if this node has no children. More...
 
TiXmlNodeParent ()
 One step up the DOM. More...
 
const TiXmlNodeParent () const
 
const TiXmlNodePreviousSibling () const
 Navigate to a sibling node. More...
 
TiXmlNodePreviousSibling ()
 
const TiXmlNodePreviousSibling (const char *) const
 Navigate to a sibling node. More...
 
TiXmlNodePreviousSibling (const char *_prev)
 
const TiXmlNodePreviousSibling (const std::string &_value) const
 STL std::string form. More...
 
TiXmlNodePreviousSibling (const std::string &_value)
 STL std::string form. More...
 
bool RemoveChild (TiXmlNode *removeThis)
 Delete a child of this node. More...
 
TiXmlNodeReplaceChild (TiXmlNode *replaceThis, const TiXmlNode &withThis)
 
void SetValue (const char *_value)
 
void SetValue (const std::string &_value)
 STL std::string form. More...
 
virtual const TiXmlCommentToComment () const
 Cast to a more defined type. Will return null if not of the requested type. More...
 
virtual TiXmlCommentToComment ()
 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 TiXmlDeclarationToDeclaration ()
 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 TiXmlElementToElement ()
 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 TiXmlTextToText ()
 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...
 
virtual TiXmlUnknownToUnknown ()
 Cast to a more defined type. Will return null if not of the requested type. More...
 
int Type () const
 
const char * Value () const
 
const std::string & ValueStr () const
 
const TIXML_STRINGValueTStr () const
 
virtual ~TiXmlNode ()
 
- Public Member Functions inherited from TiXmlBase
int Column () const
 See Row() More...
 
void * GetUserData ()
 Get a pointer to arbitrary user data. More...
 
const void * GetUserData () 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
 
virtual void StreamIn (std::istream *in, TIXML_STRING *tag)
 
- 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 {
  DOCUMENT, ELEMENT, COMMENT, UNKNOWN,
  TEXT, DECLARATION, TYPECOUNT
}
 
- Public Types inherited from TiXmlBase
enum  {
  TIXML_NO_ERROR = 0, TIXML_ERROR, TIXML_ERROR_OPENING_FILE, TIXML_ERROR_OUT_OF_MEMORY,
  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 StreamTo (std::istream *in, int character, TIXML_STRING *tag)
 
static bool StreamWhiteSpace (std::istream *in, TIXML_STRING *tag)
 
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
 
void * userData
 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.

Definition at line 1388 of file tinyxml.h.

Constructor & Destructor Documentation

TiXmlDocument::TiXmlDocument ( )

Create an empty document, that has no name.

Definition at line 893 of file tinyxml.cc.

References ClearError(), tabsize, and useMicrosoftBOM.

Referenced by Clone().

894 {
895  tabsize = 4;
896  useMicrosoftBOM = false;
897  ClearError();
898 }
void ClearError()
Definition: tinyxml.h:1510
TiXmlNode(NodeType _type)
Definition: tinyxml.cc:143
bool useMicrosoftBOM
Definition: tinyxml.h:1553
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 900 of file tinyxml.cc.

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

901 {
902  tabsize = 4;
903  useMicrosoftBOM = false;
904  value = documentName;
905  ClearError();
906 }
void ClearError()
Definition: tinyxml.h:1510
TiXmlNode(NodeType _type)
Definition: tinyxml.cc:143
bool useMicrosoftBOM
Definition: tinyxml.h:1553
TIXML_STRING value
Definition: tinyxml.h:765
TiXmlDocument::TiXmlDocument ( const std::string &  documentName)

Constructor.

Definition at line 910 of file tinyxml.cc.

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

911 {
912  tabsize = 4;
913  useMicrosoftBOM = false;
914  value = documentName;
915  ClearError();
916 }
void ClearError()
Definition: tinyxml.h:1510
TiXmlNode(NodeType _type)
Definition: tinyxml.cc:143
bool useMicrosoftBOM
Definition: tinyxml.h:1553
TIXML_STRING value
Definition: tinyxml.h:765
TiXmlDocument::TiXmlDocument ( const TiXmlDocument copy)

Definition at line 920 of file tinyxml.cc.

References CopyTo().

921 {
922  copy.CopyTo( this );
923 }
void CopyTo(TiXmlDocument *target) const
Definition: tinyxml.cc:1129
TiXmlNode(NodeType _type)
Definition: tinyxml.cc:143
virtual TiXmlDocument::~TiXmlDocument ( )
inlinevirtual

Definition at line 1404 of file tinyxml.h.

1404 {}

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 1170 of file tinyxml.cc.

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

1171 {
1172  if ( visitor->VisitEnter( *this ) )
1173  {
1174  for ( const TiXmlNode* node=FirstChild(); node; node=node->NextSibling() )
1175  {
1176  if ( !node->Accept( visitor ) )
1177  break;
1178  }
1179  }
1180  return visitor->VisitExit( *this );
1181 }
tuple node
Definition: Node.py:50
const TiXmlNode * FirstChild() const
The first child of this node. Will be null if there are no children.
Definition: tinyxml.h:526
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 1510 of file tinyxml.h.

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

Referenced by Parse(), and TiXmlDocument().

1510  { error = false;
1511  errorId = 0;
1512  errorDesc = "";
1514  //errorLocation.last = 0;
1515  }
TIXML_STRING errorDesc
Definition: tinyxml.h:1550
TiXmlCursor errorLocation
Definition: tinyxml.h:1552
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.

Definition at line 1148 of file tinyxml.cc.

References clone(), CopyTo(), and TiXmlDocument().

1149 {
1151  if ( !clone )
1152  return 0;
1153 
1154  CopyTo( clone );
1155  return clone;
1156 }
void CopyTo(TiXmlDocument *target) const
Definition: tinyxml.cc:1129
TiXmlDocument()
Create an empty document, that has no name.
Definition: tinyxml.cc:893
TEveGeoShape * clone(const TEveElement *element, TEveElement *parent)
Definition: eve_macros.cc:135
void TiXmlDocument::CopyTo ( TiXmlDocument target) const
private

Definition at line 1129 of file tinyxml.cc.

References TiXmlNode::Clone(), TiXmlNode::CopyTo(), error, errorDesc, errorId, errorLocation, TiXmlNode::firstChild, TiXmlNode::LinkEndChild(), TiXmlNode::NextSibling(), python.Node::node, tabsize, and useMicrosoftBOM.

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

1130 {
1131  TiXmlNode::CopyTo( target );
1132 
1133  target->error = error;
1134  target->errorId = errorId;
1135  target->errorDesc = errorDesc;
1136  target->tabsize = tabsize;
1137  target->errorLocation = errorLocation;
1138  target->useMicrosoftBOM = useMicrosoftBOM;
1139 
1140  TiXmlNode* node = 0;
1141  for ( node = firstChild; node; node = node->NextSibling() )
1142  {
1143  target->LinkEndChild( node->Clone() );
1144  }
1145 }
TIXML_STRING errorDesc
Definition: tinyxml.h:1550
TiXmlNode * firstChild
Definition: tinyxml.h:762
tuple node
Definition: Node.py:50
TiXmlNode * LinkEndChild(TiXmlNode *addThis)
Definition: tinyxml.cc:192
const TiXmlNode * NextSibling(const std::string &_value) const
STL std::string form.
Definition: tinyxml.h:630
void CopyTo(TiXmlNode *target) const
Definition: tinyxml.cc:168
bool useMicrosoftBOM
Definition: tinyxml.h:1553
virtual TiXmlNode * Clone() const =0
TiXmlCursor errorLocation
Definition: tinyxml.h:1552
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 1459 of file tinyxml.h.

References error.

Referenced by RivetHarvesting::getDPSXYValsErrs(), and LoadFile().

1459 { return error; }
int TiXmlDocument::ErrorCol ( ) const
inline

The column where the error occurred. See ErrorRow()

Definition at line 1477 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 1462 of file tinyxml.h.

References errorDesc.

Referenced by RivetHarvesting::getDPSXYValsErrs().

1462 { return errorDesc.c_str (); }
TIXML_STRING errorDesc
Definition: tinyxml.h:1550
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 1467 of file tinyxml.h.

References errorId.

1467 { 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 1476 of file tinyxml.h.

References errorLocation, and TiXmlCursor::row.

1476 { return errorLocation.row+1; }
TiXmlCursor errorLocation
Definition: tinyxml.h:1552
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 934 of file tinyxml.cc.

References TiXmlNode::Value().

Referenced by RivetHarvesting::getDPSXYValsErrs(), and LoadFile().

935 {
936  // See STL_STRING_BUG below.
937  //StringToBuffer buf( value );
938 
939  return LoadFile( Value(), encoding );
940 }
bool LoadFile(TiXmlEncoding encoding=TIXML_DEFAULT_ENCODING)
Definition: tinyxml.cc:934
const char * Value() const
Definition: tinyxml.h:491
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 955 of file tinyxml.cc.

References mergeVDriftHistosByStation::file, lut2db_cfg::filename, LoadFile(), query::result, SetError(), TIXML_ENCODING_UNKNOWN, TiXmlBase::TIXML_ERROR_OPENING_FILE, TIXML_STRING, TiXmlFOpen(), and TiXmlNode::value.

956 {
957  // There was a really terrifying little bug here. The code:
958  // value = filename
959  // in the STL case, cause the assignment method of the std::string to
960  // be called. What is strange, is that the std::string had the same
961  // address as it's c_str() method, and so bad things happen. Looks
962  // like a bug in the Microsoft STL implementation.
963  // Add an extra string to avoid the crash.
964  TIXML_STRING filename( _filename );
965  value = filename;
966 
967  // reading in binary mode so that tinyxml can normalize the EOL
968  FILE* file = TiXmlFOpen( value.c_str (), "rb" );
969 
970  if ( file )
971  {
972  bool result = LoadFile( file, encoding );
973  fclose( file );
974  return result;
975  }
976  else
977  {
979  return false;
980  }
981 }
bool LoadFile(TiXmlEncoding encoding=TIXML_DEFAULT_ENCODING)
Definition: tinyxml.cc:934
FILE * TiXmlFOpen(const char *filename, const char *mode)
Definition: tinyxml.cc:46
tuple result
Definition: query.py:137
void SetError(int err, const char *errorLocation, TiXmlParsingData *prevData, TiXmlEncoding encoding)
tuple filename
Definition: lut2db_cfg.py:20
TIXML_STRING value
Definition: tinyxml.h:765
#define TIXML_STRING
Definition: tinyxml.h:57
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 983 of file tinyxml.cc.

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

984 {
985  if ( !file )
986  {
988  return false;
989  }
990 
991  // Delete the existing data:
992  Clear();
993  location.Clear();
994 
995  // Get the file size, so we can pre-allocate the string. HUGE speed impact.
996  long length = 0;
997  fseek( file, 0, SEEK_END );
998  length = ftell( file );
999  fseek( file, 0, SEEK_SET );
1000 
1001  // Strange case, but good to handle up front.
1002  if ( length <= 0 )
1003  {
1005  return false;
1006  }
1007 
1008  // If we have a file, assume it is all one big XML file, and read it in.
1009  // The document parser may decide the document ends sooner than the entire file, however.
1011  data.reserve( length );
1012 
1013  // Subtle bug here. TinyXml did use fgets. But from the XML spec:
1014  // 2.11 End-of-Line Handling
1015  // <snip>
1016  // <quote>
1017  // ...the XML processor MUST behave as if it normalized all line breaks in external
1018  // parsed entities (including the document entity) on input, before parsing, by translating
1019  // both the two-character sequence #xD #xA and any #xD that is not followed by #xA to
1020  // a single #xA character.
1021  // </quote>
1022  //
1023  // It is not clear fgets does that, and certainly isn't clear it works cross platform.
1024  // Generally, you expect fgets to translate from the convention of the OS to the c/unix
1025  // convention, and not work generally.
1026 
1027  /*
1028  while( fgets( buf, sizeof(buf), file ) )
1029  {
1030  data += buf;
1031  }
1032  */
1033 
1034  char* buf = new char[ length+1 ];
1035  buf[0] = 0;
1036 
1037  if ( fread( buf, length, 1, file ) != 1 ) {
1038  delete [] buf;
1040  return false;
1041  }
1042 
1043  const char* lastPos = buf;
1044  const char* p = buf;
1045 
1046  buf[length] = 0;
1047  while( *p ) {
1048  assert( p < (buf+length) );
1049  if ( *p == 0xa ) {
1050  // Newline character. No special rules for this. Append all the characters
1051  // since the last string, and include the newline.
1052  data.append( lastPos, (p-lastPos+1) ); // append, include the newline
1053  ++p; // move past the newline
1054  lastPos = p; // and point to the new buffer (may be 0)
1055  assert( p <= (buf+length) );
1056  }
1057  else if ( *p == 0xd ) {
1058  // Carriage return. Append what we have so far, then
1059  // handle moving forward in the buffer.
1060  if ( (p-lastPos) > 0 ) {
1061  data.append( lastPos, p-lastPos ); // do not add the CR
1062  }
1063  data += (char)0xa; // a proper newline
1064 
1065  if ( *(p+1) == 0xa ) {
1066  // Carriage return - new line sequence
1067  p += 2;
1068  lastPos = p;
1069  assert( p <= (buf+length) );
1070  }
1071  else {
1072  // it was followed by something else...that is presumably characters again.
1073  ++p;
1074  lastPos = p;
1075  assert( p <= (buf+length) );
1076  }
1077  }
1078  else {
1079  ++p;
1080  }
1081  }
1082  // Handle any left over characters.
1083  if ( p-lastPos ) {
1084  data.append( lastPos, p-lastPos );
1085  }
1086  delete [] buf;
1087  buf = 0;
1088 
1089  Parse( data.c_str(), 0, encoding );
1090 
1091  if ( Error() )
1092  return false;
1093  else
1094  return true;
1095 }
bool Error() const
Definition: tinyxml.h:1459
void Clear()
Definition: tinyxml.h:107
TiXmlCursor location
Definition: tinyxml.h:377
virtual const char * Parse(const char *p, TiXmlParsingData *data=0, TiXmlEncoding encoding=TIXML_DEFAULT_ENCODING)
void SetError(int err, const char *errorLocation, TiXmlParsingData *prevData, TiXmlEncoding encoding)
char data[epos_bytes_allocation]
Definition: EPOS_Wrapper.h:82
void Clear()
Delete all the children of this node. Does not affect &#39;this&#39;.
Definition: tinyxml.cc:175
#define TIXML_STRING
Definition: tinyxml.h:57
bool TiXmlDocument::LoadFile ( const std::string &  filename,
TiXmlEncoding  encoding = TIXML_DEFAULT_ENCODING 
)
inline
Parameters
encodingSTL std::string version.

Definition at line 1427 of file tinyxml.h.

References LoadFile().

1428  {
1429 // StringToBuffer f( filename );
1430 // return ( f.buffer && LoadFile( f.buffer, encoding ));
1431  return LoadFile( filename.c_str(), encoding );
1432  }
bool LoadFile(TiXmlEncoding encoding=TIXML_DEFAULT_ENCODING)
Definition: tinyxml.cc:934
tuple filename
Definition: lut2db_cfg.py:20
TiXmlDocument & TiXmlDocument::operator= ( const TiXmlDocument copy)

Definition at line 926 of file tinyxml.cc.

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

927 {
928  Clear();
929  copy.CopyTo( this );
930  return *this;
931 }
void CopyTo(TiXmlDocument *target) const
Definition: tinyxml.cc:1129
void Clear()
Delete all the children of this node. Does not affect &#39;this&#39;.
Definition: tinyxml.cc:175
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 712 of file tinyxmlparser.cc.

References TiXmlCursor::Clear(), ClearError(), TiXmlCursor::col, TiXmlParsingData::Cursor(), TiXmlParsingData::cursor, data, TiXmlDeclaration::Encoding(), TiXmlNode::firstChild, TiXmlNode::Identify(), TiXmlNode::LinkEndChild(), TiXmlBase::location, python.Node::node, AlCaHLTBitMon_ParallelJobs::p, 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().

713 {
714  ClearError();
715 
716  // Parse away, at the document level. Since a document
717  // contains nothing but other tags, most of what happens
718  // here is skipping white space.
719  if ( !p || !*p )
720  {
722  return 0;
723  }
724 
725  // Note that, for a document, this needs to come
726  // before the while space skip, so that parsing
727  // starts from the pointer we are given.
728  location.Clear();
729  if ( prevData )
730  {
731  location.row = prevData->cursor.row;
732  location.col = prevData->cursor.col;
733  }
734  else
735  {
736  location.row = 0;
737  location.col = 0;
738  }
740  location = data.Cursor();
741 
742  if ( encoding == TIXML_ENCODING_UNKNOWN )
743  {
744  // Check for the Microsoft UTF-8 lead bytes.
745  const unsigned char* pU = (const unsigned char*)p;
746  if ( *(pU+0) && *(pU+0) == TIXML_UTF_LEAD_0
747  && *(pU+1) && *(pU+1) == TIXML_UTF_LEAD_1
748  && *(pU+2) && *(pU+2) == TIXML_UTF_LEAD_2 )
749  {
750  encoding = TIXML_ENCODING_UTF8;
751  useMicrosoftBOM = true;
752  }
753  }
754 
755  p = SkipWhiteSpace( p, encoding );
756  if ( !p )
757  {
759  return 0;
760  }
761 
762  while ( p && *p )
763  {
764  TiXmlNode* node = Identify( p, encoding );
765  if ( node )
766  {
767  p = node->Parse( p, &data, encoding );
768  // LinkEndChild just returns the input pointer unmodified,
769  // except if node is deleted, in which case it returns 0.
770  node = LinkEndChild( node );
771  }
772  else
773  {
774  break;
775  }
776 
777  // Did we get encoding info?
778  if ( encoding == TIXML_ENCODING_UNKNOWN
779  && node && node->ToDeclaration() )
780  {
781  TiXmlDeclaration* dec = node->ToDeclaration();
782  const char* enc = dec->Encoding();
783  assert( enc );
784 
785  if ( *enc == 0 )
786  encoding = TIXML_ENCODING_UTF8;
787  else if ( StringEqual( enc, "UTF-8", true, TIXML_ENCODING_UNKNOWN ) )
788  encoding = TIXML_ENCODING_UTF8;
789  else if ( StringEqual( enc, "UTF8", true, TIXML_ENCODING_UNKNOWN ) )
790  encoding = TIXML_ENCODING_UTF8; // incorrect, but be nice
791  else
792  encoding = TIXML_ENCODING_LEGACY;
793  }
794 
795  p = SkipWhiteSpace( p, encoding );
796  }
797 
798  // Was this empty?
799  if ( !firstChild ) {
800  SetError( TIXML_ERROR_DOCUMENT_EMPTY, 0, 0, encoding );
801  return 0;
802  }
803 
804  // All is well.
805  return p;
806 }
const unsigned char TIXML_UTF_LEAD_2
TiXmlNode * firstChild
Definition: tinyxml.h:762
int TabSize() const
Definition: tinyxml.h:1505
void ClearError()
Definition: tinyxml.h:1510
void Clear()
Definition: tinyxml.h:107
const TiXmlCursor & Cursor()
const unsigned char TIXML_UTF_LEAD_0
tuple node
Definition: Node.py:50
virtual const TiXmlDeclaration * ToDeclaration() const
Cast to a more defined type. Will return null if not of the requested type.
Definition: tinyxml.h:706
const char * Encoding() const
Encoding. Will return an empty string if none was found.
Definition: tinyxml.h:1306
TiXmlNode * LinkEndChild(TiXmlNode *addThis)
Definition: tinyxml.cc:192
const unsigned char TIXML_UTF_LEAD_1
TiXmlCursor location
Definition: tinyxml.h:377
virtual const char * Parse(const char *p, TiXmlParsingData *data, TiXmlEncoding encoding)=0
static const char * SkipWhiteSpace(const char *, TiXmlEncoding encoding)
TiXmlNode * Identify(const char *start, TiXmlEncoding encoding)
static bool StringEqual(const char *p, const char *endTag, bool ignoreCase, TiXmlEncoding encoding)
void SetError(int err, const char *errorLocation, TiXmlParsingData *prevData, TiXmlEncoding encoding)
char data[epos_bytes_allocation]
Definition: EPOS_Wrapper.h:82
bool useMicrosoftBOM
Definition: tinyxml.h:1553
void TiXmlDocument::Print ( void  ) const
inline

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

Definition at line 1518 of file tinyxml.h.

References Print().

Referenced by Print(), and SaveFile().

1518 { Print( stdout, 0 ); }
void Print() const
Definition: tinyxml.h:1518
void TiXmlDocument::Print ( FILE *  cfile,
int  depth = 0 
) const
virtual

Print this Document to a FILE stream.

Implements TiXmlBase.

Definition at line 1159 of file tinyxml.cc.

References TiXmlNode::FirstChild(), and python.Node::node.

1160 {
1161  assert( cfile );
1162  for ( const TiXmlNode* node=FirstChild(); node; node=node->NextSibling() )
1163  {
1164  node->Print( cfile, depth );
1165  fprintf( cfile, "\n" );
1166  }
1167 }
tuple node
Definition: Node.py:50
const TiXmlNode * FirstChild() const
The first child of this node. Will be null if there are no children.
Definition: tinyxml.h:526
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 1451 of file tinyxml.h.

References TiXmlNode::FirstChildElement().

1451 { return FirstChildElement(); }
const TiXmlElement * FirstChildElement() const
Convenience function to get through elements.
Definition: tinyxml.cc:439
TiXmlElement* TiXmlDocument::RootElement ( )
inline

Definition at line 1452 of file tinyxml.h.

References TiXmlNode::FirstChildElement().

1452 { return FirstChildElement(); }
const TiXmlElement * FirstChildElement() const
Convenience function to get through elements.
Definition: tinyxml.cc:439
bool TiXmlDocument::SaveFile ( ) const

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

Definition at line 943 of file tinyxml.cc.

References TiXmlNode::Value().

Referenced by SaveFile().

944 {
945  // See STL_STRING_BUG below.
946 // StringToBuffer buf( value );
947 //
948 // if ( buf.buffer && SaveFile( buf.buffer ) )
949 // return true;
950 //
951 // return false;
952  return SaveFile( Value() );
953 }
bool SaveFile() const
Save a file using the current document value. Returns true if successful.
Definition: tinyxml.cc:943
const char * Value() const
Definition: tinyxml.h:491
bool TiXmlDocument::SaveFile ( const char *  filename) const

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

Definition at line 1098 of file tinyxml.cc.

References query::result, SaveFile(), and TiXmlFOpen().

1099 {
1100  // The old c stuff lives on...
1101  FILE* fp = TiXmlFOpen( filename, "w" );
1102  if ( fp )
1103  {
1104  bool result = SaveFile( fp );
1105  fclose( fp );
1106  return result;
1107  }
1108  return false;
1109 }
FILE * TiXmlFOpen(const char *filename, const char *mode)
Definition: tinyxml.cc:46
tuple result
Definition: query.py:137
bool SaveFile() const
Save a file using the current document value. Returns true if successful.
Definition: tinyxml.cc:943
tuple filename
Definition: lut2db_cfg.py:20
bool TiXmlDocument::SaveFile ( FILE *  fp) const

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

Definition at line 1112 of file tinyxml.cc.

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

1113 {
1114  if ( useMicrosoftBOM )
1115  {
1116  const unsigned char TIXML_UTF_LEAD_0 = 0xefU;
1117  const unsigned char TIXML_UTF_LEAD_1 = 0xbbU;
1118  const unsigned char TIXML_UTF_LEAD_2 = 0xbfU;
1119 
1120  fputc( TIXML_UTF_LEAD_0, fp );
1121  fputc( TIXML_UTF_LEAD_1, fp );
1122  fputc( TIXML_UTF_LEAD_2, fp );
1123  }
1124  Print( fp, 0 );
1125  return (ferror(fp) == 0);
1126 }
const unsigned char TIXML_UTF_LEAD_2
const unsigned char TIXML_UTF_LEAD_0
const unsigned char TIXML_UTF_LEAD_1
void Print() const
Definition: tinyxml.h:1518
bool useMicrosoftBOM
Definition: tinyxml.h:1553
bool TiXmlDocument::SaveFile ( const std::string &  filename) const
inline

< STL std::string version.

Definition at line 1433 of file tinyxml.h.

References lut2db_cfg::filename, and SaveFile().

1434  {
1435 // StringToBuffer f( filename );
1436 // return ( f.buffer && SaveFile( f.buffer ));
1437  return SaveFile( filename.c_str() );
1438  }
bool SaveFile() const
Save a file using the current document value. Returns true if successful.
Definition: tinyxml.cc:943
tuple filename
Definition: lut2db_cfg.py:20
void TiXmlDocument::SetError ( int  err,
const char *  errorLocation,
TiXmlParsingData prevData,
TiXmlEncoding  encoding 
)

Definition at line 808 of file tinyxmlparser.cc.

References TiXmlCursor::Clear(), TiXmlParsingData::Cursor(), error, errorDesc, errorId, errorLocation, TiXmlBase::errorString, TiXmlParsingData::Stamp(), and TiXmlBase::TIXML_ERROR_STRING_COUNT.

Referenced by TiXmlNode::Identify(), TiXmlNode::InsertAfterChild(), TiXmlNode::InsertBeforeChild(), TiXmlNode::InsertEndChild(), TiXmlNode::LinkEndChild(), LoadFile(), TiXmlAttribute::Parse(), TiXmlElement::Parse(), TiXmlComment::Parse(), TiXmlText::Parse(), TiXmlDeclaration::Parse(), TiXmlUnknown::Parse(), Parse(), TiXmlElement::ReadValue(), TiXmlElement::SetAttribute(), TiXmlElement::StreamIn(), TiXmlComment::StreamIn(), TiXmlText::StreamIn(), TiXmlDeclaration::StreamIn(), TiXmlUnknown::StreamIn(), and StreamIn().

809 {
810  // The first error in a chain is more accurate - don't set again!
811  if ( error )
812  return;
813 
814  assert( err > 0 && err < TIXML_ERROR_STRING_COUNT );
815  error = true;
816  errorId = err;
818 
820  if ( pError && data )
821  {
822  data->Stamp( pError, encoding );
823  errorLocation = data->Cursor();
824  }
825 }
TIXML_STRING errorDesc
Definition: tinyxml.h:1550
void Clear()
Definition: tinyxml.h:107
static const char * errorString[TIXML_ERROR_STRING_COUNT]
Definition: tinyxml.h:375
char data[epos_bytes_allocation]
Definition: EPOS_Wrapper.h:82
TiXmlCursor errorLocation
Definition: tinyxml.h:1552
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 1503 of file tinyxml.h.

References tabsize.

1503 { tabsize = _tabsize; }
void TiXmlDocument::StreamIn ( std::istream *  in,
TIXML_STRING tag 
)
protectedvirtual

Implements TiXmlNode.

Definition at line 649 of file tinyxmlparser.cc.

References trackerHits::c, TiXmlNode::Identify(), python.Node::node, 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().

650 {
651  // The basic issue with a document is that we don't know what we're
652  // streaming. Read something presumed to be a tag (and hope), then
653  // identify it, and call the appropriate stream method on the tag.
654  //
655  // This "pre-streaming" will never read the closing ">" so the
656  // sub-tag can orient itself.
657 
658  if ( !StreamTo( in, '<', tag ) )
659  {
661  return;
662  }
663 
664  while ( in->good() )
665  {
666  int tagIndex = (int) tag->length();
667  while ( in->good() && in->peek() != '>' )
668  {
669  int c = in->get();
670  if ( c <= 0 )
671  {
673  break;
674  }
675  (*tag) += (char) c;
676  }
677 
678  if ( in->good() )
679  {
680  // We now have something we presume to be a node of
681  // some sort. Identify it, and call the node to
682  // continue streaming.
683  TiXmlNode* node = Identify( tag->c_str() + tagIndex, TIXML_DEFAULT_ENCODING );
684 
685  if ( node )
686  {
687  node->StreamIn( in, tag );
688  bool isElement = node->ToElement() != 0;
689  delete node;
690  node = 0;
691 
692  // If this is the root element, we're done. Parsing will be
693  // done by the >> operator.
694  if ( isElement )
695  {
696  return;
697  }
698  }
699  else
700  {
702  return;
703  }
704  }
705  }
706  // We should have returned sooner.
708 }
virtual void StreamIn(std::istream *in, TIXML_STRING *tag)=0
tuple node
Definition: Node.py:50
const TiXmlEncoding TIXML_DEFAULT_ENCODING
Definition: tinyxml.h:174
TiXmlNode * Identify(const char *start, TiXmlEncoding encoding)
static bool StreamTo(std::istream *in, int character, TIXML_STRING *tag)
virtual const TiXmlElement * ToElement() const
Cast to a more defined type. Will return null if not of the requested type.
Definition: tinyxml.h:702
void SetError(int err, const char *errorLocation, TiXmlParsingData *prevData, TiXmlEncoding encoding)
int TiXmlDocument::TabSize ( ) const
inline

Definition at line 1505 of file tinyxml.h.

References tabsize.

Referenced by Parse().

1505 { return tabsize; }
virtual const TiXmlDocument* TiXmlDocument::ToDocument ( ) const
inlinevirtual

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

Reimplemented from TiXmlNode.

Definition at line 1531 of file tinyxml.h.

virtual TiXmlDocument* TiXmlDocument::ToDocument ( )
inlinevirtual

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

Reimplemented from TiXmlNode.

Definition at line 1532 of file tinyxml.h.

Member Data Documentation

bool TiXmlDocument::error
private
TIXML_STRING TiXmlDocument::errorDesc
private

Definition at line 1550 of file tinyxml.h.

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

int TiXmlDocument::errorId
private

Definition at line 1549 of file tinyxml.h.

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

TiXmlCursor TiXmlDocument::errorLocation
private

Definition at line 1552 of file tinyxml.h.

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

int TiXmlDocument::tabsize
private

Definition at line 1551 of file tinyxml.h.

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

bool TiXmlDocument::useMicrosoftBOM
private

Definition at line 1553 of file tinyxml.h.

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