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
00028 #ifndef cxxtools_Xml_XmlReader_h
00029 #define cxxtools_Xml_XmlReader_h
00030
00031 #include <cxxtools/string.h>
00032 #include <cxxtools/textstream.h>
00033 #include <cxxtools/xml/api.h>
00034 #include <cxxtools/xml/node.h>
00035 #include <cxxtools/xml/enddocument.h>
00036 #include <iosfwd>
00037
00038 namespace cxxtools {
00039
00040 namespace xml {
00041
00042 class Node;
00043 class StartElement;
00044 class EntityResolver;
00045
00081 class CXXTOOLS_XML_API XmlReader
00082 {
00083 public:
00084 class Iterator
00085 {
00086 public:
00087 Iterator()
00088 : _stream(0)
00089 , _node(0)
00090 { }
00091
00092 Iterator(XmlReader& xis)
00093 : _stream(&xis)
00094 , _node(0)
00095 { _node = &_stream->get(); }
00096
00097 Iterator(const Iterator& it)
00098 : _stream(it._stream), _node(it._node)
00099 { }
00100
00101 ~Iterator()
00102 { }
00103
00104 Iterator& operator=(const Iterator& it)
00105 {
00106 _stream = it._stream;
00107 _node = it._node;
00108 return *this;
00109 }
00110
00111 inline const Node& operator*() const
00112 { return *_node; }
00113
00114 inline const Node* operator->() const
00115 { return _node; }
00116
00117 Iterator& operator++()
00118 {
00119 if(_node->type() == Node::EndDocument)
00120 _node = 0;
00121 else
00122 _node = &_stream->next();
00123
00124 return *this;
00125 }
00126
00127 inline bool operator==(const Iterator& it) const
00128 { return _node == it._node; }
00129
00130 inline bool operator!=(const Iterator& it) const
00131 { return _node != it._node; }
00132
00133 private:
00134 XmlReader* _stream;
00135 const Node* _node;
00136 };
00137
00138 public:
00139
00140
00141
00142
00143
00144
00145 XmlReader(std::istream& is, int flags = 0);
00146
00147 XmlReader(std::basic_istream<Char>& is, int flags = 0);
00148
00149 ~XmlReader();
00150
00151 void reset(std::basic_istream<Char>& is, int flags = 0);
00152
00153 void reset(std::istream& is, int flags = 0);
00154
00155 const cxxtools::String& documentVersion() const;
00156
00157 const cxxtools::String& documentEncoding() const;
00158
00159 bool standaloneDocument() const;
00160
00161 EntityResolver& entityResolver();
00162
00163 const EntityResolver& entityResolver() const;
00164
00165 size_t depth() const;
00166
00167 Iterator current()
00168 {
00169 return Iterator(*this);
00170 }
00171
00172 Iterator end() const
00173 {
00174 return Iterator();
00175 }
00176
00178 const Node& get();
00179
00181 const Node& next();
00182
00183 bool advance();
00184
00185 const StartElement& nextElement();
00186
00187 const Node& nextTag();
00188
00189 std::size_t line() const;
00190
00191 private:
00192 class XmlReaderImpl* _impl;
00193 };
00194
00195 }
00196
00197 }
00198
00199 #endif