Loading...
Searching...
No Matches
Reader.h
Go to the documentation of this file.
1/* Copyright (C) 2008 National Institute For Space Research (INPE) - Brazil.
2
3 This file is part of the TerraLib - a Framework for building GIS enabled applications.
4
5 TerraLib is free software: you can redistribute it and/or modify
6 it under the terms of the GNU Lesser General Public License as published by
7 the Free Software Foundation, either version 3 of the License,
8 or (at your option) any later version.
9
10 TerraLib is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU Lesser General Public License for more details.
14
15 You should have received a copy of the GNU Lesser General Public License
16 along with TerraLib. See COPYING. If not, write to
17 TerraLib Team at <terralib-team@terralib.org>.
18 */
19
20/*!
21 \file Reader.h
22
23 \brief A class that models a XML reader object built on top of Xerces-C++.
24*/
25
26#ifndef __TERRALIB_XERCES_INTERNAL_READER_H
27#define __TERRALIB_XERCES_INTERNAL_READER_H
28
29// TerraLib
30#include "../xml/Reader.h"
31#include "Config.h"
32
33// STL
34#include <string>
35
36// Xerces-C++
37#include <xercesc/util/XercesDefs.hpp>
38
39// Forward declaration
40XERCES_CPP_NAMESPACE_BEGIN
41class Attributes;
42class SAX2XMLReader;
43class XMLPScanToken;
44XERCES_CPP_NAMESPACE_END
45
46namespace te
47{
48 namespace xerces
49 {
50// Forward declaration
51 class ErrorHandler;
52 class ReaderHandler;
53
54 /*!
55 \class Reader
56
57 \brief A class that models a XML reader object built on top of Xerces-C++
58
59 This API is intend to simplify the task of reading XML files. We have
60 tried to model it close to the Libxml2 API (see http://xmlsoft.org/xmlreader.html for more information)
61 but keeping all Xerces-C++ support capabilities: schema validation and grammar cache.
62
63 If you prefer to use the SAX or DOM parsers, please, look
64 the Xerces-C++ documentation available at http://xerces.apache.org/xerces-c.
65 */
66 class Reader : public te::xml::Reader
67 {
68 public:
69
70 /*! \brief Default constructor. */
72
73 /*! \brief Destructor. */
75
76 void setDoNamespaces(bool d);
77
78 void setDoSchema(bool d);
79
80 void setValidationScheme(bool d);
81
83
85
87
88 void read(const std::string& fileURI);
89
90 void readFromContent(const std::string& content) override;
91
92 bool next();
93
95
96 std::string getElementURI() const;
97
98 std::string getElementLocalName() const;
99
100 std::string getElementQName() const;
101
102 std::string getElementValue() const;
103
104 std::size_t getElementDataLen() const;
105
106 bool hasAttrs() const;
107
108 std::size_t getNumberOfAttrs() const;
109
110 std::string getAttr(const std::string& name) const;
111
112 std::string getAttr(std::size_t i) const;
113
114 std::string getAttrLocalName(std::size_t i) const;
115
116 std::string getAttrQName(std::size_t i) const;
117
118 std::string getAttrURI(std::size_t i) const;
119
120 std::size_t getAttrPosition(const std::string& name) const;
121
122 std::size_t getNumberOfNamespaces() const;
123
124 void getNamespace(std::size_t i, std::pair<std::string, std::string>& ns) const;
125
126 void setInternalBufferSize(const std::size_t size);
127
128 /*!
129 \brief It resets the parser.
130
131 \exception Exception It throws an exception if it is not possible to reset the parser.
132
133 \note Xerces extended method.
134 */
135 void reset();
136
137 private:
138
139 xercesc::SAX2XMLReader* m_parser; //!< A pointer to the parser used by the reader.
140 ReaderHandler* m_readerH; //!< A pointer to a content handler.
141 ErrorHandler* m_errH; //!< A pointer to an error handler.
142 xercesc::XMLPScanToken* m_token; //!< This keeps the parser state.
143 bool m_ignoreWhiteSpaces; //!< A flag that indicates if the parser should ignore white spaces.
144 };
145
146 } // end namespace xerces
147} // end namespace te
148
149#endif // __TERRALIB_XERCES_INTERNAL_READER_H
150
This class implements Xerces interface for error handlers.
Definition: ErrorHandler.h:51
This class implements Xerces interface for a handler that receives general document events.
Definition: ReaderHandler.h:56
A class that models a XML reader object built on top of Xerces-C++.
Definition: Reader.h:67
void setDoNamespaces(bool d)
It enables or disables the parser namespace processing.
std::string getAttrQName(std::size_t i) const
It returns the qualified name for the i-th attribute.
void setValidationScheme(bool d)
If true the parser will perform a validation scheme.
void read(const std::string &fileURI)
It prepare the given file to be read.
bool m_ignoreWhiteSpaces
A flag that indicates if the parser should ignore white spaces.
Definition: Reader.h:143
void setCacheGrammarFromParse(bool d)
If true it caches the grammar in the pool for re-use in subsequent parses.
void setInternalBufferSize(const std::size_t size)
It sets the maximal allowed buffer size used for parsing.
std::string getAttr(std::size_t i) const
It returns the attribute value in the case of an element node with valid attributes.
void setIgnoreWhiteSpaces(bool d)
If true the parser will ignore the white space characters.
std::string getElementLocalName() const
It returns the local part of the element name in the case of an element node.
void reset()
It resets the parser.
std::string getElementValue() const
It returns the element data value in the case of VALUE node.
bool next()
It gets the next event to be read.
bool hasAttrs() const
It tells if the element has attributes in the case of an element node.
~Reader()
Destructor.
xercesc::XMLPScanToken * m_token
This keeps the parser state.
Definition: Reader.h:142
void setDoSchema(bool d)
It enables or disables the parser schema processing.
std::string getElementURI() const
It returns the URI of the associated namespace in the case of an element node.
std::string getAttrURI(std::size_t i) const
It returns the attribute URI of the associated namespace in the case of an element node.
te::xml::NodeType getNodeType() const
It return the type of node read.
std::size_t getElementDataLen() const
It returns the element data value in the case of VALUE node.
xercesc::SAX2XMLReader * m_parser
A pointer to the parser used by the reader.
Definition: Reader.h:139
std::size_t getNumberOfNamespaces() const
std::string getAttr(const std::string &name) const
It returns the attribute value in the case of an element node with valid attributes.
ReaderHandler * m_readerH
A pointer to a content handler.
Definition: Reader.h:140
std::string getAttrLocalName(std::size_t i) const
It returns the local part of the attribute name for the i-th attribute.
std::string getElementQName() const
It returns the qualified name in the case of an element node.
std::size_t getNumberOfAttrs() const
It returns the number of attributes in the case of an element node.
void setUseCachedGrammarInParse(bool d)
If true the reader will use cached grammar if it exists in the pool.
void getNamespace(std::size_t i, std::pair< std::string, std::string > &ns) const
std::size_t getAttrPosition(const std::string &name) const
It returns the attribute position.
ErrorHandler * m_errH
A pointer to an error handler.
Definition: Reader.h:141
void readFromContent(const std::string &content) override
It prepare the given content to be read.
Reader()
Default constructor.
This class models a XML reader object.
Definition: Reader.h:56
NodeType
The type of node read by XML reader.
Definition: Enums.h:41
TerraLib.
Proxy configuration file for TerraView (see terraview_config.h).