• Main Page
  • Related Pages
  • Modules
  • Namespaces
  • Classes
  • Files
  • File List
  • File Members

spl/xml/XmlDocument.h

00001 /*
00002  *  Much of this code is extracted from the tinyxml project, attributed below.
00003  */
00004 /*
00005 www.sourceforge.net/projects/tinyxml
00006 Original code (2.0 and earlier )copyright (c) 2000-2006 Lee Thomason (www.grinninglizard.com)
00007 
00008 This software is provided 'as-is', without any express or implied
00009 warranty. In no event will the authors be held liable for any
00010 damages arising from the use of this software.
00011 
00012 Permission is granted to anyone to use this software for any
00013 purpose, including commercial applications, and to alter it and
00014 redistribute it freely, subject to the following restrictions:
00015 
00016 1. The origin of this software must not be misrepresented; you must
00017 not claim that you wrote the original software. If you use this
00018 software in a product, an acknowledgment in the product documentation
00019 would be appreciated but is not required.
00020 
00021 2. Altered source versions must be plainly marked as such, and
00022 must not be misrepresented as being the original software.
00023 
00024 3. This notice may not be removed or altered from any source
00025 distribution.
00026 */
00027 #ifndef _xmldocument_h
00028 #define _xmldocument_h
00029 
00030 #include <spl/Debug.h>
00031 #include <spl/collection/Array.h>
00032 #include <spl/io/FileStream.h>
00033 #include <spl/RefCountPtr.h>
00034 #include <spl/io/StringStream.h>
00035 #include <spl/io/TextStream.h>
00036 #include <spl/xml/XmlNode.h>
00037 
00047 class XmlDocument : public XmlNode
00048 {
00049 private:
00050         XmlDocument( const XmlDocument& copy );
00051 
00052 protected:
00053         friend void _TestTinyXml();
00054         
00055         // [internal use]
00056         virtual XmlNodePtr Clone() const;
00057 
00058         static bool m_condenseWhiteSpace;
00059 
00060         static int m_tabsize;
00061         
00062         bool m_useMicrosoftBOM;         
00063 
00068         virtual const char *_Parse( const char *p, XmlParsingData* data = NULL, XmlEncoding encoding = TIXML_DEFAULT_ENCODING );
00069                 
00071         XmlDocument();
00072         void CopyTo( XmlDocument& target ) const;
00073         virtual void WriteTo(TextWriter& writer) const;
00074 
00075 public:
00076         
00077         virtual ~XmlDocument();
00078         
00079         void operator =( const XmlDocument& copy );
00080 
00081         virtual String Name() const;
00082 
00087         void Write( TextWriter& xmlout ) const;
00088 
00089         inline void Write( const String& filename ) const
00090         {
00091                 TextWriter tw(FileStreamPtr(new FileStream(filename, File::FILEMODE_Truncate, File::FILEACC_Write)));
00092                 Write(tw);
00093         }
00094 
00095         static XmlDocumentPtr Parse( TextReader& xmlin, XmlParsingData* data = NULL, XmlEncoding encoding = TIXML_DEFAULT_ENCODING );
00096 
00097         inline static XmlDocumentPtr Parse( const String& filename )
00098         {
00099                 TextReader tw(File::OpenRead(filename));
00100                 return Parse(tw);
00101         }
00102         
00103         inline static XmlDocumentPtr ParseXml( const String& xml, XmlParsingData* data = NULL, XmlEncoding encoding = TIXML_DEFAULT_ENCODING )
00104         {
00105                 TextReader tw(StringStreamPtr(new StringStream(xml)));
00106                 return Parse(tw, data, encoding);
00107         }
00108 
00113         XmlElementPtr RootElement();
00114 
00139         inline static void SetTabSize( int _tabsize ) { m_tabsize = _tabsize; }
00140         inline static int TabSize()     { return m_tabsize; }
00141         
00142         inline static void SetCondenseWhiteSpace(bool condense) { m_condenseWhiteSpace = condense; }
00143         inline static bool CondenseWhiteSpace() { return m_condenseWhiteSpace; }
00144         static inline bool IsWhiteSpaceCondensed() { return m_condenseWhiteSpace; }
00145 
00146         virtual XmlDocumentPtr    ToDocument()    const; 
00147 
00148         virtual StringPtr InnerXml() const;
00149         virtual StringPtr ToString() const;
00150                                                 
00151 #ifdef DEBUG
00152         virtual void ValidateMem() const;
00153         virtual void CheckMem() const;
00154 #endif
00155 };
00156 
00157 REGISTER_TYPEOF( 536, XmlDocument );
00158 
00161 #endif