27 #include "../common/Exception.h" 
   28 #include "../common/Translator.h" 
   37 #include <xercesc/sax2/SAX2XMLReader.hpp> 
   38 #include <xercesc/sax2/XMLReaderFactory.hpp> 
   45     m_ignoreWhiteSpaces(false)
 
   47   m_parser = xercesc::XMLReaderFactory::createXMLReader();
 
   55     m_parser->setFeature(xercesc::XMLUni::fgSAX2CoreNameSpaces, 
true);
 
   56     m_parser->setFeature(xercesc::XMLUni::fgXercesSchema, 
true);
 
   57     m_parser->setFeature(xercesc::XMLUni::fgSAX2CoreValidation, 
true);
 
   58     m_parser->setFeature(xercesc::XMLUni::fgXercesUseCachedGrammarInParse, 
true);
 
   59     m_parser->setFeature(xercesc::XMLUni::fgXercesCacheGrammarFromParse, 
true);
 
   76   m_parser->setFeature(xercesc::XMLUni::fgSAX2CoreNameSpaces, d);
 
   81   m_parser->setFeature(xercesc::XMLUni::fgXercesSchema, d);
 
   86   m_parser->setFeature(xercesc::XMLUni::fgSAX2CoreValidation, d);
 
   91   m_parser->setFeature(xercesc::XMLUni::fgXercesUseCachedGrammarInParse, d);
 
   96   m_parser->setFeature(xercesc::XMLUni::fgXercesCacheGrammarFromParse, d);
 
  101   m_ignoreWhiteSpaces = d;
 
  112   m_token = 
new xercesc::XMLPScanToken;
 
  116     if(!m_parser->parseFirst(fileURI.c_str(), *m_token))
 
  120       std::string m  = 
TE_TR(
"Could not start reading the file due to the following problem: ");
 
  132   catch(
const xercesc::XMLException& e)
 
  134     std::string m  = 
TE_TR(
"Error when reading the XML document. Exception messages is: ");
 
  141     throw Exception(
TE_TR(
"Unexpected error reading the XML document!"));
 
  151   bool parserStatus = 
true;
 
  155     while(
true && parserStatus)
 
  157       if(m_readerH->isInContractedForm())
 
  160         m_readerH->setInContractedForm(
false);
 
  164         parserStatus = m_parser->parseNext(*m_token);
 
  166       if(m_parser->getErrorCount() != 0)
 
  168         std::string errmsg = m_errH->getErrors();
 
  169         throw Exception(errmsg);
 
  172       if(m_readerH->isInContractedForm())
 
  184   catch(
const xercesc::XMLException& e)
 
  186     std::string m  = 
TE_TR(
"Error parsing the XML document. Exception messages is: ");
 
  191   catch(
const std::exception& )
 
  197     throw Exception(
TE_TR(
"Unexpected error in parse next!"));
 
  205   return m_readerH->getNodeType();
 
  210   return ToString(m_readerH->getElementURI());
 
  215   return ToString(m_readerH->getElementLocalName());
 
  220   return ToString(m_readerH->getElementQName());
 
  225   return ToString(m_readerH->getElementValue());
 
  230   return m_readerH->getDataLen();
 
  235   return (m_readerH->getElementAttrs() != 0) && (m_readerH->getElementAttrs()->getLength() > 0);
 
  240   return (hasAttrs() ? m_readerH->getElementAttrs()->getLength() : 0);
 
  245   assert(m_readerH->getElementAttrs());
 
  247   const XMLCh* value = m_readerH->getElementAttrs()->getValue(
StrToXMLCh(name).getXMLCh());
 
  254   assert(m_readerH->getElementAttrs());
 
  255   assert(i < m_readerH->getElementAttrs()->getLength());
 
  257   const XMLCh* value = m_readerH->getElementAttrs()->getValue(i);
 
  264   assert(m_readerH->getElementAttrs());
 
  265   assert(i < m_readerH->getElementAttrs()->getLength());
 
  267   const XMLCh* name = m_readerH->getElementAttrs()->getLocalName(i);
 
  274   assert(m_readerH->getElementAttrs());
 
  275   assert(m_readerH->getElementAttrs()->getLength() > i);
 
  277   const XMLCh* name = m_readerH->getElementAttrs()->getQName(i);
 
  284   assert(m_readerH->getElementAttrs());
 
  285   assert(m_readerH->getElementAttrs()->getLength() > i);
 
  287   const XMLCh* name = m_readerH->getElementAttrs()->getURI(i);
 
  294   assert(m_readerH->getElementAttrs());
 
  296   return m_readerH->getElementAttrs()->getIndex(
StrToXMLCh(name).getXMLCh());
 
  301   return m_readerH->getNumberOfNamespaces();
 
  306   const std::pair<const XMLCh*, const XMLCh*>& nns = m_readerH->getNamespace(i);
 
  314   m_parser->setInputBufferSize(size);
 
  324     m_parser->parseReset(*m_token);
 
  326   catch(
const xercesc::XMLException& e)
 
  328     std::string m  = 
TE_TR(
"Error reseting the parser. Exception messages is: ");
 
  335     throw 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. 
 
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::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. 
 
ErrorHandler * m_errH
A pointer to an error handler. 
 
void read(const std::string &fileURI)
It prepare the given file to be read. 
 
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 
 
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. 
 
ReaderHandler * m_readerH
A pointer to a content handler. 
 
void setInternalBufferSize(const std::size_t size)
It sets the maximal allowed buffer size used for parsing. 
 
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. 
 
void setUseCachedGrammarInParse(bool d)
If true the reader will use cached grammar if it exists in the pool. 
 
std::string getElementQName() const 
It returns the qualified name in the case of an element node. 
 
void setDoSchema(bool d)
It enables or disables the parser schema processing. 
 
This class is designed to declare objects to be thrown as exceptions by TerraLib. ...
 
std::string getElementValue() const 
It returns the element data value in the case of VALUE node. 
 
#define TE_XERCES_READER_MAX_BUFFSIZE
It defines the default internal buffer size for parsing a XERCES file. 
 
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 
 
std::string ToString(const XMLCh *const value)
It converts the XML string to a standard C++ string. 
 
void reset()
It resets the parser.