×

Discussion Board

Results 1 to 2 of 2
  1. #1
    Registered User
    Join Date
    Jul 2011
    Posts
    4

    XMLListModel - get element attribute AND childnodes into a scrollable list?

    Hi,

    Is it possible to get both an element attribut and the elements childnodes? What I want to accomplish is an scrollable list of elements having the element attribute as title and below that all children content.



    If for example the xml was something like this:

    Code:
    <?xml version="1.0"?>
    <authors>
    <author name"Mickey Mouse">
    <book>
    <pubdate>1994</pubdate>
    <pageCount>45</pageCount>
    </book>
    </author>
    <author name"Donald Duck">
    <book>
    <pubdate>1957</pubdate>
    <pageCount>87</pageCount>
    </book>
    <book>
    <pubdate>1963</pubdate>
    <pageCount>12</pageCount>
    </book>
    </author>
    </authors>
    In other words, the xml could contain many authors and every author could have many books.
    I'd like to get this into an XMLListModel.
    I tried to query all authors, and i get a list of them, but how can I get another list for evey author to display variable count of books?
    It seems it is not possible to put an XMLListModel into another.
    I also tryd to query all books instead and then to get the author by using xpath for parent node in the xmlrole. It seemed to me that XMLListModel does not support xpath for getting parents, or then i just didnt write proper xpath.


    Edit:
    The xml I wrote was just an example and has some errors. I completed my example and the xml seems to work fine for the attribute, but the problem to get all books into the XMLListModel still remains:
    Code:
    <?xml version="1.0"?>
    <authors>
    	<author name="Mickey Mouse">
    		<book>
    			<pubdate>1994</pubdate>
    			<pageCount>45</pageCount>
    		</book>
    		<book>
    			<pubdate>1991</pubdate>
    			<pageCount>32</pageCount>
    		</book>
    	</author>
    	<author name="Donald Duck">
    		<book>
    			<pubdate>1957</pubdate>
    			<pageCount>87</pageCount>
    		</book>
    		<book>
    			<pubdate>1963</pubdate>
    			<pageCount>12</pageCount>
    		</book>
    	</author>
    </authors>
    The qml I've used in the example looks like this:
    Code:
    import QtQuick 1.0
    
    Rectangle {
        id: window
        width: 640
        height: 360
    
        XmlListModel {
            id: authors
            //xml: "/authors.xml" Couldn't get local file to work at all..
            source: "http://myserver.com/authors.xml"
            query: "/authors/author"
    
            XmlRole { name: "author"; query: "@name/string()" }
        }
    
        ListView {
            id: authorsList
            anchors.fill: parent
            model: authors
            delegate: Text {
                text: "Author name: " + author;
            }
        }
    }
    I get the the author name properly, but is it possible to display the authors books below the authors somehow?


    Best Regards,

    Sebastian
    Last edited by SBockelman; 2011-07-30 at 13:31.

  2. #2
    Registered User
    Join Date
    Jul 2011
    Posts
    4

    Re: XMLListModel - get element attribute AND childnodes into a scrollable list?

    This post was added to the original.
    Last edited by SBockelman; 2011-07-30 at 13:32.

Similar Threads

  1. XmlListModel and setRawHeader
    By atonical in forum [Archived] Qt Quick
    Replies: 1
    Last Post: 2011-07-14, 07:04
  2. element attribute setting not work with N97
    By web_tur in forum Symbian
    Replies: 2
    Last Post: 2010-07-08, 17:54
  3. Replies: 4
    Last Post: 2006-09-05, 15:15
  4. horizontal scrollable multicolumn list
    By hariprasadth in forum Symbian User Interface
    Replies: 0
    Last Post: 2005-11-10, 07:10
  5. Always a Scrollable List
    By gfree0300 in forum Mobile Java General
    Replies: 1
    Last Post: 2003-12-12, 20:16

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
×