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 CEYLAN_XML_PARSER_H_
00028 #define CEYLAN_XML_PARSER_H_
00029
00030
00031 #include "CeylanTextDisplayable.h"
00032 #include "CeylanTree.h"
00033 #include "CeylanXML.h"
00034 #include "CeylanInputStream.h"
00035
00036 #include <string>
00037 #include <stack>
00038
00039
00040
00041
00042 namespace Ceylan
00043 {
00044
00045
00046
00047 namespace System
00048 {
00049
00050
00051 class InputStream ;
00052
00053 }
00054
00055
00056
00057
00058 namespace XML
00059 {
00060
00061
00062
00063
00064 class XMLElement ;
00065
00066
00067
00072 class CEYLAN_DLL XMLParserException : public Ceylan::XML::XMLException
00073 {
00074
00075 public:
00076
00077 explicit XMLParserException( const std::string & reason ) ;
00078
00079 virtual ~XMLParserException() throw() ;
00080
00081 } ;
00082
00083
00084
00085
00086
00087 template <typename XMLElement> class Tree ;
00088
00089
00090
00091
00104 class CEYLAN_DLL XMLParser : public Ceylan::TextDisplayable
00105 {
00106
00107
00108
00109 public:
00110
00111
00112 typedef Ceylan::Tree<Ceylan::XML::XMLElement> XMLTree ;
00113
00114
00115
00133 explicit XMLParser( const std::string & filename ) ;
00134
00135
00136
00141 virtual ~XMLParser() throw() ;
00142
00143
00144
00145
00146
00147
00148
00149
00150
00157 virtual bool hasXMLTree() const ;
00158
00159
00160
00172 virtual XMLTree & getXMLTree() const ;
00173
00174
00175
00186 virtual void setXMLTree( XMLTree & newTree ) ;
00187
00188
00189
00190
00191
00192
00193
00194
00195
00209 virtual void saveToFile( const std::string & filename = "" )
00210 const ;
00211
00212
00213
00224 virtual void loadFromFile() ;
00225
00226
00227
00239 virtual const std::string toString(
00240 Ceylan::VerbosityLevels level = Ceylan::high ) const ;
00241
00242
00243
00244
00245
00246
00247
00248
00249
00251 static std::string DefaultEncoding ;
00252
00253
00254
00255
00257 enum LowerThanSequence
00258 {
00259
00260
00262 Declaration,
00263
00265 Comment,
00266
00268 OpeningMarkup,
00269
00271 ClosingMarkup,
00272
00274 UnexpectedElement
00275
00276
00277 } ;
00278
00279
00280
00281
00297 static LowerThanSequence InterpretLowerThanSequence(
00298 System::InputStream & input, Ceylan::Uint8 & readChar ) ;
00299
00300
00301
00308 static std::string DescribeLowerThanSequence(
00309 LowerThanSequence sequence ) ;
00310
00311
00312
00326 static void InterpretXMLDeclaration(
00327 System::InputStream & input ) ;
00328
00329
00330
00343 static void ParseAttributeSequence(
00344 const std::string & toBeParsed,
00345 AttributeMap & attributeMap ) ;
00346
00347
00348
00349
00350
00351 protected:
00352
00353
00354
00375 virtual void handleNextElement(
00376 System::InputStream & input,
00377 std::stack<std::string> & markupStack,
00378 XMLTree * currentNode,
00379 Ceylan::Uint8 & remainder ) ;
00380
00381
00382
00388 std::string _filename ;
00389
00390
00391
00393 XMLTree * _parsedTree ;
00394
00395
00396
00403 std::string _encoding ;
00404
00405
00406
00407
00408 private:
00409
00410
00411
00422 XMLParser( const XMLParser & source ) ;
00423
00424
00425
00433 XMLParser & operator = ( const XMLParser & source ) ;
00434
00435
00436 } ;
00437
00438
00439 }
00440
00441 }
00442
00443
00444
00445 #endif // CEYLAN_XML_PARSER_H_
00446