← Back to team overview

ubuntu-phone team mailing list archive

Re: Multiple nested levels in a QML XmlListModel

 

There's also the parsing mechanism of XmlHttpRequest. That's probably more reliable than any self-written parser. ;)

Am Mo, 20. Apr, 2015 um 5:37 schrieb Sam Bull <sam.hacking@xxxxxxxx>:
On sab, 2015-04-18 at 15:20 +0200, Simon wrote:
 Is it really *that* hard to parse a multilevel XML file in QML? Feel
 like a complete idiot.

Complex XML is impossible to parse using the XmlListModel, as I found
out when creating my dictionary app. If you're finding your XML is too
complex, then there are 2 other ways I tried, which worked to varying
degrees for me.

The first way is to write Javascript functions that parse the XML
object. You can have a look at my code for how to do this:

        This is the code used to load the XML file.
http://bazaar.launchpad.net/~dreamsorcerer/eo-dict-app/trunk/view/18/qml/ResultsPage.qml#L17

        This is the function that parses the top level tag and creates
        components to represent it's child tags.
http://bazaar.launchpad.net/~dreamsorcerer/eo-dict-app/trunk/view/18/qml/ResultsPage.qml#L39

        The first element it creates is this file, which does much the
        same thing of parsing it's child nodes.
http://bazaar.launchpad.net/~dreamsorcerer/eo-dict-app/trunk/view/18/qml/XmlArt.qml



Due to the size of the XML files, this ended up being too slow and
complex, so my new method is using XSLT. I have a Python script which
transforms all the XML files into generated QML files, so my app now
simply loads a QML file and doesn't deal with the XML at all. Obviously,
this is only useful if you don't need to process varying XML files in
your app, I am able to bake the files like this as I don't allow
downloading of updated data in the app.


If either of these techniques is better for you, feel free to look
through the code or ask me any questions. The Javascript method is in
revisions 18-41, later revisions move to the XSLT technique.

Follow ups

References