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)
 
void operator= (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 1386 of file tinyxml.h.

Constructor & Destructor Documentation

TiXmlDocument::TiXmlDocument ( )

Create an empty document, that has no name.

Definition at line 886 of file tinyxml.cc.

References ClearError(), tabsize, and useMicrosoftBOM.

Referenced by Clone().

887 {
888  tabsize = 4;
889  useMicrosoftBOM = false;
890  ClearError();
891 }
void ClearError()
Definition: tinyxml.h:1508
TiXmlNode(NodeType _type)
Definition: tinyxml.cc:137
bool useMicrosoftBOM
Definition: tinyxml.h:1551
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 tinyxml.cc.

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

894 {
895  tabsize = 4;
896  useMicrosoftBOM = false;
897  value = documentName;
898  ClearError();
899 }
void ClearError()
Definition: tinyxml.h:1508
TiXmlNode(NodeType _type)
Definition: tinyxml.cc:137
bool useMicrosoftBOM
Definition: tinyxml.h:1551
TIXML_STRING value
Definition: tinyxml.h:763
TiXmlDocument::TiXmlDocument ( const std::string &  documentName)

Constructor.

Definition at line 903 of file tinyxml.cc.

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

904 {
905  tabsize = 4;
906  useMicrosoftBOM = false;
907  value = documentName;
908  ClearError();
909 }
void ClearError()
Definition: tinyxml.h:1508
TiXmlNode(NodeType _type)
Definition: tinyxml.cc:137
bool useMicrosoftBOM
Definition: tinyxml.h:1551
TIXML_STRING value
Definition: tinyxml.h:763
TiXmlDocument::TiXmlDocument ( const TiXmlDocument copy)

Definition at line 913 of file tinyxml.cc.

References CopyTo().

914 {
915  copy.CopyTo( this );
916 }
void CopyTo(TiXmlDocument *target) const
Definition: tinyxml.cc:1121
TiXmlNode(NodeType _type)
Definition: tinyxml.cc:137
virtual TiXmlDocument::~TiXmlDocument ( )
inlinevirtual

Definition at line 1402 of file tinyxml.h.

1402 {}

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

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

1163 {
1164  if ( visitor->VisitEnter( *this ) )
1165  {
1166  for ( const TiXmlNode* node=FirstChild(); node; node=node->NextSibling() )
1167  {
1168  if ( !node->Accept( visitor ) )
1169  break;
1170  }
1171  }
1172  return visitor->VisitExit( *this );
1173 }
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:524
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 1508 of file tinyxml.h.

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

Referenced by Parse(), and TiXmlDocument().

1508  { error = false;
1509  errorId = 0;
1510  errorDesc = "";
1512  //errorLocation.last = 0;
1513  }
TIXML_STRING errorDesc
Definition: tinyxml.h:1548
TiXmlCursor errorLocation
Definition: tinyxml.h:1550
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 1140 of file tinyxml.cc.

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

1141 {
1143  if ( !clone )
1144  return 0;
1145 
1146  CopyTo( clone );
1147  return clone;
1148 }
void CopyTo(TiXmlDocument *target) const
Definition: tinyxml.cc:1121
TiXmlDocument()
Create an empty document, that has no name.
Definition: tinyxml.cc:886
T * clone(const T *tp)
Definition: Ptr.h:42
void TiXmlDocument::CopyTo ( TiXmlDocument target) const
private

Definition at line 1121 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().

1122 {
1123  TiXmlNode::CopyTo( target );
1124 
1125  target->error = error;
1126  target->errorId = errorId;
1127  target->errorDesc = errorDesc;
1128  target->tabsize = tabsize;
1129  target->errorLocation = errorLocation;
1130  target->useMicrosoftBOM = useMicrosoftBOM;
1131 
1132  TiXmlNode* node = 0;
1133  for ( node = firstChild; node; node = node->NextSibling() )
1134  {
1135  target->LinkEndChild( node->Clone() );
1136  }
1137 }
TIXML_STRING errorDesc
Definition: tinyxml.h:1548
TiXmlNode * firstChild
Definition: tinyxml.h:760
tuple node
Definition: Node.py:50
TiXmlNode * LinkEndChild(TiXmlNode *addThis)
Definition: tinyxml.cc:186
const TiXmlNode * NextSibling(const std::string &_value) const
STL std::string form.
Definition: tinyxml.h:628
void CopyTo(TiXmlNode *target) const
Definition: tinyxml.cc:162
bool useMicrosoftBOM
Definition: tinyxml.h:1551
virtual TiXmlNode * Clone() const =0
TiXmlCursor errorLocation
Definition: tinyxml.h:1550
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 1457 of file tinyxml.h.

References error.

Referenced by LoadFile().

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

The column where the error occurred. See ErrorRow()

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

References errorDesc.

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

References errorId.

1465 { 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 1474 of file tinyxml.h.

References errorLocation, and TiXmlCursor::row.

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

References TiXmlNode::Value().

Referenced by LoadFile().

927 {
928  // See STL_STRING_BUG below.
929  //StringToBuffer buf( value );
930 
931  return LoadFile( Value(), encoding );
932 }
bool LoadFile(TiXmlEncoding encoding=TIXML_DEFAULT_ENCODING)
Definition: tinyxml.cc:926
const char * Value() const
Definition: tinyxml.h:489
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 947 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.

948 {
949  // There was a really terrifying little bug here. The code:
950  // value = filename
951  // in the STL case, cause the assignment method of the std::string to
952  // be called. What is strange, is that the std::string had the same
953  // address as it's c_str() method, and so bad things happen. Looks
954  // like a bug in the Microsoft STL implementation.
955  // Add an extra string to avoid the crash.
956  TIXML_STRING filename( _filename );
957  value = filename;
958 
959  // reading in binary mode so that tinyxml can normalize the EOL
960  FILE* file = TiXmlFOpen( value.c_str (), "rb" );
961 
962  if ( file )
963  {
964  bool result = LoadFile( file, encoding );
965  fclose( file );
966  return result;
967  }
968  else
969  {
971  return false;
972  }
973 }
bool LoadFile(TiXmlEncoding encoding=TIXML_DEFAULT_ENCODING)
Definition: tinyxml.cc:926
FILE * TiXmlFOpen(const char *filename, const char *mode)
Definition: tinyxml.cc:40
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:763
#define TIXML_STRING
Definition: tinyxml.h:51
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 975 of file tinyxml.cc.

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

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

Definition at line 1425 of file tinyxml.h.

References LoadFile().

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

Definition at line 919 of file tinyxml.cc.

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

920 {
921  Clear();
922  copy.CopyTo( this );
923 }
void CopyTo(TiXmlDocument *target) const
Definition: tinyxml.cc:1121
void Clear()
Delete all the children of this node. Does not affect &#39;this&#39;.
Definition: tinyxml.cc:169
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 709 of file tinyxmlparser.cc.

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

710 {
711  ClearError();
712 
713  // Parse away, at the document level. Since a document
714  // contains nothing but other tags, most of what happens
715  // here is skipping white space.
716  if ( !p || !*p )
717  {
719  return 0;
720  }
721 
722  // Note that, for a document, this needs to come
723  // before the while space skip, so that parsing
724  // starts from the pointer we are given.
725  location.Clear();
726  if ( prevData )
727  {
728  location.row = prevData->cursor.row;
729  location.col = prevData->cursor.col;
730  }
731  else
732  {
733  location.row = 0;
734  location.col = 0;
735  }
737  location = data.Cursor();
738 
739  if ( encoding == TIXML_ENCODING_UNKNOWN )
740  {
741  // Check for the Microsoft UTF-8 lead bytes.
742  const unsigned char* pU = (const unsigned char*)p;
743  if ( *(pU+0) && *(pU+0) == TIXML_UTF_LEAD_0
744  && *(pU+1) && *(pU+1) == TIXML_UTF_LEAD_1
745  && *(pU+2) && *(pU+2) == TIXML_UTF_LEAD_2 )
746  {
747  encoding = TIXML_ENCODING_UTF8;
748  useMicrosoftBOM = true;
749  }
750  }
751 
752  p = SkipWhiteSpace( p, encoding );
753  if ( !p )
754  {
756  return 0;
757  }
758 
759  while ( p && *p )
760  {
761  TiXmlNode* node = Identify( p, encoding );
762  if ( node )
763  {
764  p = node->Parse( p, &data, encoding );
765  LinkEndChild( node );
766  }
767  else
768  {
769  break;
770  }
771 
772  // Did we get encoding info?
773  if ( encoding == TIXML_ENCODING_UNKNOWN
774  && node->ToDeclaration() )
775  {
776  TiXmlDeclaration* dec = node->ToDeclaration();
777  const char* enc = dec->Encoding();
778  assert( enc );
779 
780  if ( *enc == 0 )
781  encoding = TIXML_ENCODING_UTF8;
782  else if ( StringEqual( enc, "UTF-8", true, TIXML_ENCODING_UNKNOWN ) )
783  encoding = TIXML_ENCODING_UTF8;
784  else if ( StringEqual( enc, "UTF8", true, TIXML_ENCODING_UNKNOWN ) )
785  encoding = TIXML_ENCODING_UTF8; // incorrect, but be nice
786  else
787  encoding = TIXML_ENCODING_LEGACY;
788  }
789 
790  p = SkipWhiteSpace( p, encoding );
791  }
792 
793  // Was this empty?
794  if ( !firstChild ) {
795  SetError( TIXML_ERROR_DOCUMENT_EMPTY, 0, 0, encoding );
796  return 0;
797  }
798 
799  // All is well.
800  return p;
801 }
const unsigned char TIXML_UTF_LEAD_2
TiXmlNode * firstChild
Definition: tinyxml.h:760
int TabSize() const
Definition: tinyxml.h:1503
void ClearError()
Definition: tinyxml.h:1508
void Clear()
Definition: tinyxml.h:105
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:704
const char * Encoding() const
Encoding. Will return an empty string if none was found.
Definition: tinyxml.h:1304
TiXmlNode * LinkEndChild(TiXmlNode *addThis)
Definition: tinyxml.cc:186
const unsigned char TIXML_UTF_LEAD_1
TiXmlCursor location
Definition: tinyxml.h:375
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)
bool useMicrosoftBOM
Definition: tinyxml.h:1551
void TiXmlDocument::Print ( void  ) const
inline

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

Definition at line 1516 of file tinyxml.h.

References Print().

Referenced by Print(), and SaveFile().

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

Print this Document to a FILE stream.

Implements TiXmlBase.

Definition at line 1151 of file tinyxml.cc.

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

1152 {
1153  assert( cfile );
1154  for ( const TiXmlNode* node=FirstChild(); node; node=node->NextSibling() )
1155  {
1156  node->Print( cfile, depth );
1157  fprintf( cfile, "\n" );
1158  }
1159 }
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:524
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 1449 of file tinyxml.h.

References TiXmlNode::FirstChildElement().

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

Definition at line 1450 of file tinyxml.h.

References TiXmlNode::FirstChildElement().

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

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

Definition at line 935 of file tinyxml.cc.

References TiXmlNode::Value().

Referenced by SaveFile().

936 {
937  // See STL_STRING_BUG below.
938 // StringToBuffer buf( value );
939 //
940 // if ( buf.buffer && SaveFile( buf.buffer ) )
941 // return true;
942 //
943 // return false;
944  return SaveFile( Value() );
945 }
bool SaveFile() const
Save a file using the current document value. Returns true if successful.
Definition: tinyxml.cc:935
const char * Value() const
Definition: tinyxml.h:489
bool TiXmlDocument::SaveFile ( const char *  filename) const

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

Definition at line 1090 of file tinyxml.cc.

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

1091 {
1092  // The old c stuff lives on...
1093  FILE* fp = TiXmlFOpen( filename, "w" );
1094  if ( fp )
1095  {
1096  bool result = SaveFile( fp );
1097  fclose( fp );
1098  return result;
1099  }
1100  return false;
1101 }
FILE * TiXmlFOpen(const char *filename, const char *mode)
Definition: tinyxml.cc:40
tuple result
Definition: query.py:137
bool SaveFile() const
Save a file using the current document value. Returns true if successful.
Definition: tinyxml.cc:935
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 1104 of file tinyxml.cc.

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

1105 {
1106  if ( useMicrosoftBOM )
1107  {
1108  const unsigned char TIXML_UTF_LEAD_0 = 0xefU;
1109  const unsigned char TIXML_UTF_LEAD_1 = 0xbbU;
1110  const unsigned char TIXML_UTF_LEAD_2 = 0xbfU;
1111 
1112  fputc( TIXML_UTF_LEAD_0, fp );
1113  fputc( TIXML_UTF_LEAD_1, fp );
1114  fputc( TIXML_UTF_LEAD_2, fp );
1115  }
1116  Print( fp, 0 );
1117  return (ferror(fp) == 0);
1118 }
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:1516
bool useMicrosoftBOM
Definition: tinyxml.h:1551
bool TiXmlDocument::SaveFile ( const std::string &  filename) const
inline

< STL std::string version.

Definition at line 1431 of file tinyxml.h.

References lut2db_cfg::filename, and SaveFile().

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

Definition at line 803 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().

804 {
805  // The first error in a chain is more accurate - don't set again!
806  if ( error )
807  return;
808 
809  assert( err > 0 && err < TIXML_ERROR_STRING_COUNT );
810  error = true;
811  errorId = err;
813 
815  if ( pError && data )
816  {
817  data->Stamp( pError, encoding );
818  errorLocation = data->Cursor();
819  }
820 }
TIXML_STRING errorDesc
Definition: tinyxml.h:1548
void Clear()
Definition: tinyxml.h:105
static const char * errorString[TIXML_ERROR_STRING_COUNT]
Definition: tinyxml.h:373
TiXmlCursor errorLocation
Definition: tinyxml.h:1550
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 1501 of file tinyxml.h.

References tabsize.

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

Implements TiXmlNode.

Definition at line 646 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().

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

Definition at line 1503 of file tinyxml.h.

References tabsize.

Referenced by Parse().

1503 { 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 1529 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 1530 of file tinyxml.h.

Member Data Documentation

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

Definition at line 1548 of file tinyxml.h.

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

int TiXmlDocument::errorId
private

Definition at line 1547 of file tinyxml.h.

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

TiXmlCursor TiXmlDocument::errorLocation
private

Definition at line 1550 of file tinyxml.h.

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

int TiXmlDocument::tabsize
private

Definition at line 1549 of file tinyxml.h.

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

bool TiXmlDocument::useMicrosoftBOM
private

Definition at line 1551 of file tinyxml.h.

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