This class will read in an XML-file and call the appropriate handler functions of the Object classes and objects. More...
#include <utils.h>
Public Types | |
typedef pair< Attribute, XMLElement > | datapair |
Public Member Functions | |
bool | getAbortOnDataError () const |
const AttributeList & | getAttributes () const |
const datapair & | getCurrentElement () const |
const datapair & | getParentElement () const |
Object * | getParentObject () const |
Object * | getPreviousObject () const |
void * | getUserArea () const |
PythonFunction | getUserExit () const |
void | IgnoreElement () |
void | invalidateCurrentObject () |
bool | isObjectEnd () |
void | parse (xercesc::InputSource &, Object *, bool=false) |
void | readto (Object *) |
void | setAbortOnDataError (bool i) |
void | setUserArea (void *v) |
void | setUserExit (PyObject *p) |
void | shutdown () |
XMLInput (unsigned short maxNestedElmnts=20) | |
virtual | ~XMLInput () |
Static Public Member Functions | |
static char * | transcodeUTF8 (const XMLCh *) |
Protected Member Functions | |
virtual void | parse (Object *s, bool b=false) |
![]() | |
NonCopyable () | |
~NonCopyable () | |
This class will read in an XML-file and call the appropriate handler functions of the Object classes and objects.
This class is implemented based on the Xerces SAX XML parser. For debugging purposes a flag is defined at the start of the file "xmlparser.cpp". Uncomment the line and recompile to use it.
FrePPLe creates a new parser and loads the XML schema every time XML data need to be parsed. When this happens only a few times during a run this is good enough.
However, when the libary has to parse plenty of small XML messages this will create a significant overhead. The code would need to be enhanced to maintain a pool of parsers and cache their grammars.
typedef pair<Attribute,XMLElement> frepple::utils::XMLInput::datapair |
frepple::utils::XMLInput::XMLInput | ( | unsigned short | maxNestedElmnts = 20 | ) |
Constructor.
maxNestedElmnts | Defines the maximum depth of elements an XML document is allowed to have. The default is 20. |
Definition at line 78 of file xmlparser.cpp.
|
inlinevirtual |
|
inline |
Returns the behavior of the parser in case of data errors.
When true is returned, the processing of the XML stream continues after a DataException. Other, more critical, exceptions types will still abort the parsing process.
False indicates that the processing of the XML stream is aborted.
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
Return a pointer to the previous object being read in.
In a typical use the returned pointer will require a dynamic_cast to a subclass type.
The typical usage is as follows:
Operation o = dynamic_cast<Operation>(pIn.getPreviousObject()); if (o) doSomeThing(o); else throw LogicException("Incorrect object type");
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
void frepple::utils::XMLInput::parse | ( | xercesc::InputSource & | in, |
Object * | pRoot, | ||
bool | validate = false |
||
) |
This is the core parsing function, which triggers the XML parser to start processing the input. It is normally called from the method parse(Object*) once a proper stream has been created.
Definition at line 500 of file xmlparser.cpp.
|
inlineprotectedvirtual |
The real parsing job is delegated to subclasses. Subclass can then define the specifics for parsing a flat file, a string, a SOAP message, etc...
RuntimeException | Thrown in the following situations:
|
DataException | Thrown when the data can't be processed normally by the objects being created or updated. |
Reimplemented in frepple::utils::XMLInputFile, and frepple::utils::XMLInputString.
void frepple::utils::XMLInput::readto | ( | Object * | pPI | ) |
Redirect event stream into a new Object.
It is also possible to pass a NULL pointer to the function. In that situation, we simple ignore the content of that element.
Important: The user is reponsible of making sure the argument object has a proper write-lock. The release of that lock is handled by the parser.
Definition at line 388 of file xmlparser.cpp.
|
inline |
|
inline |
|
inline |
void frepple::utils::XMLInput::shutdown | ( | ) |
Abort the parsing. The actual shutdown cannot be called inside a SAX handler function, so actual shutdown is deferred until the next iteration of the feed loop.
Definition at line 415 of file xmlparser.cpp.
|
static |
Transcode the Xerces XML characters to our UTF8 encoded buffer. This method uses a statically allocated buffer, and subsequent calls to this method will overwrite the previous results.
Definition at line 66 of file xmlparser.cpp.