00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #ifndef Tanl_Text_XmlReader_H
00025 #define Tanl_Text_XmlReader_H
00026
00027 #undef yyFlexLexer
00028 #define yyFlexLexer xmlFlexLexer
00029 #include "FlexLexer.h"
00030 #include "xml.h"
00031
00032 #include "Encoding.h"
00033
00034
00035 #include <fstream>
00036 #include <stdexcept>
00037 #include <vector>
00038
00039 namespace Tanl {
00040 namespace XML {
00041
00042 enum XmlNodeType
00043 {
00044 None,
00045 Attribute,
00046 CDATA,
00047 Comment,
00048 Document,
00049 DocumentType,
00050 Element,
00051 EndElement,
00052 Entity,
00053 EntityReference,
00054 Notation,
00055 ProcessingInstruction,
00056 Text,
00057 Whitespace,
00058 XmlDeclaration
00059 };
00060
00061 struct XmlException : public std::runtime_error {
00062 XmlException(char const* msg) : std::runtime_error(msg) {}
00063 };
00064
00065 class XmlReader
00066 {
00067 public:
00068
00069 XmlReader(std::istream& stream);
00070
00071 enum State {
00072 Initial,
00073 Interactive,
00074 Error,
00075 EndOfFile,
00076 Closed
00077 };
00078
00083 bool Read() throw(XmlException);
00084
00085 int AttributeCount() { return attrs.size(); }
00086
00087 bool MoveToFirstAttribute();
00088
00089 bool MoveToNextAttribute();
00091 bool Eof() { return state == EndOfFile; }
00092
00093 int Depth() { return depth; }
00094
00095 XmlNodeType NodeType;
00096 std::string Name;
00097 std::string Value;
00098 bool isEmptyElement;
00099 Text::Encoding const* encoding;
00100
00101 struct NodeAttr {
00102 NodeAttr(std::string& name, std::string& value) :
00103 name(name),
00104 value(value)
00105 { }
00106 std::string name;
00107 std::string value;
00108 };
00109
00110 private:
00111 bool readAttributes();
00112
00113 XmlScanner scanner;
00114 State state;
00115 int depth;
00116 std::string tagName;
00117 std::vector<NodeAttr> attrs;
00118 unsigned attrIndex;
00119 };
00120
00121 }
00122 }
00123
00124 #endif // Tanl_Text_XmlReader_H