Need enlightenment with XmlListModel



  • Hello everyone,

    I hope this is the right place to ask for help in the following matter, if not just point me in the right direction.
    I'm trying to use XmlListModel with a xml file I got from a server. I think the problem may be with namespace declarations but I have tried many combinations without success. To be sure I could use this qml type, I tried this with another xml file - https://www.w3schools.com/xml/books.xml - all went good!

    Here's a portion of the "problematic" xml file:

    <?xml version="1.0"?>
    <s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/" xmlns:u="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">
    	<s:Header>
    		<o:Security xmlns:o="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd" s:mustUnderstand="1">
    			<u:Timestamp u:Id="_0">
    				<u:Created>2018-02-07T20:04:36.232Z</u:Created>
    				<u:Expires>2018-02-07T20:09:36.232Z</u:Expires>
    			</u:Timestamp>
    		</o:Security>
    	</s:Header>
    	<s:Body xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
    		<RecebeResponse xmlns="http://www.precoscombustiveis.dgge.pt/PCOM/Recebe">
    			<RecebeResult>
    				<Pedido xmlns="" id="1" data="2018-02-07" hora="20:03">
    					<Actualizacoes>
    						<Actualizacao id="8479" data="2018-02-05" hora="00:36">
    							<Postos>
    								<Existentes>
    									<Posto id="67270">
    										<Nome> BP Xabregas</Nome>
    										<Marca>BP</Marca>
    										<Utilizacao>P&#xFA;blica</Utilizacao>
    										<TipoPosto>Outro</TipoPosto>
    										<Municipio>Lisboa</Municipio>
    										<Localidade>Lisboa - Xabregas</Localidade>
    										<Morada>Av. Infante D.Henrique, 61</Morada>
    										<CodPostal1>1900</CodPostal1>
    										<CodPostal2>439</CodPostal2>
    										<CodPostalLocalidade>Lisboa</CodPostalLocalidade>
    										<Sentido>Descendente</Sentido>
    										<Latitude>38.72526</Latitude>
    										<Longitude>-9.11153</Longitude>
    										<HorarioDiasUteis>Hor&#xE1;rio espec&#xED;fico</HorarioDiasUteis>
    										<HoraAberturaDiasUteis>07:00</HoraAberturaDiasUteis>
    										<HoraFechoDiasUteis>23:00</HoraFechoDiasUteis>
    										<HorarioSabados>Hor&#xE1;rio espec&#xED;fico</HorarioSabados>
    										<HoraAberturaSabados>07:00</HoraAberturaSabados>
    										<HoraFechoSabados>23:00</HoraFechoSabados>
    										<HorarioDomFeriados>Hor&#xE1;rio espec&#xED;fico</HorarioDomFeriados>
    										<HoraAberturaDomFeriados>07:00</HoraAberturaDomFeriados>
    										<HoraFechoDomFeriados>23:00</HoraFechoDomFeriados>
    										<Descontos/>
    										<Observacoes>Pagamentos com cart&#xE3;o Routex&#xD;
    Desconto aos portadores de cart&#xE3;o Azul BP&#xD;
    Desconto aos portadores de cart&#xE3;o ACP&#xD;
    Desconto aos portadores de cart&#xE3;o INATEL&#xD;
    Desconto aos portadores de cart&#xE3;o Poupa Mais&#xD;
    Desconto aos portadores de cart&#xF5;es BP/Acordos</Observacoes>
    										<Servicos>
    											<Servico>Venda de carburante de qualidade superior</Servico>
    											<Servico>Venda de g&#xE1;s dom&#xE9;stico em garrafas</Servico>
    											<Servico>WC</Servico>
    											<Servico>Calibragem de pneus</Servico>
    											<Servico>Loja de Conveni&#xEA;ncia</Servico>
    										</Servicos>
    									</Posto>
    

    Here's my qml code:

    import QtQuick 2.9
    import QtQuick.Window 2.2
    import QtQuick.XmlListModel 2.0
    
    Window {
        visible: true
        width: 640
        height: 480
        title: qsTr("Hello World")
    
        XmlListModel {
            id: xmlModel
    		source: "qrc:/xml/dataFULL.xml"
            query: "/Envelope/Body/RecebeResponse/RecebeResult/Pedido/Actualizacoes/Actualizacao/Postos/Existentes/Posto"
    
    
            namespaceDeclarations: "declare default element namespace 'http://schemas.xmlsoap.org/soap/envelope/';"+
                                   "declare namespace u='http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd';"+
                                   "declare namespace o='http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd';"+
                                   "declare namespace xsi='http://www.w3.org/2001/XMLSchema-instance';"+
                                   "declare namespace xsd='http://www.w3.org/2001/XMLSchema';"
    
    
            XmlRole { name: "Nome"; query: "Nome/string()"}
    
        }
    
        ListView{
            id: list
            width: 300; height: 300
            model: xmlModel
            delegate: Text { text: Nome }
        }
    }
    

    With this code the "Text" in the ListView doesn't show anything.
    I'm think this model have some error but I don't know how to retrieve the error to fix it.

    Hope someone can give me a hand figuring this out!



  • ... Since I couldn't use xmllistmodel I changed my approach.
    Created a class derived from QAbstractItemModel and applied this model to QML.
    Don't know if this is the best way but for now it works.


Log in to reply
 

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