42 const std::string& file,
const std::string& expectedRoot)
43 : myParentHandler(nullptr), myParentIndicator(
SUMO_TAG_NOTHING), myFileName(file),
44 myExpectedRoot(expectedRoot), myNextSectionStart(-1, nullptr) {
46 while (tags[i].key != terminatorTag) {
47 myTagMap.insert(TagMap::value_type(tags[i].str, tags[i].key));
51 while (attrs[i].key != terminatorAttr) {
52 int key = attrs[i].
key;
87 int len = (int)name.length();
88 XMLCh* ret =
new XMLCh[len + 1];
90 for (; i < len; i++) {
91 ret[i] = (XMLCh) name[i];
101 const XMLCh*
const qname,
102 const XERCES_CPP_NAMESPACE::Attributes& attrs) {
136 const XMLCh*
const qname) {
145 char* buf =
new char[len + 1];
157 }
catch (std::runtime_error&) {
187 const XERCES3_SIZE_t length) {
196 TagMap::const_iterator i =
myTagMap.find(tag);
206 std::ostringstream buf;
207 char* pMsg = XERCES_CPP_NAMESPACE::XMLString::transcode(exception.getMessage());
208 buf << pMsg << std::endl;
209 buf <<
TL(
" In file '") <<
getFileName() <<
"'" << std::endl;
210 buf <<
TL(
" At line/column ") << exception.getLineNumber() + 1
211 <<
'/' << exception.getColumnNumber() <<
"." << std::endl;
212 XERCES_CPP_NAMESPACE::XMLString::release(&pMsg);
#define WRITE_WARNINGF(...)
#define WRITE_WARNING(msg)
@ SUMO_TAG_NOTHING
invalid tag, must be the last one
static bool isAbsolute(const std::string &path)
Returns the information whether the given path is absolute.
static std::string getConfigurationRelative(const std::string &configPath, const std::string &path)
Returns the second path as a relative path to the first file.
A handler which converts occurring elements and attributes into enums.
void registerParent(const int tag, GenericSAXHandler *handler)
Assigning a parent handler which is enabled when the specified tag is closed.
virtual void myCharacters(int element, const std::string &chars)
Callback method for characters to implement by derived classes.
std::string buildErrorMessage(const XERCES_CPP_NAMESPACE::SAXParseException &exception)
Builds an error message.
int convertTag(const std::string &tag) const
Converts a tag from its string into its numerical representation.
XMLCh * convert(const std::string &name) const
converts from c++-string into unicode
GenericSAXHandler(SequentialStringBijection::Entry *tags, int terminatorTag, SequentialStringBijection::Entry *attrs, int terminatorAttr, const std::string &file, const std::string &expectedRoot="")
Constructor.
void startElement(const XMLCh *const uri, const XMLCh *const localname, const XMLCh *const qname, const XERCES_CPP_NAMESPACE::Attributes &attrs)
The inherited method called when a new tag opens.
bool mySectionEnded
whether the reader has already seen the end of the section
std::string myFileName
The name of the currently parsed file.
bool mySectionOpen
whether an element of the current section is open
void error(const XERCES_CPP_NAMESPACE::SAXParseException &exception)
Handler for XML-errors.
bool mySectionSeen
whether the reader has already seen the begin of the section
GenericSAXHandler * myParentHandler
The handler to give control back to.
int mySection
The tag indicating the current section to parse.
void setFileName(const std::string &name)
Sets the current file name.
int myParentIndicator
The tag indicating that control should be given back.
void characters(const XMLCh *const chars, const XERCES3_SIZE_t length)
The inherited method called when characters occurred.
virtual ~GenericSAXHandler()
Destructor.
virtual void myEndElement(int element)
Callback method for a closing tag to implement by derived classes.
void warning(const XERCES_CPP_NAMESPACE::SAXParseException &exception)
Handler for XML-warnings.
std::string myExpectedRoot
The root element to expect, empty string disables the check.
std::pair< int, SUMOSAXAttributes * > myNextSectionStart
void callParentEnd(int element)
signal endElement to the parent handler (special case for MSCalibrator)
virtual void myStartElement(int element, const SUMOSAXAttributes &attrs)
Callback method for an opening tag to implement by derived classes.
std::vector< std::string > myCharactersVector
A list of character strings obtained so far to build the complete characters string at the end.
void fatalError(const XERCES_CPP_NAMESPACE::SAXParseException &exception)
Handler for XML-errors.
bool myRootSeen
whether the reader has already seen the root element
bool myCollectCharacterData
whether the reader should collect character data
const std::string & getFileName() const
returns the current file name
std::vector< std::string > myPredefinedTagsMML
the map from ids to their string representation
void endElement(const XMLCh *const uri, const XMLCh *const localname, const XMLCh *const qname)
The inherited method called when a tag is being closed.
Encapsulated SAX-Attributes.
Encapsulated Xerces-SAX-attributes.
std::string getString(int id, bool *isPresent=nullptr) const
Returns the string-value of the named (by its enum-value) attribute.
static std::string transcode(const XMLCh *const data)
converts a 0-terminated XMLCh* array (usually UTF-16, stemming from Xerces) into std::string in UTF-8
static void setHandler(GenericSAXHandler &handler)
Sets the given handler for the default reader.
static bool runParser(GenericSAXHandler &handler, const std::string &file, const bool isNet=false, const bool isRoute=false, const bool isExternal=false, const bool catchExceptions=true)
Runs the given handler on the given file; returns if everything's ok.