ReactOS  0.4.11-dev-946-g431643b
tinyxml2::XMLDocument Class Reference

#include <tinyxml2.h>

Inheritance diagram for tinyxml2::XMLDocument:
Collaboration diagram for tinyxml2::XMLDocument:

Public Member Functions

 XMLDocument (bool processEntities=true, Whitespace=PRESERVE_WHITESPACE)
 constructor More...
 
 ~XMLDocument ()
 
virtual XMLDocumentToDocument ()
 Safely cast to a Document, or null. More...
 
virtual const XMLDocumentToDocument () const
 
XMLError Parse (const char *xml, size_t nBytes=(size_t)(-1))
 
XMLError LoadFile (const char *filename)
 
XMLError LoadFile (FILE *)
 
XMLError SaveFile (const char *filename, bool compact=false)
 
XMLError SaveFile (FILE *fp, bool compact=false)
 
bool ProcessEntities () const
 
Whitespace WhitespaceMode () const
 
bool HasBOM () const
 
void SetBOM (bool useBOM)
 
XMLElementRootElement ()
 
const XMLElementRootElement () const
 
void Print (XMLPrinter *streamer=0) const
 
virtual bool Accept (XMLVisitor *visitor) const
 
XMLElementNewElement (const char *name)
 
XMLCommentNewComment (const char *comment)
 
XMLTextNewText (const char *text)
 
XMLDeclarationNewDeclaration (const char *text=0)
 
XMLUnknownNewUnknown (const char *text)
 
void DeleteNode (XMLNode *node)
 
void SetError (XMLError error, const char *str1, const char *str2)
 
bool Error () const
 Return true if there was an error parsing the document. More...
 
XMLError ErrorID () const
 Return the errorID. More...
 
const charErrorName () const
 
const charGetErrorStr1 () const
 Return a possibly helpful diagnostic location or string. More...
 
const charGetErrorStr2 () const
 Return a possibly helpful secondary diagnostic location or string. More...
 
void PrintError () const
 If there is an error, print it to stdout. More...
 
void Clear ()
 Clear the document, resetting it to the initial state. More...
 
charIdentify (char *p, XMLNode **node)
 
virtual XMLNodeShallowClone (XMLDocument *) const
 
virtual bool ShallowEqual (const XMLNode *) const
 
- Public Member Functions inherited from tinyxml2::XMLNode
const XMLDocumentGetDocument () const
 Get the XMLDocument that owns this XMLNode. More...
 
XMLDocumentGetDocument ()
 Get the XMLDocument that owns this XMLNode. More...
 
virtual XMLElementToElement ()
 Safely cast to an Element, or null. More...
 
virtual XMLTextToText ()
 Safely cast to Text, or null. More...
 
virtual XMLCommentToComment ()
 Safely cast to a Comment, or null. More...
 
virtual XMLDeclarationToDeclaration ()
 Safely cast to a Declaration, or null. More...
 
virtual XMLUnknownToUnknown ()
 Safely cast to an Unknown, or null. More...
 
virtual const XMLElementToElement () const
 
virtual const XMLTextToText () const
 
virtual const XMLCommentToComment () const
 
virtual const XMLDeclarationToDeclaration () const
 
virtual const XMLUnknownToUnknown () const
 
const charValue () const
 
void SetValue (const char *val, bool staticMem=false)
 
const XMLNodeParent () const
 Get the parent of this node on the DOM. More...
 
XMLNodeParent ()
 
bool NoChildren () const
 Returns true if this node has no children. More...
 
const XMLNodeFirstChild () const
 Get the first child node, or null if none exists. More...
 
XMLNodeFirstChild ()
 
const XMLElementFirstChildElement (const char *name=0) const
 
XMLElementFirstChildElement (const char *name=0)
 
const XMLNodeLastChild () const
 Get the last child node, or null if none exists. More...
 
XMLNodeLastChild ()
 
const XMLElementLastChildElement (const char *name=0) const
 
XMLElementLastChildElement (const char *name=0)
 
const XMLNodePreviousSibling () const
 Get the previous (left) sibling node of this node. More...
 
XMLNodePreviousSibling ()
 
const XMLElementPreviousSiblingElement (const char *name=0) const
 Get the previous (left) sibling element of this node, with an optionally supplied name. More...
 
XMLElementPreviousSiblingElement (const char *name=0)
 
const XMLNodeNextSibling () const
 Get the next (right) sibling node of this node. More...
 
XMLNodeNextSibling ()
 
const XMLElementNextSiblingElement (const char *name=0) const
 Get the next (right) sibling element of this node, with an optionally supplied name. More...
 
XMLElementNextSiblingElement (const char *name=0)
 
XMLNodeInsertEndChild (XMLNode *addThis)
 
XMLNodeLinkEndChild (XMLNode *addThis)
 
XMLNodeInsertFirstChild (XMLNode *addThis)
 
XMLNodeInsertAfterChild (XMLNode *afterThis, XMLNode *addThis)
 
void DeleteChildren ()
 
void DeleteChild (XMLNode *node)
 

Private Member Functions

 XMLDocument (const XMLDocument &)
 
void operator= (const XMLDocument &)
 
void Parse ()
 

Private Attributes

bool _writeBOM
 
bool _processEntities
 
XMLError _errorID
 
Whitespace _whitespace
 
const char_errorStr1
 
const char_errorStr2
 
char_charBuffer
 
MemPoolT< sizeof(XMLElement) > _elementPool
 
