00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013 #ifndef XMLElement_H
00014 #define XMLElement_H
00015
00016 #include <iostream>
00017 #include <fstream>
00018 #include <string>
00019 #include <map>
00020 #include <list>
00021
00022 #include "XMLParseException.h"
00023
00024 using namespace std;
00025
00026
00032 class XMLElement
00033 {
00037 private: map<string,string> attributes;
00038
00042 private: list<XMLElement> children;
00043
00047 private: string name;
00048
00049
00053 private: string contents;
00054
00055
00060 private: map<string,string> * entities;
00061
00068 private: map<string,string> entitiesInstance;
00069
00070
00074 private: int lineNr;
00075
00079 private: int parserLineNr;
00080
00087 private: unsigned char charReadTooMuch;
00088
00092 private: istream * reader;
00093
00094
00099 private: bool ignoreWhitespace;
00100
00101
00102
00108 public: XMLElement();
00109
00118 public: XMLElement(map<string,string> * entities);
00119
00128 public: XMLElement(bool skipLeadingWhitespace);
00129
00140 public: XMLElement(map<string,string> * entities, bool skipLeadingWhitespace);
00141
00142
00160 private: XMLElement(map<string,string> * entities, bool skipLeadingWhitespace,
00161 bool fillBasicConversionTable);
00162
00173 private: void initialize(bool skipLeadingWhitespace,
00174 bool fillBasicConversionTable);
00175
00188 private: void initialize(map<string,string> * entities,
00189 bool skipLeadingWhitespace,
00190 bool fillBasicConversionTable);
00191
00197 public: int countChildren();
00198
00204 public: void addChild(XMLElement & child);
00205
00212 public: void setAttribute(string & name, string & value);
00213
00220 public: void setAttribute(string & name, int value);
00221
00228 public: void setAttribute(string & name, double value);
00229
00237 public: void parse(string & file);
00238
00239
00247 public: void parse(istream & reader);
00248
00257 private: void parse(istream & reader, int startingLineNr);
00258
00264 public: void removeChild(XMLElement & child);
00265
00272 public: list<XMLElement> * getChildren();
00273
00274
00283 public: string getStringAttribute(string & name);
00284
00294 public: string getStringAttribute(string & name, string & defaultValue);
00295
00304 public: int getIntAttribute(string & name);
00305
00315 public: int getIntAttribute(string & name, int defaultValue);
00316
00325 public: double getDoubleAttribute(string & name);
00326
00336 public: double getDoubleAttribute(string & name, double defaultValue);
00337
00358 public: bool getBooleanAttribute(string & name, string & trueValue,
00359 string & falseValue, bool defaultValue);
00360
00366 public: void removeAttribute(string & name);
00367
00373 public: void setContent(string & content);
00374
00381 public: string getContent();
00382
00388 public: string getName();
00389
00395 public: void setName(string &name);
00396
00403 public: int getLineNr();
00404
00411 private: void scanIdentifier(string & result);
00412
00418 private: unsigned char scanWhitespace();
00419
00428 private: unsigned char scanWhitespace(string & result);
00429
00436 private: void scanString(string & str);
00437
00445 private: void scanPCData(string & data);
00446
00452 private: void scanElement(XMLElement & elt);
00453
00460 private: bool checkCDATA(string & buf);
00461
00465 private: void skipComment();
00466
00473 private: void skipSpecialTag(int bracketLevel);
00474
00482 private: bool checkLiteral(string literal);
00483
00490 private: void resolveEntity(string & buf);
00491
00497 private: unsigned char readChar();
00498
00504 private: void unreadChar(unsigned char ch);
00505
00513 private: XMLElement createAnotherElement();
00514
00520 public: void singleLineWriter(ostream & writer);
00521
00529 private: void indent(ostream & writer, int depth);
00530
00536 public: void write(string & file);
00537
00538
00544 public: void prettyWriter(ostream & writer);
00545
00553 private: void prettyWriter(ostream & writer,int depth);
00554
00555
00562 private: void writeEncoded(ostream & writer, string & str);
00563
00569 public: void operator=(XMLElement & rhs);
00570
00579 public: bool operator==(XMLElement & rhs);
00580
00589 private: XMLParseException invalidValueSet(string name);
00590
00600 private: XMLParseException invalidValue(string name, string value);
00601
00608 private: XMLParseException unexpectedEndOfData();
00609
00617 private: XMLParseException syntaxError(string context);
00618
00627 private: XMLParseException unicodeError(int value);
00628
00638 private: XMLParseException expectedInput(string charSet);
00639
00647 private: XMLParseException unknownEntity(string name);
00648 };
00649
00650 #endif