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. Impossible to read an xml file

Impossible to read an xml file

Scheduled Pinned Locked Moved Solved QML and Qt Quick
10 Posts 3 Posters 2.6k 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.
  • M Offline
    M Offline
    modjo756
    wrote on last edited by
    #1

    Hi all, like said in the title i have a problem to read this file (zwave configuration file) see under the code that i use :

    Rectangle {
        width: 400; height: 260
        color: "#404040"
        XmlListModel {
            id: xmlModel
            source: Qt.resolvedUrl("https://raw.githubusercontent.com/OpenZWave/open-zwave/master/config/fibaro/fgrm222.xml"
            query: "/Product"
    
            XmlRole { name: "title"; query: "@xmlns/string()" }
            Component.onCompleted: {
                    console.log(source.toString())
             }
        }
    
        ListView {
            anchors.fill: parent
            anchors.margins: 4
            model: xmlModel
            delegate: Text {
                text: model.title
                color:"white"
                font.pixelSize: 32
            }
        }
    }
    

    This code work fine with another xml file (like network.xml in qt installation) but not with it (try also locally). Do you have an idea how i can resolve this ?

    1 Reply Last reply
    0
    • dheerendraD Offline
      dheerendraD Offline
      dheerendra
      Qt Champions 2022
      wrote on last edited by
      #2

      Try changing your query to "xmlns/string()"

      Dheerendra
      @Community Service
      Certified Qt Specialist
      http://www.pthinks.com

      1 Reply Last reply
      6
      • M Offline
        M Offline
        modjo756
        wrote on last edited by
        #3

        Thanks but don't work better !

        1 Reply Last reply
        0
        • M Offline
          M Offline
          modjo756
          wrote on last edited by
          #4

          just a little up !

          mrjjM 1 Reply Last reply
          0
          • M modjo756

            just a little up !

            mrjjM Offline
            mrjjM Offline
            mrjj
            Lifetime Qt Champion
            wrote on last edited by
            #5

            @modjo756

            Well the xml is surely valid

            alt text

            M 1 Reply Last reply
            0
            • mrjjM mrjj

              @modjo756

              Well the xml is surely valid

              alt text

              M Offline
              M Offline
              modjo756
              wrote on last edited by
              #6

              @mrjj
              Thanks but why Qt can't read it ?

              mrjjM 1 Reply Last reply
              0
              • M modjo756

                @mrjj
                Thanks but why Qt can't read it ?

                mrjjM Offline
                mrjjM Offline
                mrjj
                Lifetime Qt Champion
                wrote on last edited by
                #7

                @modjo756
                well if you compare with an xml that works, with the
                XmlRole { name: "title"; query: "@xmlns/string()" }
                and the structure , you have in this file.

                What is then the difference ?

                M 1 Reply Last reply
                0
                • mrjjM mrjj

                  @modjo756
                  well if you compare with an xml that works, with the
                  XmlRole { name: "title"; query: "@xmlns/string()" }
                  and the structure , you have in this file.

                  What is then the difference ?

                  M Offline
                  M Offline
                  modjo756
                  wrote on last edited by
                  #8

                  @mrjj
                  The problem is that i can't get the value of the xml file. For example, i just want to get the first (for test) item Product. In the file this give :

                  <?xml version="1.0" encoding="utf-8"?>
                  <Product xmlns='http://code.google.com/p/open-zwave/'>

                  In my code i want to get the value of xmlns, i proceed like this :

                          query: "/Product"
                          XmlRole { name: "title"; query: "@xmlns/string()" }
                  

                  But this don't give me the result ... and i don't know why !

                  1 Reply Last reply
                  0
                  • M Offline
                    M Offline
                    modjo756
                    wrote on last edited by modjo756
                    #9

                    Hi, with a help of my Qt instructor it seems there is a problem with the attribute xmlns in this files. If i replace this one by link (in the xml file) for example it works ! Now i can access to all data in the file ! Perhaps it's necessary to register xmlns with registerMetaType or other ... If someone have an idea ?

                    1 Reply Last reply
                    1
                    • M Offline
                      M Offline
                      modjo756
                      wrote on last edited by
                      #10

                      I known this is an old topic but it can help some people. I have find a solution to read this file. For that just use the namespaceDeclarations property like this :

                      namespaceDeclarations:"declare default element namespace 'http://code.google.com/p/open-zwave/';"
                      

                      Now i can parse the file !

                      1 Reply Last reply
                      1

                      • Login

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