MemPoolT< sizeof(XMLAttribute) > _attributePool
 
MemPoolT< sizeof(XMLText) > _textPool
 
MemPoolT< sizeof(XMLComment) > _commentPool
 

Static Private Attributes

static const char_errorNames [XML_ERROR_COUNT]
 

Friends

class XMLElement
 

Additional Inherited Members

- Protected Member Functions inherited from tinyxml2::XMLNode
 XMLNode (XMLDocument *)
 
virtual ~XMLNode ()
 
virtual charParseDeep (char *, StrPair *)
 
- Protected Attributes inherited from tinyxml2::XMLNode
XMLDocument_document
 
XMLNode_parent
 
StrPair _value
 
XMLNode_firstChild
 
XMLNode_lastChild
 
XMLNode_prev
 
XMLNode_next
 

Detailed Description

A Document binds together all the functionality. It can be saved, loaded, and printed to the screen. All Nodes are connected and allocated to a Document. If the Document is deleted, all its Nodes are also deleted.

Definition at line 1520 of file tinyxml2.h.

Constructor & Destructor Documentation

◆ XMLDocument() [1/2]

tinyxml2::XMLDocument::XMLDocument ( bool  processEntities = true,
Whitespace  whitespace = PRESERVE_WHITESPACE 
)

constructor

Definition at line 1770 of file tinyxml2.cpp.

1770  :
1771  XMLNode( 0 ),
1772  _writeBOM( false ),
1773  _processEntities( processEntities ),
1776  _errorStr1( 0 ),
1777  _errorStr2( 0 ),
1778  _charBuffer( 0 )
1779 {
1780  // avoid VC++ C4355 warning about 'this' in initializer list (C4355 is off by default in VS2012+)
1781  _document = this;
1782 }
XMLNode(XMLDocument *)
Definition: tinyxml2.cpp:701
Whitespace _whitespace
Definition: tinyxml2.h:1717
const char * _errorStr1
Definition: tinyxml2.h:1718
const char * _errorStr2
Definition: tinyxml2.h:1719
XMLDocument * _document
Definition: tinyxml2.h:861
static const char whitespace[]
Definition: main.c:63

◆ ~XMLDocument()

tinyxml2::XMLDocument::~XMLDocument ( )

Definition at line 1785 of file tinyxml2.cpp.

1786 {
1787  Clear();
1788 }
void Clear()
Clear the document, resetting it to the initial state.
Definition: tinyxml2.cpp:1791

◆ XMLDocument() [2/2]

tinyxml2::XMLDocument::XMLDocument ( const XMLDocument )
private

Member Function Documentation

◆ Accept()

bool tinyxml2::XMLDocument::Accept ( XMLVisitor visitor) const
virtual

Accept a hierarchical visit of the nodes in the TinyXML-2 DOM. Every node in the XML tree will be conditionally visited and the host will be called back via the XMLVisitor interface.

This is essentially a SAX interface for TinyXML-2. (Note however it doesn't re-parse the XML for the callbacks, so the performance of TinyXML-2 is unchanged by using this interface versus any other.)

The interface has been based on ideas from:

Which are both good references for "visiting".

An example of using Accept():

XMLPrinter printer;
tinyxmlDoc.Accept( &printer );
const char* xmlcstr = printer.CStr();

Implements tinyxml2::XMLNode.

Definition at line 685 of file tinyxml2.cpp.

Referenced by Print().

686 {
687  TIXMLASSERT( visitor );
688  if ( visitor->VisitEnter( *this ) ) {
689  for ( const XMLNode* node=FirstChild(); node; node=node->NextSibling() ) {
690  if ( !node->Accept( visitor ) ) {
691  break;
692  }
693  }
694  }
695  return visitor->VisitExit( *this );
696 }
XMLNode(XMLDocument *)
Definition: tinyxml2.cpp:701
Definition: graphics.c:170
struct node node
const XMLNode * FirstChild() const
Get the first child node, or null if none exists.
Definition: tinyxml2.h:705
#define TIXMLASSERT(x)
Definition: tinyxml2.h:88

◆ Clear()

void tinyxml2::XMLDocument::Clear ( )

Clear the document, resetting it to the initial state.

Definition at line 1791 of file tinyxml2.cpp.

Referenced by LoadFile(), Parse(), and ~XMLDocument().

1792 {
1793  DeleteChildren();
1794 
1795 #ifdef DEBUG
1796  const bool hadError = Error();
1797 #endif
1799  _errorStr1 = 0;
1800  _errorStr2 = 0;
1801 
1802  delete [] _charBuffer;
1803  _charBuffer = 0;
1804 
1805 #if 0
1806  _textPool.Trace( "text" );
1807  _elementPool.Trace( "element" );
1808  _commentPool.Trace( "comment" );
1809  _attributePool.Trace( "attribute" );
1810 #endif
1811 
1812 #ifdef DEBUG
1813  if ( !hadError ) {
1814  TIXMLASSERT( _elementPool.CurrentAllocs() == _elementPool.Untracked() );
1815  TIXMLASSERT( _attributePool.CurrentAllocs() == _attributePool.Untracked() );
1816  TIXMLASSERT( _textPool.CurrentAllocs() == _textPool.Untracked() );
1817  TIXMLASSERT( _commentPool.CurrentAllocs() == _commentPool.Untracked() );
1818  }
1819 #endif
1820 }
const char * _errorStr1
Definition: tinyxml2.h:1718
MemPoolT< sizeof(XMLAttribute) > _attributePool
Definition: tinyxml2.h:1723
bool Error() const
Return true if there was an error parsing the document.
Definition: tinyxml2.h:1677
void DeleteChildren()
Definition: tinyxml2.cpp:738
MemPoolT< sizeof(XMLComment) > _commentPool
Definition: tinyxml2.h:1725
const char * _errorStr2
Definition: tinyxml2.h:1719
#define TIXMLASSERT(x)
Definition: tinyxml2.h:88
MemPoolT< sizeof(XMLText) > _textPool
Definition: tinyxml2.h:1724
MemPoolT< sizeof(XMLElement) > _elementPool
Definition: tinyxml2.h:1722

◆ DeleteNode()

void tinyxml2::XMLDocument::DeleteNode ( XMLNode node)

Delete a node associated with this document. It will be unlinked from the DOM.

Definition at line 1888 of file tinyxml2.cpp.

1888  {
1889  TIXMLASSERT( node );
1890  TIXMLASSERT(node->_document == this );
1891  if (node->_parent) {
1892  node->_parent->DeleteChild( node );
1893  }
1894  else {
1895  // Isn't in the tree.
1896  // Use the parent delete.
1897  // Also, we need to mark it tracked: we 'know'
1898  // it was never used.
1899  node->_memPool->SetTracked();
1900  // Call the static XMLNode version:
1902  }
1903 }
Definition: graphics.c:170
static void DeleteNode(XMLNode *node)
Definition: tinyxml2.cpp:1017
#define TIXMLASSERT(x)
Definition: tinyxml2.h:88

◆ Error()

bool tinyxml2::XMLDocument::Error ( ) const
inline

Return true if there was an error parsing the document.

Definition at line 1677 of file tinyxml2.h.

Referenced by Clear(), Parse(), tinyxml2::XMLNode::ParseDeep(), and PrintError().

1677  {
1678  return _errorID != XML_NO_ERROR;
1679  }

◆ ErrorID()

XMLError tinyxml2::XMLDocument::ErrorID ( ) const
inline

Return the errorID.

Definition at line 1681 of file tinyxml2.h.

1681  {
1682  return _errorID;
1683  }

◆ ErrorName()

const char * tinyxml2::XMLDocument::ErrorName ( ) const

Definition at line 2061 of file tinyxml2.cpp.

Referenced by PrintError().

2062 {
2064  const char* errorName = _errorNames[_errorID];
2065  TIXMLASSERT( errorName && errorName[0] );
2066  return errorName;
2067 }
static const char * _errorNames[XML_ERROR_COUNT]
Definition: tinyxml2.h:1727
#define TIXMLASSERT(x)
Definition: tinyxml2.h:88

◆ GetErrorStr1()

const char* tinyxml2::XMLDocument::GetErrorStr1 ( ) const
inline

Return a possibly helpful diagnostic location or string.

Definition at line 1687 of file tinyxml2.h.

1687  {
1688  return _errorStr1;
1689  }
const char * _errorStr1
Definition: tinyxml2.h:1718

◆ GetErrorStr2()

const char* tinyxml2::XMLDocument::GetErrorStr2 ( ) const
inline

Return a possibly helpful secondary diagnostic location or string.

Definition at line 1691 of file tinyxml2.h.

1691  {
1692  return _errorStr2;
1693  }
const char * _errorStr2
Definition: tinyxml2.h:1719

◆ HasBOM()

bool tinyxml2::XMLDocument::HasBOM ( ) const
inline

Returns true if this document has a leading Byte Order Mark of UTF8.

Definition at line 1595 of file tinyxml2.h.

Referenced by tinyxml2::XMLPrinter::VisitEnter().

1595  {
1596  return _writeBOM;
1597  }

◆ Identify()

char * tinyxml2::XMLDocument::Identify ( char p,
XMLNode **  node 
)

Definition at line 611 of file tinyxml2.cpp.

Referenced by tinyxml2::XMLNode::ParseDeep().

612 {
613  TIXMLASSERT( node );
614  TIXMLASSERT( p );
615  char* const start = p;
617  if( !*p ) {
618  *node = 0;
619  TIXMLASSERT( p );
620  return p;
621  }
622 
623  // These strings define the matching patterns:
624  static const char* xmlHeader = { "<?" };
625  static const char* commentHeader = { "<!--" };
626  static const char* cdataHeader = { "<![CDATA[" };
627  static const char* dtdHeader = { "<!" };
628  static const char* elementHeader = { "<" }; // and a header for everything else; check last.
629 
630  static const int xmlHeaderLen = 2;
631  static const int commentHeaderLen = 4;
632  static const int cdataHeaderLen = 9;
633  static const int dtdHeaderLen = 2;
634  static const int elementHeaderLen = 1;
635 
636  TIXMLASSERT( sizeof( XMLComment ) == sizeof( XMLUnknown ) ); // use same memory pool
637  TIXMLASSERT( sizeof( XMLComment ) == sizeof( XMLDeclaration ) ); // use same memory pool
638  XMLNode* returnNode = 0;
639  if ( XMLUtil::StringEqual( p, xmlHeader, xmlHeaderLen ) ) {
640  TIXMLASSERT( sizeof( XMLDeclaration ) == _commentPool.ItemSize() );
641  returnNode = new (_commentPool.Alloc()) XMLDeclaration( this );
642  returnNode->_memPool = &_commentPool;
643  p += xmlHeaderLen;
644  }
645  else if ( XMLUtil::StringEqual( p, commentHeader, commentHeaderLen ) ) {
646  TIXMLASSERT( sizeof( XMLComment ) == _commentPool.ItemSize() );
647  returnNode = new (_commentPool.Alloc()) XMLComment( this );
648  returnNode->_memPool = &_commentPool;
649  p += commentHeaderLen;
650  }
651  else if ( XMLUtil::StringEqual( p, cdataHeader, cdataHeaderLen ) ) {
652  TIXMLASSERT( sizeof( XMLText ) == _textPool.ItemSize() );
653  XMLText* text = new (_textPool.Alloc()) XMLText( this );
654  returnNode = text;
655  returnNode->_memPool = &_textPool;
656  p += cdataHeaderLen;
657  text->SetCData( true );
658  }
659  else if ( XMLUtil::StringEqual( p, dtdHeader, dtdHeaderLen ) ) {
660  TIXMLASSERT( sizeof( XMLUnknown ) == _commentPool.ItemSize() );
661  returnNode = new (_commentPool.Alloc()) XMLUnknown( this );
662  returnNode->_memPool = &_commentPool;
663  p += dtdHeaderLen;
664  }
665  else if ( XMLUtil::StringEqual( p, elementHeader, elementHeaderLen ) ) {
666  TIXMLASSERT( sizeof( XMLElement ) == _elementPool.ItemSize() );
667  returnNode = new (_elementPool.Alloc()) XMLElement( this );
668  returnNode->_memPool = &_elementPool;
669  p += elementHeaderLen;
670  }
671  else {
672  TIXMLASSERT( sizeof( XMLText ) == _textPool.ItemSize() );
673  returnNode = new (_textPool.Alloc()) XMLText( this );
674  returnNode->_memPool = &_textPool;
675  p = start; // Back it up, all the text counts.
676  }
677 
678  TIXMLASSERT( returnNode );
679  TIXMLASSERT( p );
680  *node = returnNode;
681  return p;
682 }
XMLNode(XMLDocument *)
Definition: tinyxml2.cpp:701
Definition: graphics.c:170
const WCHAR * text
Definition: package.c:1827
static const char * SkipWhiteSpace(const char *p)
Definition: tinyxml2.h:519
MemPoolT< sizeof(XMLComment) > _commentPool
Definition: tinyxml2.h:1725
static bool StringEqual(const char *p, const char *q, int nChar=INT_MAX)
Definition: tinyxml2.h:555
#define TIXMLASSERT(x)
Definition: tinyxml2.h:88
GLuint start
Definition: gl.h:1545
MemPoolT< sizeof(XMLText) > _textPool
Definition: tinyxml2.h:1724
MemPoolT< sizeof(XMLElement) > _elementPool
Definition: tinyxml2.h:1722
friend class XMLElement
Definition: tinyxml2.h:1522
GLfloat GLfloat p
Definition: glext.h:8902

◆ LoadFile() [1/2]

XMLError tinyxml2::XMLDocument::LoadFile ( const char filename)

Load an XML file from disk. Returns XML_NO_ERROR (0) on success, or an errorID.

Definition at line 1906 of file tinyxml2.cpp.

Referenced by Database::fromXml().

1907 {
1908  Clear();
1909  FILE* fp = callfopen( filename, "rb" );
1910  if ( !fp ) {
1912  return _errorID;
1913  }
1914  LoadFile( fp );
1915  fclose( fp );
1916  return _errorID;
1917 }
void SetError(XMLError error, const char *str1, const char *str2)
Definition: tinyxml2.cpp:2053
XMLError LoadFile(const char *filename)
Definition: tinyxml2.cpp:1906
const char * filename
Definition: ioapi.h:135
void Clear()
Clear the document, resetting it to the initial state.
Definition: tinyxml2.cpp:1791
_Check_return_opt_ _CRTIMP int __cdecl fclose(_Inout_ FILE *_File)
static FILE * callfopen(const char *filepath, const char *mode)
Definition: tinyxml2.cpp:1872

◆ LoadFile() [2/2]

XMLError tinyxml2::XMLDocument::LoadFile ( FILE fp)

Load an XML file from disk. You are responsible for providing and closing the FILE*.

NOTE: The file should be opened as binary ("rb") not text in order for TinyXML-2 to correctly do newline normalization.

Returns XML_NO_ERROR (0) on success, or an errorID.

Definition at line 1940 of file tinyxml2.cpp.

1941 {
1942  Clear();
1943 
1944  fseek( fp, 0, SEEK_SET );
1945  if ( fgetc( fp ) == EOF && ferror( fp ) != 0 ) {
1947  return _errorID;
1948  }
1949 
1950  fseek( fp, 0, SEEK_END );
1951  const long filelength = ftell( fp );
1952  fseek( fp, 0, SEEK_SET );
1953  if ( filelength == -1L ) {
1955  return _errorID;
1956  }
1957  TIXMLASSERT( filelength >= 0 );
1958 
1959  if ( !LongFitsIntoSizeTMinusOne<>::Fits( filelength ) ) {
1960  // Cannot handle files which won't fit in buffer together with null terminator
1962  return _errorID;
1963  }
1964 
1965  if ( filelength == 0 ) {
1967  return _errorID;
1968  }
1969 
1970  const size_t size = filelength;
1971  TIXMLASSERT( _charBuffer == 0 );
1972  _charBuffer = new char[size+1];
1973  size_t read = fread( _charBuffer, 1, size, fp );
1974  if ( read != size ) {
1976  return _errorID;
1977  }
1978 
1979  _charBuffer[size] = 0;
1980 
1981  Parse();
1982  return _errorID;
1983 }
void SetError(XMLError error, const char *str1, const char *str2)
Definition: tinyxml2.cpp:2053
_Check_return_ _CRTIMP int __cdecl ferror(_In_ FILE *_File)
_Check_return_ _CRTIMP long __cdecl filelength(_In_ int _FileHandle)
_Check_return_opt_ _CRTIMP size_t __cdecl fread(_Out_writes_bytes_(_ElementSize *_Count) void *_DstBuf, _In_ size_t _ElementSize, _In_ size_t _Count, _Inout_ FILE *_File)
void Clear()
Clear the document, resetting it to the initial state.
Definition: tinyxml2.cpp:1791
_Check_return_opt_ _CRTIMP int __cdecl fseek(_Inout_ FILE *_File, _In_ long _Offset, _In_ int _Origin)
#define SEEK_SET
Definition: jmemansi.c:26
GLsizeiptr size
Definition: glext.h:5919
static bool Fits(unsigned long value)
Definition: tinyxml2.cpp:1928
static const WCHAR L[]
Definition: oid.c:1087
#define TIXMLASSERT(x)
Definition: tinyxml2.h:88
#define EOF
Definition: stdio.h:24
_Check_return_ _CRTIMP long __cdecl ftell(_Inout_ FILE *_File)
#define SEEK_END
Definition: cabinet.c:27
_CRTIMP int __cdecl read(_In_ int _FileHandle, _Out_writes_bytes_(_MaxCharCount) void *_DstBuf, _In_ unsigned int _MaxCharCount)
_Check_return_opt_ _CRTIMP int __cdecl fgetc(_Inout_ FILE *_File)

◆ NewComment()

XMLComment * tinyxml2::XMLDocument::NewComment ( const char comment)

Create a new Comment associated with this Document. The memory for the Comment is managed by the Document.

Definition at line 1833 of file tinyxml2.cpp.

Referenced by tinyxml2::XMLComment::ShallowClone().

1834 {
1835  TIXMLASSERT( sizeof( XMLComment ) == _commentPool.ItemSize() );
1836  XMLComment* comment = new (_commentPool.Alloc()) XMLComment( this );
1837  comment->_memPool = &_commentPool;
1838  comment->SetValue( str );
1839  return comment;
1840 }
const WCHAR * str
MemPoolT< sizeof(XMLComment) > _commentPool
Definition: tinyxml2.h:1725
Definition: id3.c:18
#define TIXMLASSERT(x)
Definition: tinyxml2.h:88

◆ NewDeclaration()

XMLDeclaration * tinyxml2::XMLDocument::NewDeclaration ( const char text = 0)

Create a new Declaration associated with this Document. The memory for the object is managed by the Document.

If the 'text' param is null, the standard declaration is used.:

    <?xml version="1.0" encoding="UTF-8"?>

Definition at line 1853 of file tinyxml2.cpp.

Referenced by tinyxml2::XMLDeclaration::ShallowClone().

1854 {
1855  TIXMLASSERT( sizeof( XMLDeclaration ) == _commentPool.ItemSize() );
1856  XMLDeclaration* dec = new (_commentPool.Alloc()) XMLDeclaration( this );
1857  dec->_memPool = &_commentPool;
1858  dec->SetValue( str ? str : "xml version=\"1.0\" encoding=\"UTF-8\"" );
1859  return dec;
1860 }
ios_base &_STLP_CALL dec(ios_base &__s)
Definition: _ios_base.h:321
const WCHAR * str
MemPoolT< sizeof(XMLComment) > _commentPool
Definition: tinyxml2.h:1725
#define TIXMLASSERT(x)
Definition: tinyxml2.h:88

◆ NewElement()

XMLElement * tinyxml2::XMLDocument::NewElement ( const char name)

Create a new Element associated with this Document. The memory for the Element is managed by the Document.

Definition at line 1823 of file tinyxml2.cpp.

Referenced by tinyxml2::XMLElement::ShallowClone().

1824 {
1825  TIXMLASSERT( sizeof( XMLElement ) == _elementPool.ItemSize() );
1826  XMLElement* ele = new (_elementPool.Alloc()) XMLElement( this );
1827  ele->_memPool = &_elementPool;
1828  ele->SetName( name );
1829  return ele;
1830 }
#define TIXMLASSERT(x)
Definition: tinyxml2.h:88
Definition: name.c:36
MemPoolT< sizeof(XMLElement) > _elementPool
Definition: tinyxml2.h:1722
friend class XMLElement
Definition: tinyxml2.h:1522

◆ NewText()

XMLText * tinyxml2::XMLDocument::NewText ( const char text)

Create a new Text associated with this Document. The memory for the Text is managed by the Document.

Definition at line 1843 of file tinyxml2.cpp.

Referenced by tinyxml2::XMLElement::SetText(), and tinyxml2::XMLText::ShallowClone().

1844 {
1845  TIXMLASSERT( sizeof( XMLText ) == _textPool.ItemSize() );
1846  XMLText* text = new (_textPool.Alloc()) XMLText( this );
1847  text->_memPool = &_textPool;
1848  text->SetValue( str );
1849  return text;
1850 }
const WCHAR * text
Definition: package.c:1827
const WCHAR * str
#define TIXMLASSERT(x)
Definition: tinyxml2.h:88
MemPoolT< sizeof(XMLText) > _textPool
Definition: tinyxml2.h:1724

◆ NewUnknown()

XMLUnknown * tinyxml2::XMLDocument::NewUnknown ( const char text)

Create a new Unknown associated with this Document. The memory for the object is managed by the Document.

Definition at line 1863 of file tinyxml2.cpp.

Referenced by tinyxml2::XMLUnknown::ShallowClone().

1864 {
1865  TIXMLASSERT( sizeof( XMLUnknown ) == _commentPool.ItemSize() );
1866  XMLUnknown* unk = new (_commentPool.Alloc()) XMLUnknown( this );
1867  unk->_memPool = &_commentPool;
1868  unk->SetValue( str );
1869  return unk;
1870 }
const WCHAR * str
MemPoolT< sizeof(XMLComment) > _commentPool
Definition: tinyxml2.h:1725
#define TIXMLASSERT(x)
Definition: tinyxml2.h:88

◆ operator=()

◆ Parse() [1/2]

XMLError tinyxml2::XMLDocument::Parse ( const char xml,
size_t  nBytes = (size_t)(-1) 
)

Parse an XML file from a character string. Returns XML_NO_ERROR (0) on success, or an errorID.

You may optionally pass in the 'nBytes', which is the number of bytes which will be parsed. If not specified, TinyXML-2 will assume 'xml' points to a null terminated string.

Definition at line 2010 of file tinyxml2.cpp.

2011 {
2012  Clear();
2013 
2014  if ( len == 0 || !p || !*p ) {
2016  return _errorID;
2017  }
2018  if ( len == (size_t)(-1) ) {
2019  len = strlen( p );
2020  }
2021  TIXMLASSERT( _charBuffer == 0 );
2022  _charBuffer = new char[ len+1 ];
2023  memcpy( _charBuffer, p, len );
2024  _charBuffer[len] = 0;
2025 
2026  Parse();
2027  if ( Error() ) {
2028  // clean up now essentially dangling memory.
2029  // and the parse fail can put objects in the
2030  // pools that are dead and inaccessible.
2031  DeleteChildren();
2032  _elementPool.Clear();
2033  _attributePool.Clear();
2034  _textPool.Clear();
2035  _commentPool.Clear();
2036  }
2037  return _errorID;
2038 }
void SetError(XMLError error, const char *str1, const char *str2)
Definition: tinyxml2.cpp:2053
ACPI_SIZE strlen(const char *String)
Definition: utclib.c:269
MemPoolT< sizeof(XMLAttribute) > _attributePool
Definition: tinyxml2.h:1723
bool Error() const
Return true if there was an error parsing the document.
Definition: tinyxml2.h:1677
void Clear()
Clear the document, resetting it to the initial state.
Definition: tinyxml2.cpp:1791
void DeleteChildren()
Definition: tinyxml2.cpp:738
MemPoolT< sizeof(XMLComment) > _commentPool
Definition: tinyxml2.h:1725
#define memcpy(s1, s2, n)
Definition: mkisofs.h:878
GLenum GLsizei len
Definition: glext.h:6722
#define TIXMLASSERT(x)
Definition: tinyxml2.h:88
MemPoolT< sizeof(XMLText) > _textPool
Definition: tinyxml2.h:1724
MemPoolT< sizeof(XMLElement) > _elementPool
Definition: tinyxml2.h:1722
GLfloat GLfloat p
Definition: glext.h:8902

◆ Parse() [2/2]

void tinyxml2::XMLDocument::Parse ( )
private

Definition at line 2091 of file tinyxml2.cpp.

Referenced by LoadFile(), and Parse().

2092 {
2093  TIXMLASSERT( NoChildren() ); // Clear() must have been called previously
2095  char* p = _charBuffer;
2096  p = XMLUtil::SkipWhiteSpace( p );
2097  p = const_cast<char*>( XMLUtil::ReadBOM( p, &_writeBOM ) );
2098  if ( !*p ) {
2100  return;
2101  }
2102  ParseDeep(p, 0 );
2103 }
void SetError(XMLError error, const char *str1, const char *str2)
Definition: tinyxml2.cpp:2053
static const char * SkipWhiteSpace(const char *p)
Definition: tinyxml2.h:519
static const char * ReadBOM(const char *p, bool *hasBOM)
Definition: tinyxml2.cpp:363
virtual char * ParseDeep(char *, StrPair *)
Definition: tinyxml2.cpp:930
#define TIXMLASSERT(x)
Definition: tinyxml2.h:88
bool NoChildren() const
Returns true if this node has no children.
Definition: tinyxml2.h:700
GLfloat GLfloat p
Definition: glext.h:8902

◆ Print()

void tinyxml2::XMLDocument::Print ( XMLPrinter streamer = 0) const

Print the Document. If the Printer is not provided, it will print to stdout. If you provide Printer, this can print to a file:

XMLPrinter printer( fp );
doc.Print( &printer );

Or you can use a printer to print to memory:

XMLPrinter printer;
doc.Print( &printer );
// printer.CStr() has a const char* to the XML

Definition at line 2041 of file tinyxml2.cpp.

Referenced by SaveFile().

2042 {
2043  if ( streamer ) {
2044  Accept( streamer );
2045  }
2046  else {
2047  XMLPrinter stdoutStreamer( stdout );
2048  Accept( &stdoutStreamer );
2049  }
2050 }
FILE * stdout
virtual bool Accept(XMLVisitor *visitor) const
Definition: tinyxml2.cpp:685

◆ PrintError()

void tinyxml2::XMLDocument::PrintError ( ) const

If there is an error, print it to stdout.

Definition at line 2069 of file tinyxml2.cpp.

2070 {
2071  if ( Error() ) {
2072  static const int LEN = 20;
2073  char buf1[LEN] = { 0 };
2074  char buf2[LEN] = { 0 };
2075 
2076  if ( _errorStr1 ) {
2077  TIXML_SNPRINTF( buf1, LEN, "%s", _errorStr1 );
2078  }
2079  if ( _errorStr2 ) {
2080  TIXML_SNPRINTF( buf2, LEN, "%s", _errorStr2 );
2081  }
2082 
2083  // Should check INT_MIN <= _errorID && _errorId <= INT_MAX, but that
2084  // causes a clang "always true" -Wtautological-constant-out-of-range-compare warning
2085  TIXMLASSERT( 0 <= _errorID && XML_ERROR_COUNT - 1 <= INT_MAX );
2086  printf( "XMLDocument error id=%d '%s' str1=%s str2=%s\n",
2087  static_cast<int>( _errorID ), ErrorName(), buf1, buf2 );
2088  }
2089 }
const char * _errorStr1
Definition: tinyxml2.h:1718
#define INT_MAX
Definition: limits.h:40
bool Error() const
Return true if there was an error parsing the document.
Definition: tinyxml2.h:1677
#define TIXML_SNPRINTF
Definition: tinyxml2.cpp:92
const char * ErrorName() const
Definition: tinyxml2.cpp:2061
#define LEN
Definition: rtl.c:127
const char * _errorStr2
Definition: tinyxml2.h:1719
#define TIXMLASSERT(x)
Definition: tinyxml2.h:88
#define printf
Definition: config.h:203

◆ ProcessEntities()

bool tinyxml2::XMLDocument::ProcessEntities ( ) const
inline

◆ RootElement() [1/2]

XMLElement* tinyxml2::XMLDocument::RootElement ( )
inline

Return the root element of DOM. Equivalent to FirstChildElement(). To get the first node, use FirstChild().

Definition at line 1607 of file tinyxml2.h.

1607  {
1608  return FirstChildElement();
1609  }
const XMLElement * FirstChildElement(const char *name=0) const
Definition: tinyxml2.cpp:876

◆ RootElement() [2/2]

const XMLElement* tinyxml2::XMLDocument::RootElement ( ) const
inline

Definition at line 1610 of file tinyxml2.h.

1610  {
1611  return FirstChildElement();
1612  }
const XMLElement * FirstChildElement(const char *name=0) const
Definition: tinyxml2.cpp:876

◆ SaveFile() [1/2]

XMLError tinyxml2::XMLDocument::SaveFile ( const char filename,
bool  compact = false 
)

Save the XML file to disk. Returns XML_NO_ERROR (0) on success, or an errorID.

Definition at line 1986 of file tinyxml2.cpp.

1987 {
1988  FILE* fp = callfopen( filename, "w" );
1989  if ( !fp ) {
1991  return _errorID;
1992  }
1993  SaveFile(fp, compact);
1994  fclose( fp );
1995  return _errorID;
1996 }
void SetError(XMLError error, const char *str1, const char *str2)
Definition: tinyxml2.cpp:2053
const char * filename
Definition: ioapi.h:135
XMLError SaveFile(const char *filename, bool compact=false)
Definition: tinyxml2.cpp:1986
_Check_return_opt_ _CRTIMP int __cdecl fclose(_Inout_ FILE *_File)
static FILE * callfopen(const char *filepath, const char *mode)
Definition: tinyxml2.cpp:1872

◆ SaveFile() [2/2]

XMLError tinyxml2::XMLDocument::SaveFile ( FILE fp,
bool  compact = false 
)

Save the XML file to disk. You are responsible for providing and closing the FILE*.

Returns XML_NO_ERROR (0) on success, or an errorID.

Definition at line 1999 of file tinyxml2.cpp.

2000 {
2001  // Clear any error from the last save, otherwise it will get reported
2002  // for *this* call.
2003  SetError( XML_NO_ERROR, 0, 0 );
2004  XMLPrinter stream( fp, compact );
2005  Print( &stream );
2006  return _errorID;
2007 }
void SetError(XMLError error, const char *str1, const char *str2)
Definition: tinyxml2.cpp:2053
void Print(XMLPrinter *streamer=0) const
Definition: tinyxml2.cpp:2041
Definition: parse.h:22
GLuint GLuint stream
Definition: glext.h:7522

◆ SetBOM()

void tinyxml2::XMLDocument::SetBOM ( bool  useBOM)
inline

Sets whether to write the BOM when writing the file.

Definition at line 1600 of file tinyxml2.h.

1600  {
1601  _writeBOM = useBOM;
1602  }

◆ SetError()

void tinyxml2::XMLDocument::SetError ( XMLError  error,
const char str1,
const char str2 
)

◆ ShallowClone()

virtual XMLNode* tinyxml2::XMLDocument::ShallowClone ( XMLDocument document) const
inlinevirtual

Make a copy of this node, but not its children. You may pass in a Document pointer that will be the owner of the new Node. If the 'document' is null, then the node returned will be allocated from the current Document. (this->GetDocument())

Note: if called on a XMLDocument, this will return null.

Implements tinyxml2::XMLNode.

Definition at line 1703 of file tinyxml2.h.

1703  {
1704  return 0;
1705  }

◆ ShallowEqual()

virtual bool tinyxml2::XMLDocument::ShallowEqual ( const XMLNode compare) const
inlinevirtual

Test if 2 nodes are the same, but don't test children. The 2 nodes do not need to be in the same Document.

Note: if called on a XMLDocument, this will return false.

Implements tinyxml2::XMLNode.

Definition at line 1706 of file tinyxml2.h.

1706  {
1707  return false;
1708  }

◆ ToDocument() [1/2]

virtual XMLDocument* tinyxml2::XMLDocument::ToDocument ( )
inlinevirtual

Safely cast to a Document, or null.

Reimplemented from tinyxml2::XMLNode.

Definition at line 1528 of file tinyxml2.h.

1528  {
1529  TIXMLASSERT( this == _document );
1530  return this;
1531  }
#define TIXMLASSERT(x)
Definition: tinyxml2.h:88
XMLDocument * _document
Definition: tinyxml2.h:861

◆ ToDocument() [2/2]

virtual const XMLDocument* tinyxml2::XMLDocument::ToDocument ( ) const
inlinevirtual

Reimplemented from tinyxml2::XMLNode.

Definition at line 1532 of file tinyxml2.h.

1532  {
1533  TIXMLASSERT( this == _document );
1534  return this;
1535  }
#define TIXMLASSERT(x)
Definition: tinyxml2.h:88
XMLDocument * _document
Definition: tinyxml2.h:861

◆ WhitespaceMode()

Whitespace tinyxml2::XMLDocument::WhitespaceMode ( ) const
inline

Definition at line 1588 of file tinyxml2.h.

Referenced by tinyxml2::XMLText::ParseDeep().

1588  {
1589  return _whitespace;
1590  }
Whitespace _whitespace
Definition: tinyxml2.h:1717

Friends And Related Function Documentation

◆ XMLElement

friend class XMLElement
friend

Definition at line 1522 of file tinyxml2.h.

Referenced by NewElement().

Member Data Documentation

◆ _attributePool

MemPoolT< sizeof(XMLAttribute) > tinyxml2::XMLDocument::_attributePool
private

◆ _charBuffer

char* tinyxml2::XMLDocument::_charBuffer
private

Definition at line 1720 of file tinyxml2.h.

Referenced by Clear(), LoadFile(), and Parse().

◆ _commentPool

MemPoolT< sizeof(XMLComment) > tinyxml2::XMLDocument::_commentPool
private

Definition at line 1725 of file tinyxml2.h.

Referenced by Clear(), NewComment(), NewDeclaration(), NewUnknown(), and Parse().

◆ _elementPool

MemPoolT< sizeof(XMLElement) > tinyxml2::XMLDocument::_elementPool
private

Definition at line 1722 of file tinyxml2.h.

Referenced by Clear(), NewElement(), and Parse().

◆ _errorID

XMLError tinyxml2::XMLDocument::_errorID
private

Definition at line 1716 of file tinyxml2.h.

Referenced by Clear(), ErrorName(), LoadFile(), Parse(), PrintError(), SaveFile(), and SetError().

◆ _errorNames

const char * tinyxml2::XMLDocument::_errorNames
staticprivate
Initial value:
= {
"XML_SUCCESS",
"XML_NO_ATTRIBUTE",
"XML_WRONG_ATTRIBUTE_TYPE",
"XML_ERROR_FILE_NOT_FOUND",
"XML_ERROR_FILE_COULD_NOT_BE_OPENED",
"XML_ERROR_FILE_READ_ERROR",
"XML_ERROR_ELEMENT_MISMATCH",
"XML_ERROR_PARSING_ELEMENT",
"XML_ERROR_PARSING_ATTRIBUTE",
"XML_ERROR_IDENTIFYING_TAG",
"XML_ERROR_PARSING_TEXT",
"XML_ERROR_PARSING_CDATA",
"XML_ERROR_PARSING_COMMENT",
"XML_ERROR_PARSING_DECLARATION",
"XML_ERROR_PARSING_UNKNOWN",
"XML_ERROR_EMPTY_DOCUMENT",
"XML_ERROR_MISMATCHED_ELEMENT",
"XML_ERROR_PARSING",
"XML_CAN_NOT_CONVERT_TEXT",
"XML_NO_TEXT_NODE"
}

Definition at line 1727 of file tinyxml2.h.

Referenced by tinyxml2::XMLElement::Accept(), and ErrorName().

◆ _errorStr1

const char* tinyxml2::XMLDocument::_errorStr1
private

Definition at line 1718 of file tinyxml2.h.

Referenced by Clear(), PrintError(), and SetError().

◆ _errorStr2

const char* tinyxml2::XMLDocument::_errorStr2
private

Definition at line 1719 of file tinyxml2.h.

Referenced by Clear(), PrintError(), and SetError().

◆ _processEntities

bool tinyxml2::XMLDocument::_processEntities
private

Definition at line 1715 of file tinyxml2.h.

◆ _textPool

MemPoolT< sizeof(XMLText) > tinyxml2::XMLDocument::_textPool
private

Definition at line 1724 of file tinyxml2.h.

Referenced by Clear(), NewText(), and Parse().

◆ _whitespace

Whitespace tinyxml2::XMLDocument::_whitespace
private

Definition at line 1717 of file tinyxml2.h.

◆ _writeBOM

bool tinyxml2::XMLDocument::_writeBOM
private

Definition at line 1714 of file tinyxml2.h.

Referenced by Parse().


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