Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. [solved] XmlListModel parse local xml file
Forum Updated to NodeBB v4.3 + New Features

[solved] XmlListModel parse local xml file

Scheduled Pinned Locked Moved QML and Qt Quick
6 Posts 3 Posters 6.4k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • L Offline
    L Offline
    Landy
    wrote on last edited by
    #1

    @ XmlListModel {
    id: xmlModel
    source:"local.xml"

        query: "/feed/entry"
    
        namespaceDeclarations: "declare default element namespace 'http://www.w3.org/2005/Atom';"
        XmlRole { name: "title"; query: "content/string()"}
    }
    
    Component {
        id: xmlModelDelegate
    
        Text {
            width: 350
            text: title
            wrapMode:Text.Wrap
        }
    }
    
    ListView {
        id:parseHtmlListview
        width: parent.width
        height: parent.height - 40
    
        clip: true
        model: xmlModel
        delegate: xmlModelDelegate
    }
    

    //local.xml such as follow

    <feed>
    <entry>
    <content type="html">
    <div id="Intro"><p>Hello World.</p> ></div>
    </content>
    </entry>
    </feed>
    @

    hi, when i use XmlListModel parse loacl xml file, i can't get data, please help me, thanks~~~

    1 Reply Last reply
    0
    • D Offline
      D Offline
      Diph
      wrote on last edited by
      #2

      I guess you have correct namespace in xml (code-tags seems to remove the namespace...)

      If you want hello world text:

      @XmlListModel {
      ...
      XmlRole { name: "title"; query: "content/div/p/string()"}
      }@

      1 Reply Last reply
      0
      • L Offline
        L Offline
        Landy
        wrote on last edited by
        #3

        Hi Diph,

        Thanks for your reply.
        I am sorry i did't describe the problem exactly.
        I can phase the xml file when it is in server.
        But after i downloaded it from server to my computer, I can't phase it from local.
        As the same file content, I don't know why it doesn't work.
        Do u have any idea about this?

        [quote author="Diph" date="1313584756"]I guess you have correct namespace in xml (code-tags seems to remove the namespace...)

        If you want hello world text:

        @XmlListModel {
        ...
        XmlRole { name: "title"; query: "content/div/p/string()"}
        }@[/quote]

        1 Reply Last reply
        0
        • D Offline
          D Offline
          DenisKormalev
          wrote on last edited by
          #4

          Maybe it is located in another place? Not where qml looks for it?

          1 Reply Last reply
          0
          • D Offline
            D Offline
            Diph
            wrote on last edited by
            #5

            Maybe you can set your own QNetworkAccessManager which uses cache? http://doc.qt.nokia.com/latest/qdeclarativenetwork.html#configuring-the-network-access-manager

            1 Reply Last reply
            0
            • L Offline
              L Offline
              Landy
              wrote on last edited by
              #6

              the problem have been resolved.
              encoding caused the problem.
              the file must be unicode format.
              thanks for all your reply.

              1 Reply Last reply
              0

              • Login

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • Users
              • Groups
              • Search
              • Get Qt Extensions
              • Unsolved