![]() |
Mapper
0.9.0
API documentation
|
This class provides recovery from invalid characters in an XML stream. More...
#include <xml_stream_util.h>
Public Member Functions | |
XmlRecoveryHelper (QXmlStreamReader &xml) | |
Constructs a new recovery helper for the given xml stream. More... | |
bool | operator() () |
Checks the stream for an error which this utility can handle, applies corrections, and resets the stream. More... | |
This class provides recovery from invalid characters in an XML stream.
Some characters are not allowed in well-formed XML 1.0 (cf. https://www.w3.org/TR/2008/REC-xml-20081126/#NT-Char). While QXmlStreamWriter will not complain when writing such characters, QXmlStreamReader will raise a NotWellFormedError. This class will remove offending characters from the input and reset the stream reader to the state it had when the helper object was initialized.
In a single recovery attempt, the utility tries to handle all offending characters from the element for which the tool was constructed. For each offending character, the whole XML data is parsed again from the start. That's why multiple corrections may take a long time to run.
The XML stream must be based on a QIODevice which supports QIODevice::seek.
Synopsis:
XmlRecoveryHelper recovery(xml); auto text = xml.readElementText(); if (xml.hasError() && recovery()) { addWarning(tr("Some invalid characters had to be removed."); text = xml.readElementText(); }
|
inline |
Constructs a new recovery helper for the given xml stream.
Captures the current position in the XML stream (QXmlStreamReader::characterOffset()).
bool OpenOrienteering::XmlRecoveryHelper::operator() | ( | ) |
Checks the stream for an error which this utility can handle, applies corrections, and resets the stream.
If this operator returns false if either there was a different type of error, or if recovery failed. If it returns true, the stream was modified in order to fix the errors which are handled by this utility, and a new attempt can be made to parse the remainder of the stream.