Results 1 to 2 of 2

Thread: Need enlightenment working with xmllistmodel

  1. #1
    Join Date
    Feb 2018
    Posts
    2
    Qt products
    Qt5
    Platforms
    MacOS X

    Default Need enlightenment working 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. Just to be sure I also tested with another and more simple xml file - https://www.w3schools.com/xml/books.xml - and all went fine.

    A portion of the "problematic" XML file:
    Qt Code:
    1. <?xml version="1.0"?>
    2. <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">
    3. <s:Header>
    4. <o:Security xmlns:o="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd" s:mustUnderstand="1">
    5. <u:Timestamp u:Id="_0">
    6. <u:Created>2018-02-07T20:04:36.232Z</u:Created>
    7. <u:Expires>2018-02-07T20:09:36.232Z</u:Expires>
    8. </u:Timestamp>
    9. </o:Security>
    10. </s:Header>
    11. <s:Body xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
    12. <RecebeResponse xmlns="http://www.precoscombustiveis.dgge.pt/PCOM/Recebe">
    13. <RecebeResult>
    14. <Pedido xmlns="" id="1" data="2018-02-07" hora="20:03">
    15. <Actualizacoes>
    16. <Actualizacao id="8479" data="2018-02-05" hora="00:36">
    17. <Postos>
    18. <Existentes>
    19. <Posto id="67270">
    20. <Nome> BP Xabregas</Nome>
    21. <Marca>BP</Marca>
    22. <Utilizacao>P&#xFA;blica</Utilizacao>
    23. <TipoPosto>Outro</TipoPosto>
    24. <Municipio>Lisboa</Municipio>
    25. <Localidade>Lisboa - Xabregas</Localidade>
    26. <Morada>Av. Infante D.Henrique, 61</Morada>
    27. <CodPostal1>1900</CodPostal1>
    28. <CodPostal2>439</CodPostal2>
    29. <CodPostalLocalidade>Lisboa</CodPostalLocalidade>
    30. <Sentido>Descendente</Sentido>
    31. <Latitude>38.72526</Latitude>
    32. <Longitude>-9.11153</Longitude>
    33. <HorarioDiasUteis>Hor&#xE1;rio espec&#xED;fico</HorarioDiasUteis>
    34. <HoraAberturaDiasUteis>07:00</HoraAberturaDiasUteis>
    35. <HoraFechoDiasUteis>23:00</HoraFechoDiasUteis>
    36. <HorarioSabados>Hor&#xE1;rio espec&#xED;fico</HorarioSabados>
    37. <HoraAberturaSabados>07:00</HoraAberturaSabados>
    38. <HoraFechoSabados>23:00</HoraFechoSabados>
    39. <HorarioDomFeriados>Hor&#xE1;rio espec&#xED;fico</HorarioDomFeriados>
    40. <HoraAberturaDomFeriados>07:00</HoraAberturaDomFeriados>
    41. <HoraFechoDomFeriados>23:00</HoraFechoDomFeriados>
    42. <Descontos/>
    43. <Observacoes>Pagamentos com cart&#xE3;o Routex&#xD;
    44. Desconto aos portadores de cart&#xE3;o Azul BP&#xD;
    45. Desconto aos portadores de cart&#xE3;o ACP&#xD;
    46. Desconto aos portadores de cart&#xE3;o INATEL&#xD;
    47. Desconto aos portadores de cart&#xE3;o Poupa Mais&#xD;
    48. Desconto aos portadores de cart&#xF5;es BP/Acordos</Observacoes>
    49. <Servicos>
    50. <Servico>Venda de carburante de qualidade superior</Servico>
    51. <Servico>Venda de g&#xE1;s dom&#xE9;stico em garrafas</Servico>
    52. <Servico>WC</Servico>
    53. <Servico>Calibragem de pneus</Servico>
    54. <Servico>Loja de Conveni&#xEA;ncia</Servico>
    55. </Servicos>
    56. </Posto>
    To copy to clipboard, switch view to plain text mode 

    My QML code:
    Qt Code:
    1. import QtQuick 2.9
    2. import QtQuick.Window 2.2
    3. import QtQuick.XmlListModel 2.0
    4.  
    5. Window {
    6. visible: true
    7. width: 640
    8. height: 480
    9. title: qsTr("Hello World")
    10.  
    11. XmlListModel {
    12. id: xmlModel
    13. source: "qrc:/xml/dataFULL.xml"
    14. query: "/Envelope/Body/RecebeResponse/RecebeResult/Pedido/Actualizacoes/Actualizacao/Postos/Existentes/Posto"
    15.  
    16.  
    17. namespaceDeclarations: "declare default element namespace 'http://schemas.xmlsoap.org/soap/envelope/';"+
    18. "declare namespace u='http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd';"+
    19. "declare namespace o='http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd';"+
    20. "declare namespace xsi='http://www.w3.org/2001/XMLSchema-instance';"+
    21. "declare namespace xsd='http://www.w3.org/2001/XMLSchema';"
    22.  
    23.  
    24. XmlRole { name: "Nome"; query: "Nome/string()"}
    25.  
    26. }
    27.  
    28. ListView{
    29. id: list
    30. width: 300; height: 300
    31. model: xmlModel
    32. delegate: Text { text: Nome }
    33. }
    34. }
    To copy to clipboard, switch view to plain text mode 

    Hope someone can give me a hand figuring this out!

  2. #2
    Join Date
    Feb 2018
    Posts
    2
    Qt products
    Qt5
    Platforms
    MacOS X

    Default Re: Need enlightenment working with xmllistmodel

    ... Since I couldn't use xmllistmodel I have changed my approach.
    Created a class derived from QAbstractItemModel applied this model to QML.

    For now it works.

Similar Threads

  1. Error reading local XML file with XmlListModel
    By KeineAhnung in forum Newbie
    Replies: 4
    Last Post: 9th March 2016, 20:55
  2. XmlListModel
    By mymissing in forum Qt Quick
    Replies: 1
    Last Post: 2nd September 2013, 23:40
  3. qml PathView XmlListModel
    By waiter in forum Qt Quick
    Replies: 14
    Last Post: 15th January 2013, 02:18
  4. Replies: 7
    Last Post: 24th September 2012, 08:17
  5. problem using XmlListModel query to parsing rss xml
    By xiazhouquan in forum Qt Quick
    Replies: 1
    Last Post: 19th June 2011, 10:22

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.