ReactOS 0.4.15-dev-5858-g16decc6
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
 
 ~XMLDocument ()
 
virtual XMLDocumentToDocument ()
 Safely cast to a Document, or null.
 
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.
 
XMLError ErrorID () const
 Return the errorID.
 
const charErrorName () const
 
const charGetErrorStr1 () const
 Return a possibly helpful diagnostic location or string.
 
const charGetErrorStr2 () const
 Return a possibly helpful secondary diagnostic location or string.
 
void PrintError () const
 If there is an error, print it to stdout.
 
void Clear ()
 Clear the document, resetting it to the initial state.
 
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.
 
XMLDocumentGetDocument ()
 Get the XMLDocument that owns this XMLNode.
 
virtual XMLElementToElement ()
 Safely cast to an Element, or null.
 
virtual XMLTextToText ()
 Safely cast to Text, or null.
 
virtual XMLCommentToComment ()
 Safely cast to a Comment, or null.
 
virtual XMLDocumentToDocument ()
 Safely cast to a Document, or null.
 
virtual XMLDeclarationToDeclaration ()
 Safely cast to a Declaration, or null.
 
virtual XMLUnknownToUnknown ()
 Safely cast to an Unknown, or null.
 
virtual const XMLElementToElement () const
 
virtual const XMLTextToText () const
 
virtual const XMLCommentToComment () const
 
virtual const XMLDocumentToDocument () 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.
 
XMLNodeParent ()
 
bool NoChildren () const
 Returns true if this node has no children.
 
const XMLNodeFirstChild () const
 Get the first child node, or null if none exists.
 
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.
 
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.
 
XMLNodePreviousSibling ()
 
const XMLElementPreviousSiblingElement (const char *name=0) const
 Get the previous (left) sibling element of this node, with an optionally supplied name.
 
XMLElementPreviousSiblingElement (const char *name=0)
 
const XMLNodeNextSibling () const
 Get the next (right) sibling node of this node.
 
XMLNodeNextSibling ()
 
const XMLElementNextSiblingElement (const char *name=0) const
 Get the next (right) sibling element of this node, with an optionally supplied name.
 
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)
 
virtual XMLNodeShallowClone (XMLDocument *document) const =0
 
virtual bool ShallowEqual (const XMLNode *compare) const =0
 
virtual bool Accept (XMLVisitor *visitor) const =0
 

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}
const char * _errorStr1
Definition: tinyxml2.h:1718
Whitespace _whitespace
Definition: tinyxml2.h:1717
const char * _errorStr2
Definition: tinyxml2.h:1719
XMLNode(XMLDocument *)
Definition: tinyxml2.cpp:701
XMLDocument * _document
Definition: tinyxml2.h:861
static const char whitespace[]
Definition: main.c:63
@ XML_NO_ERROR
Definition: tinyxml2.h:488

◆ ~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.

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}
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
Definition: dlist.c:348

Referenced by Print().

◆ Clear()

void tinyxml2::XMLDocument::Clear ( )

Clear the document, resetting it to the initial state.

Definition at line 1791 of file tinyxml2.cpp.

1792{
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}
MemPoolT< sizeof(XMLAttribute) > _attributePool
Definition: tinyxml2.h:1723
MemPoolT< sizeof(XMLElement) > _elementPool
Definition: tinyxml2.h:1722
bool Error() const
Return true if there was an error parsing the document.
Definition: tinyxml2.h:1677
MemPoolT< sizeof(XMLComment) > _commentPool
Definition: tinyxml2.h:1725
MemPoolT< sizeof(XMLText) > _textPool
Definition: tinyxml2.h:1724
void DeleteChildren()
Definition: tinyxml2.cpp:738

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

◆ 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}
static void DeleteNode(XMLNode *node)
Definition: tinyxml2.cpp:1017

◆ 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.

1677 {
1678 return _errorID != XML_NO_ERROR;
1679 }

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

◆ 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.

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
@ XML_ERROR_COUNT
Definition: tinyxml2.h:509

Referenced by PrintError().

◆ 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 }

◆ 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 }

◆ 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.

1595 {
1596 return _writeBOM;
1597 }

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

◆ Identify()

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

Definition at line 611 of file tinyxml2.cpp.

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}
friend class XMLElement
Definition: tinyxml2.h:1522
static const char * SkipWhiteSpace(const char *p)
Definition: tinyxml2.h:519
static bool StringEqual(const char *p, const char *q, int nChar=INT_MAX)
Definition: tinyxml2.h:555
const WCHAR * text
Definition: package.c:1799
GLuint start
Definition: gl.h:1545
GLfloat GLfloat p
Definition: glext.h:8902

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

