Impossible to read an xml file



  • 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 ?



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



  • Thanks but don't work better !



  • just a little up !


  • Qt Champions 2016

    @modjo756

    Well the xml is surely valid

    alt text



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


  • Qt Champions 2016

    @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 ?



  • @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 !



  • 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 ?



  • 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 !


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.