A wrapper for QXmlStreamReader. More...
Public Types | |
enum | ErrorCode { NoError = 0 , UnexpectedElementError = 1 , CustomError = 2 , NotWellFormedError = 3 , PrematureEndOfDocumentError = 4 } |
Error codes. More... | |
enum | TokenType { NoToken = 0 , Invalid = 1 , StartDocument = 2 , EndDocument = 3 , StartElement = 4 , EndElement = 5 , Characters = 6 , Comment = 7 , DTD = 8 , EntityReference = 9 , ProcessingInstruction = 10 } |
Token types. More... | |
enum | XmlType { XmlFile = 0 , XmlString = 1 } |
Constructor flags. More... | |
Public Member Functions | |
void | raiseError (String aMessage='') |
Raises a custom error with an optional error message. More... | |
ByteArray | readElementBytes () |
Binary version of readElementText(), returning the decoded binary data. More... | |
String | readElementText () |
Convenience function to be called in case a StartElement was read. More... | |
TokenType | readNext () |
Reads the next token and returns its type. More... | |
XmlReader (String aString, XmlType aType=XmlFile) | |
Flexible constructor. More... | |
Properties | |
Boolean | atEnd |
Returns true if the reader has read until the end of the XML document, or if an error has occurred and reading has been aborted. More... | |
ArrayOfObjects | attributes |
The attributes of a StartElement, as array of objects where each object holds the data of one attribute. More... | |
Object | attributeValues |
The attributes of a StartElement, as an object holding the qualified names of the attributes with their values as properties. More... | |
ByteArray | bytes |
Returns the binary data from the text of Characters which is assumed to be Base64 encoded. More... | |
Number | columnNumber |
The current column number. More... | |
String | documentEncoding |
If tokenType is StartDocument, this function returns the encoding string as specified in the XML declaration. More... | |
String | documentVersion |
If tokenType is StartDocument, this function returns the version string as specified in the XML declaration. More... | |
String | dtdName |
If tokenType is DTD, this function returns the DTD's name. More... | |
String | dtdPublicId |
If tokenType is DTD, this function returns the DTD's public identifier. More... | |
String | dtdSystemId |
If tokenType is DTD, this function returns the DTD's system identifier. More... | |
ErrorCode | error |
Returns the type of the current error, or NoError if no error occurred. More... | |
String | errorString |
Returns the error message that was set with raiseError(). More... | |
Boolean | hasError |
The reader has is in error state. More... | |
Boolean | isCDATA |
Returns true if the reader reports characters that stem from a CDATA section. More... | |
Boolean | isWhitespace |
The current token of type Characters is white space only. More... | |
Number | lineNumber |
The current line number in the XML. More... | |
String | name |
Returns the local name of a StartElement, EndElement, or an EntityReference. More... | |
String | prefix |
Returns the local name of a StartElement, EndElement or an EntityReference. More... | |
String | qualifiedName |
Returns the qualified name of a StartElement or EndElement. More... | |
String | text |
Returns the text of Characters, Comment, DTD, or EntityReference. More... | |
String | tokenString |
Returns the reader's current token as string. More... | |
TokenType | tokenType |
Returns the type of the current token. More... | |
A wrapper for QXmlStreamReader.
Example usage:
Error codes.
Enumerator | |
---|---|
NoError | No error has occurred. |
UnexpectedElementError | The parser encountered an element that was different to those it expected. |
CustomError | A custom error has been raised with raiseError(). |
NotWellFormedError | The parser internally raised an error due to the read XML not being well-formed. |
PrematureEndOfDocumentError | The input stream ended before a well-formed XML document was parsed. |
Token types.
Enumerator | |
---|---|
NoToken | The reader has not yet read anything. |
Invalid | An error has occurred, reported in error and errorString. |
StartDocument | The reader reports the XML version number in documentVersion, and the encoding as specified in the XML document in documentEncoding. |
EndDocument | The reader reports the end of the document. |
StartElement | The reader reports the start of an element with name. Empty elements are also reported as StartElement, followed directly by EndElement. The convenience function readElementText() can be called to concatenate all content until the corresponding EndElement. Attributes are reported in attributes and attributeValues. |
EndElement | The reader reports the end of an element with name. |
Characters | The reader reports characters in text. If the characters are all white-space, isWhitespace returns true. If the characters stem from a CDATA section, isCDATA is true. |
Comment | The reader reports a comment in text. |
DTD | The reader reports a DTD in text. Details of the DTD declaration are reported in in dtdName, dtdPublicId and dtdSystemId. |
EntityReference | The reader reports an entity reference that could not be resolved. The name of the reference is reported in name, the replacement in text. |
ProcessingInstruction | The reader reports a processing instruction. |
Flexible constructor.
aString | The file name or the XML itself. |
aType | Whether aString is a file name (the default), or the XML content itself. |
void bps::XmlReader::raiseError | ( | String | aMessage = '' | ) |
Raises a custom error with an optional error message.
aMessage | The custom message to apply if not empty. |
ByteArray bps::XmlReader::readElementBytes | ( | ) |
Binary version of readElementText(), returning the decoded binary data.
The text is assumed to be encoded as Base64.
String bps::XmlReader::readElementText | ( | ) |
Convenience function to be called in case a StartElement was read.
Reads until the corresponding EndElement and returns all text in-between. In case of no error, the current token (see tokenType) after having called this function is EndElement. The function concatenates text when it reads either Characters or EntityReference tokens, but skips ProcessingInstruction and Comment. In case anything else is read before reaching EndElement, the function returns what it read so far and raises an UnexpectedElementError.
TokenType bps::XmlReader::readNext | ( | ) |
Reads the next token and returns its type.
Once an error is reported by readNext(), further reading of the XML stream is not possible. Then atEnd returns true, hasError returns true, and this function returns Invalid.
|
read |
Returns true if the reader has read until the end of the XML document, or if an error has occurred and reading has been aborted.
Otherwise, it returns false.
|
read |
The attributes of a StartElement, as array of objects where each object holds the data of one attribute.
Following elements are in the object:
Name | Type | Description |
---|---|---|
isDefault | Boolean | True if the parser added this attribute with a default value following an ATTLIST declaration in the DTD. |
name | String | The attributes local name. |
namespaceUri | String | The attributes resolved namespaceUri, or an empty string reference if the attribute does not have a defined namespace. |
prefix | String | The attributes namespace prefix. |
qualifiedName | String | The attributes qualified name. |
value | String | The attributes value. |
|
read |
The attributes of a StartElement, as an object holding the qualified names of the attributes with their values as properties.
Example:
Is equivalent to:
|
read |
Returns the binary data from the text of Characters which is assumed to be Base64 encoded.
|
read |
The current column number.
Column counting starts with 0.
|
read |
If tokenType is StartDocument, this function returns the encoding string as specified in the XML declaration.
Otherwise an empty string is returned.
|
read |
If tokenType is StartDocument, this function returns the version string as specified in the XML declaration.
Otherwise an empty string is returned.
|
read |
If tokenType is DTD, this function returns the DTD's name.
Otherwise an empty string is returned.
|
read |
If tokenType is DTD, this function returns the DTD's public identifier.
Otherwise an empty string is returned.
|
read |
If tokenType is DTD, this function returns the DTD's system identifier.
Otherwise an empty string is returned.
|
read |
Returns the type of the current error, or NoError if no error occurred.
|
read |
Returns the error message that was set with raiseError().
|
read |
The reader has is in error state.
Check error and errorString.
|
read |
Returns true if the reader reports characters that stem from a CDATA section.
Otherwise returns false.
|
read |
The current token of type Characters is white space only.
This is normally between two elements in formatted XML.
|
read |
The current line number in the XML.
Line numbering starts with 1.
|
read |
Returns the local name of a StartElement, EndElement, or an EntityReference.
|
read |
Returns the local name of a StartElement, EndElement or an EntityReference.
|
read |
Returns the qualified name of a StartElement or EndElement.
A qualified name is the raw name of an element in the XML data. It consists of the namespace prefix, followed by colon, followed by the element's local name. Since the namespace prefix is not unique (the same prefix can point to different namespaces and different prefixes can point to the same namespace), you shouldn't use qualifiedName(), but the resolved namespaceUri() and the attributes local name.
|
read |
Returns the text of Characters, Comment, DTD, or EntityReference.
|
read |
Returns the reader's current token as string.
|
read |
Returns the type of the current token.