◆ 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.

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}
XMLError LoadFile(const char *filename)
Definition: tinyxml2.cpp:1906
void SetError(XMLError error, const char *str1, const char *str2)
Definition: tinyxml2.cpp:2053
_Check_return_opt_ _CRTIMP int __cdecl fclose(_Inout_ FILE *_File)
const char * filename
Definition: ioapi.h:137
@ XML_ERROR_FILE_NOT_FOUND
Definition: tinyxml2.h:491
static FILE * callfopen(const char *filepath, const char *mode)
Definition: tinyxml2.cpp:1872

Referenced by Database::fromXml(), and LoadFile().

◆ 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
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}
#define read
Definition: acwin.h:96
#define SEEK_END
Definition: cabinet.c:27
GLsizeiptr size
Definition: glext.h:5919
_Check_return_opt_ _CRTIMP int __cdecl fgetc(_Inout_ FILE *_File)
_Check_return_ _CRTIMP int __cdecl ferror(_In_ FILE *_File)
#define EOF
Definition: stdio.h:24
_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)
_Check_return_opt_ _CRTIMP int __cdecl fseek(_Inout_ FILE *_File, _In_ long _Offset, _In_ int _Origin)
_Check_return_ _CRTIMP long __cdecl ftell(_Inout_ FILE *_File)
#define SEEK_SET
Definition: jmemansi.c:26
@ XML_ERROR_EMPTY_DOCUMENT
Definition: tinyxml2.h:503
@ XML_ERROR_FILE_READ_ERROR
Definition: tinyxml2.h:493
_Check_return_ _CRTIMP long __cdecl filelength(_In_ int _FileHandle)
static bool Fits(unsigned long value)
Definition: tinyxml2.cpp:1928

◆ 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.

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}
#define comment(fmt, arg1)
Definition: rebar.c:820
const WCHAR * str

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

◆ 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.

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

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

◆ 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.

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}
Definition: name.c:39

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

◆ 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.

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}

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

◆ 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.

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}

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

◆ operator=()

void tinyxml2::XMLDocument::operator= ( const XMLDocument )
private

◆ Parse() [1/2]

void tinyxml2::XMLDocument::Parse ( )
private

Definition at line 2091 of file tinyxml2.cpp.

2092{
2093 TIXMLASSERT( NoChildren() ); // Clear() must have been called previously
2095 char* p = _charBuffer;
2097 p = const_cast<char*>( XMLUtil::ReadBOM( p, &_writeBOM ) );
2098 if ( !*p ) {
2100 return;
2101 }
2102 ParseDeep(p, 0 );
2103}
virtual char * ParseDeep(char *, StrPair *)
Definition: tinyxml2.cpp:930
bool NoChildren() const
Returns true if this node has no children.
Definition: tinyxml2.h:700
static const char * ReadBOM(const char *p, bool *hasBOM)
Definition: tinyxml2.cpp:363

Referenced by LoadFile(), and Parse().

◆ Parse() [2/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.
2032 _elementPool.Clear();
2033 _attributePool.Clear();
2034 _textPool.Clear();
2035 _commentPool.Clear();
2036 }
2037 return _errorID;
2038}
ACPI_SIZE strlen(const char *String)
Definition: utclib.c:269
GLenum GLsizei len
Definition: glext.h:6722
#define memcpy(s1, s2, n)
Definition: mkisofs.h:878

◆ 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.

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

Referenced by SaveFile().

◆ 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 * ErrorName() const
Definition: tinyxml2.cpp:2061
#define printf
Definition: freeldr.h:94
#define INT_MAX
Definition: limits.h:40
#define LEN
Definition: rtl.c:127
#define TIXML_SNPRINTF
Definition: tinyxml2.cpp:92

◆ 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 }

◆ 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}
XMLError SaveFile(const char *filename, bool compact=false)
Definition: tinyxml2.cpp:1986
@ XML_ERROR_FILE_COULD_NOT_BE_OPENED
Definition: tinyxml2.h:492

Referenced by SaveFile().

◆ 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 Print(XMLPrinter *streamer=0) const
Definition: tinyxml2.cpp:2041
Definition: parse.h:23

◆ 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 }

◆ 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 }

◆ WhitespaceMode()

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

Definition at line 1588 of file tinyxml2.h.

1588 {
1589 return _whitespace;
1590 }

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

Friends And Related Function Documentation

◆ XMLElement

friend class XMLElement
friend

Definition at line 1522 of file tinyxml2.h.

Referenced by Identify(), and 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(), Identify(), NewComment(), NewDeclaration(), NewUnknown(), and Parse().

◆ _elementPool

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

Definition at line 1722 of file tinyxml2.h.

Referenced by Clear(), Identify(), 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 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(), Identify(), 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: