27 #include "../common/Exception.h" 28 #include "../core/encoding/CharEncoding.h" 29 #include "../core/logger/Logger.h" 30 #include "../core/translator/Translator.h" 31 #include "../xml/Exception.h" 42 #include <xercesc/sax2/SAX2XMLReader.hpp> 43 #include <xercesc/framework/MemBufInputSource.hpp> 44 #include <xercesc/sax2/XMLReaderFactory.hpp> 51 m_ignoreWhiteSpaces(true)
53 m_parser = xercesc::XMLReaderFactory::createXMLReader();
61 m_parser->setFeature(xercesc::XMLUni::fgSAX2CoreNameSpaces,
true);
62 m_parser->setFeature(xercesc::XMLUni::fgXercesSchema,
false);
63 m_parser->setFeature(xercesc::XMLUni::fgSAX2CoreValidation,
false);
64 m_parser->setFeature(xercesc::XMLUni::fgXercesUseCachedGrammarInParse,
true);
65 m_parser->setFeature(xercesc::XMLUni::fgXercesCacheGrammarFromParse,
true);
89 m_parser->setFeature(xercesc::XMLUni::fgSAX2CoreNameSpaces, d);
94 m_parser->setFeature(xercesc::XMLUni::fgXercesSchema, d);
99 m_parser->setFeature(xercesc::XMLUni::fgSAX2CoreValidation, d);
104 m_parser->setFeature(xercesc::XMLUni::fgXercesUseCachedGrammarInParse, d);
109 m_parser->setFeature(xercesc::XMLUni::fgXercesCacheGrammarFromParse, d);
125 m_token =
new xercesc::XMLPScanToken;
130 std::string text((std::istreambuf_iterator<char>(file)),
131 std::istreambuf_iterator<char>());
132 xercesc::MemBufInputSource xmlbuffer((const ::XMLByte*)text.c_str(), text.size(),
"");
137 std::string m =
TE_TR(
"Could not start reading the file due to the following problem: ");
141 throw te::xml::Exception(m);
149 catch(
const xercesc::XMLException& e)
151 std::string m =
TE_TR(
"Error when reading the XML document. Exception messages is: ");
154 throw te::xml::Exception(m);
158 throw te::xml::Exception(
TE_TR(
"Unexpected error reading the XML document!"));
168 bool parserStatus =
true;
172 while(
true && parserStatus)
186 throw te::xml::Exception(errmsg);
201 catch(
const xercesc::XMLException& e)
203 std::string m =
TE_TR(
"Error parsing the XML document. Exception messages is: ");
206 throw te::xml::Exception(m);
208 catch(
const std::exception& )
214 throw te::xml::Exception(
TE_TR(
"Unexpected error in parse next!"));
272 assert(i < m_readerH->getElementAttrs()->getLength());
282 assert(i < m_readerH->getElementAttrs()->getLength());
343 catch(
const xercesc::XMLException& e)
345 std::string m =
TE_TR(
"Error reseting the parser. Exception messages is: ");
348 throw te::xml::Exception(m);
352 throw te::xml::Exception(
TE_TR(
"Unexpected error reseting the parser!"));
std::string getAttrLocalName(std::size_t i) const
It returns the local part of the attribute name for the i-th attribute.
A class for converting a standard string to a Xerces string (XMLCh).
bool next()
It gets the next event to be read.
std::string getElementURI() const
It returns the URI of the associated namespace in the case of an element node.
bool m_ignoreWhiteSpaces
A flag that indicates if the parser should ignore white spaces.
void setDoNamespaces(bool d)
It enables or disables the parser namespace processing.
Reader()
Default constructor.
std::size_t getAttrPosition(const std::string &name) const
It returns the attribute position.
void setIgnoreWhiteSpaces(bool d)
If true the parser will ignore the white space characters.
A class for converting a standard string to a Xerces string (XMLCh).
This class implements Xerces interface for error handlers.
std::size_t getNumberOfNamespaces() const
const xercesc::Attributes * getElementAttrs() const
TODO.
std::string getAttrURI(std::size_t i) const
It returns the attribute URI of the associated namespace in the case of an element node...
#define TE_TR(message)
It marks a string in order to get translated.
static std::string fromUTF8(const std::string &src)
Convert a string in UTF-8 to the current locale encoding.
ErrorHandler * m_errH
A pointer to an error handler.
const XMLCh * getElementQName() const
TODO.
void setNodeType(te::xml::NodeType type)
void read(const std::string &fileURI)
It prepare the given file to be read.
const std::pair< const XMLCh *, const XMLCh * > & getNamespace(std::size_t i) const
void setCacheGrammarFromParse(bool d)
If true it caches the grammar in the pool for re-use in subsequent parses.
const std::string getErrors() const
It returns a concatenation of all reported error messages.
void setValidationScheme(bool d)
If true the parser will perform a validation scheme.
NodeType
The type of node read by XML reader.
This class implements Xerces interface for a handler that receives general document events...
std::size_t getNumberOfNamespaces() const
const XMLCh * getElementURI() const
TODO.
xercesc::SAX2XMLReader * m_parser
A pointer to the parser used by the reader.
std::string getAttrQName(std::size_t i) const
It returns the qualified name for the i-th attribute.
static te::dt::DateTime d(2010, 8, 9, 15, 58, 39)
ReaderHandler * m_readerH
A pointer to a content handler.
xercesc::XMLPScanToken * m_token
This keeps the parser state.
void setInternalBufferSize(const std::size_t size)
It sets the maximal allowed buffer size used for parsing.
#define TE_XERCES_READER_MAX_BUFFSIZE
It defines the default internal buffer size for parsing a XERCES file.
std::string getElementLocalName() const
It returns the local part of the element name in the case of an element node.
This class implements Xerces interface for a handler that receives general document events...
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.
This class implements Xerces interface for error handlers.
const XMLCh * getElementLocalName() const
TODO.
te::xml::NodeType getNodeType() const
It return the type of node read by the handler.
bool isInContractedForm() const
void setUseCachedGrammarInParse(bool d)
If true the reader will use cached grammar if it exists in the pool.
XMLSize_t getDataLen() const
std::string getElementQName() const
It returns the qualified name in the case of an element node.
const XMLCh * getElementValue() const
void setDoSchema(bool d)
It enables or disables the parser schema processing.
void setInContractedForm(bool d)
#define TE_LOG_ERROR(message)
Use this tag in order to log a message to the TerraLib default logger with the ERROR level...
std::string getElementValue() const
It returns the element data value in the case of VALUE node.
std::size_t getNumberOfAttrs() const
It returns the number of attributes in the case of an element node.
bool hasAttrs() const
It tells if the element has attributes in the case of an element node.
std::string getAttr(const std::string &name) const
It returns the attribute value in the case of an element node with valid attributes.
void getNamespace(std::size_t i, std::pair< std::string, std::string > &ns) const
file(WRITE ${CMAKE_BINARY_DIR}/config_qhelp.cmake"configure_file (${TERRALIB_ABSOLUTE_ROOT_DIR}/doc/qhelp/help.qhcp.in ${CMAKE_BINARY_DIR}/share/terraview/help/help.qhcp @ONLY)") add_custom_command(OUTPUT del_dir COMMAND $
std::string ToString(const XMLCh *const value)
It converts the XML string to a standard C++ string.
void reset()
It resets the parser.