#include <nanoxml.h>
Public Member Functions | |
NanoXml (const QString &path) | |
Constructor. | |
NanoXml (QIODevice *ioDevice) | |
~NanoXml () | |
Destructor. | |
const QString | namespaceUri () |
Returns the namespace URI of the parsed (source) XML document. | |
bool | didFail () |
Returns true if parsing failed. | |
bool | startElement (const QString &, const QString &, const QString &name, const QXmlAttributes &attrs) |
Called by the XML parser when parsing starts. | |
bool | endElement (const QString &, const QString &, const QString &name) |
Called by the XML parser when parsing starts. | |
bool | startPrefixMapping (const QString &prefix, const QString &uri) |
Called when a namespace prefix mapping starts. | |
bool | characters (const QString &chars) |
Called by the XML parser when parsing starts. | |
AssocTree | result () |
Private Member Functions | |
void | pushList () |
Parser internal. Creates a new list and pushes it to the top of the stack. | |
void | addValue (const QString &v) |
Parser internal. Add a value (item) v to the current list on the stack. | |
void | popList () |
Parser internal. | |
void | initAndParse (QIODevice *ioDevice) |
Private Attributes | |
QVariant | rootVariant |
The root variant. Created at the end of parsing. | |
QList< QVariant > * | current |
The current list that we're adding to. Top of the stack, kinda. | |
QStack< QList< QVariant > * > | stack |
The stack of lists. | |
bool | failed |
This is set by the parser to signify an error. | |
QString | nspace |
Stores the namespace uri. |
This class is not exported in the public API. It's used to parse a formatted XML into a nanodom tree. To learn about the nano dom please read the documentation on the desktop types.
Short overview - the following XML is being turned into the following tree structure:
<key name="Example.Random" type="string"> <doc>A random property.</doc> </key> ['key', ['name', 'Example.Random' ], ['type', 'string' ], ['doc', 'A random property.'] ]
Another example:
<key name="Example.Random"> <type> <list type="number"/> </type> </key> ['key', ['name', 'Example.Random' ], ['type', ['list', ['type', 'number' ] ] ] ]
NanoXml::NanoXml | ( | const QString & | path | ) |
Constructor.
Creates a new nanodom tree reading XML data from path. After creating the object you should check the didFail to see if parsing succeded.
NanoXml::NanoXml | ( | QIODevice * | ioDevice | ) |
NanoXml::~NanoXml | ( | ) |
Destructor.
const QString NanoXml::namespaceUri | ( | ) |
Returns the namespace URI of the parsed (source) XML document.
Empty if it wasn't specified.
bool NanoXml::didFail | ( | ) |
Returns true if parsing failed.
Fals otherwise. Use it to check if the nanodom tree is fine and usable.
void NanoXml::pushList | ( | ) | [private] |
Parser internal. Creates a new list and pushes it to the top of the stack.
void NanoXml::addValue | ( | const QString & | v | ) | [private] |
Parser internal. Add a value (item) v to the current list on the stack.
void NanoXml::popList | ( | ) | [private] |
Parser internal.
Pops one list from the stack. Closes the list and attaches it to the previoius list on the stack.
void NanoXml::initAndParse | ( | QIODevice * | ioDevice | ) | [private] |
bool NanoXml::startElement | ( | const QString & | , | |
const QString & | , | |||
const QString & | name, | |||
const QXmlAttributes & | attrs | |||
) |
Called by the XML parser when parsing starts.
bool NanoXml::endElement | ( | const QString & | , | |
const QString & | , | |||
const QString & | name | |||
) |
Called by the XML parser when parsing starts.
bool NanoXml::startPrefixMapping | ( | const QString & | prefix, | |
const QString & | uri | |||
) |
Called when a namespace prefix mapping starts.
We use this to get the xml version.
bool NanoXml::characters | ( | const QString & | chars | ) |
Called by the XML parser when parsing starts.
AssocTree NanoXml::result | ( | ) |
QVariant NanoXml::rootVariant [private] |
The root variant. Created at the end of parsing.
QList<QVariant>* NanoXml::current [private] |
The current list that we're adding to. Top of the stack, kinda.
QStack<QList <QVariant>* > NanoXml::stack [private] |
The stack of lists.
bool NanoXml::failed [private] |
This is set by the parser to signify an error.
QString NanoXml::nspace [private] |
Stores the namespace uri.