ubuntu-phone team mailing list archive
-
ubuntu-phone team
-
Mailing list archive
-
Message #12281
Re: Multiple nested levels in a QML XmlListModel
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.
Attachment:
signature.asc
Description: This is a digitally signed message part
Follow ups
References