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  = 
TR_XERCES(
"Could not start reading the file due to the following problem: ");
 
  132   catch(
const xercesc::XMLException& e)
 
  134     std::string m  = 
TR_XERCES(
"Error when reading the XML document. Exception messages is: ");
 
  141     throw Exception(
TR_XERCES(
"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);
 
  179   catch(
const xercesc::XMLException& e)
 
  181     std::string m  = 
TR_XERCES(
"Error parsing the XML document. Exception messages is: ");
 
  186   catch(
const std::exception& )
 
  192     throw Exception(
TR_XERCES(
"Unexpected error in parse next!"));
 
  200   return m_readerH->getNodeType();
 
  205   return ToString(m_readerH->getElementURI());
 
  210   return ToString(m_readerH->getElementLocalName());
 
  215   return ToString(m_readerH->getElementQName());
 
  220   return ToString(m_readerH->getElementValue());
 
  225   return m_readerH->getDataLen();
 
  230   return (m_readerH->getElementAttrs() != 0) && (m_readerH->getElementAttrs()->getLength() > 0);
 
  235   return (hasAttrs() ? m_readerH->getElementAttrs()->getLength() : 0);
 
  240   assert(m_readerH->getElementAttrs());
 
  242   const XMLCh* value = m_readerH->getElementAttrs()->getValue(
StrToXMLCh(name).getXMLCh());
 
  249   assert(m_readerH->getElementAttrs());
 
  250   assert(i < m_readerH->getElementAttrs()->getLength());
 
  252   const XMLCh* value = m_readerH->getElementAttrs()->getValue(i);
 
  259   assert(m_readerH->getElementAttrs());
 
  260   assert(i < m_readerH->getElementAttrs()->getLength());
 
  262   const XMLCh* name = m_readerH->getElementAttrs()->getLocalName(i);
 
  269   assert(m_readerH->getElementAttrs());
 
  270   assert(m_readerH->getElementAttrs()->getLength() > i);
 
  272   const XMLCh* name = m_readerH->getElementAttrs()->getQName(i);
 
  279   assert(m_readerH->getElementAttrs());
 
  280   assert(m_readerH->getElementAttrs()->getLength() > i);
 
  282   const XMLCh* name = m_readerH->getElementAttrs()->getURI(i);
 
  289   assert(m_readerH->getElementAttrs());
 
  291   return m_readerH->getElementAttrs()->getIndex(
StrToXMLCh(name).getXMLCh());
 
  296   return m_readerH->getNumberOfNamespaces();
 
  301   const std::pair<const XMLCh*, const XMLCh*>& nns = m_readerH->getNamespace(i);
 
  309   m_parser->setInputBufferSize(size);
 
  319     m_parser->parseReset(*m_token);
 
  321   catch(
const xercesc::XMLException& e)
 
  323     std::string m  = 
TR_XERCES(
"Error reseting the parser. Exception messages is: ");
 
  330     throw Exception(
TR_XERCES(
"Unexpected error reseting the parser!"));
 
A class for converting a standard string to a Xerces string (XMLCh). 
 
A class for converting a standard string to a Xerces string (XMLCh). 
 
Reader()
Default constructor. 
 
#define TE_XERCES_READER_MAX_BUFFSIZE
It defines the default internal buffer size for parsing a XERCES file. 
 
std::string getAttrURI(std::size_t i) const 
It returns the attribute URI of the associated namespace in the case of an element node...
 
bool hasAttrs() const 
It tells if the element has attributes in the case of an element node. 
 
void getNamespace(std::size_t i, std::pair< std::string, std::string > &ns) const 
 
void setValidationScheme(bool d)
If true the parser will perform a validation scheme. 
 
ReaderHandler * m_readerH
A pointer to a content handler. 
 
This class implements Xerces interface for error handlers. 
 
const std::string getErrors() const 
It returns a concatenation of all reported error messages. 
 
This class implements Xerces interface for a handler that receives general document events...
 
std::string getAttrLocalName(std::size_t i) const 
It returns the local part of the attribute name for the i-th attribute. 
 
std::size_t getNumberOfNamespaces() const 
 
This class is designed to declare objects to be thrown as exceptions by TerraLib. ...
 
void setDoNamespaces(bool d)
It enables or disables the parser namespace processing. 
 
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. 
 
void setUseCachedGrammarInParse(bool d)
If true the reader will use cached grammar if it exists in the pool. 
 
std::string getAttr(const std::string &name) const 
It returns the attribute value in the case of an element node with valid attributes. 
 
std::size_t getAttrPosition(const std::string &name) const 
It returns the attribute position. 
 
bool next()
It gets the next event to be read. 
 
std::size_t getElementDataLen() const 
It returns the element data value in the case of VALUE node. 
 
std::string ToString(const XMLCh *const value)
It converts the XML string to a standard C++ string. 
 
NodeType
The type of node read by XML reader. 
 
xercesc::SAX2XMLReader * m_parser
A pointer to the parser used by the reader. 
 
te::xml::NodeType getNodeType() const 
It return the type of node read. 
 
This class implements Xerces interface for error handlers. 
 
void setDoSchema(bool d)
It enables or disables the parser schema processing. 
 
void reset()
It resets the parser. 
 
std::string getElementURI() const 
It returns the URI of the associated namespace in the case of an element node. 
 
ErrorHandler * m_errH
A pointer to an error handler. 
 
std::string getAttrQName(std::size_t i) const 
It returns the qualified name for the i-th attribute. 
 
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. 
 
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. 
 
std::string getElementQName() const 
It returns the qualified name in the case of an element node. 
 
This class implements Xerces interface for a handler that receives general document events...
 
void setInternalBufferSize(const std::size_t size)
It sets the maximal allowed buffer size used for parsing. 
 
#define TR_XERCES(message)
It marks a string in order to get translated. This is a special mark used in the Xerces module of Ter...