×

Discussion Board

Results 1 to 5 of 5
  1. #1
    Registered User
    Join Date
    Sep 2011
    Posts
    5

    Question Parsing complex XML Tags with QML

    I wanna parse RSS feed with QML.

    the feed structure looks like

    Code:
    <channel>
        <item>
        <title>
        </title>
        <description>
        </description>
        <media:content url="http://someURLHere.com/avatar/somethingHere?s=96&#38;d=identicon&#38;r=G" medium="image">
        </media:content>
        </item>
    my problem is with the <media:content> tag, how can i parse the url with QML into a string ?

  2. #2
    Super Contributor
    Join Date
    Mar 2009
    Posts
    1,024

    Re: Parsing complex XML Tags with QML

    Hi,
    You can use JS to parse XML.
    Here is an example which show you how to get tag attributes;

    <fruits>
    <fruit name="Apple" colour="Green" />
    <fruit name="Banana" colour="Yellow" />
    </fruits>
    JavaScript:

    function getFruits(xml) {
    var fruits = xml.getElementsByTagName("fruits")[0];
    if (fruits) {
    var fruitsNodes = fruits.childNodes;
    if (fruitsNodes) {
    for (var i = 0; i < fruitsNodes.length; i++) {
    var name = fruitsNodes[i].getAttribute("name");
    var colour = fruitsNodes[i].getAttribute("colour");
    alert("Fruit " + name + " is coloured " + colour);
    }
    }
    }
    }

  3. #3
    Registered User
    Join Date
    Sep 2011
    Posts
    5

    Re: Parsing complex XML Tags with QML

    what is meant by xml in getFruits(xml) ?
    is it the feed url ?

  4. #4
    Super Contributor
    Join Date
    Mar 2009
    Posts
    1,024

    Re: Parsing complex XML Tags with QML

    xml is a string

  5. #5
    Registered User
    Join Date
    Sep 2011
    Posts
    5

    Re: Parsing complex XML Tags with QML

    Thanks gnuton.

    I figured another solution with QML without need for Javascript
    we just declare media namespace

    for example the code will look like

    Code:
     
    XmlListModel {
    namespaceDeclarations: "declare namespace media = 'http://search.yahoo.com/mrss/'; declare 
    namespace default = 'http://rss.news.yahoo.com/rss/world';"
    .
    .
    .
    .
    XmlRole { name: "img"; query: "media:content/@url/string()" }
    }
    I hope this is helpful for anyone who needs it later

Similar Threads

  1. XML parsing of string with user defined tags
    By dilipsinh in forum Symbian
    Replies: 4
    Last Post: 2011-07-04, 16:14
  2. Am I making it too complex?
    By Matoking in forum Qt
    Replies: 2
    Last Post: 2010-10-13, 04:46
  3. Parsing DocBook for named tags - Output XML
    By Noeff2002 in forum [Archived] Flash Lite on Nokia Devices
    Replies: 2
    Last Post: 2010-01-02, 09:38
  4. complex error
    By mohamed gamal in forum Open C/C++
    Replies: 0
    Last Post: 2009-12-08, 19:59
  5. Complex Forms
    By xcash in forum Symbian
    Replies: 1
    Last Post: 2005-07-05, 12:12

Posting Permissions

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