00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
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
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