Reading and using PHP generated XML in Qt
Hello I'm building an Qt application which, amongst other things displays products of a store. The products are stored in a MySQL database, which is queried by php functions. The PHP function returns an XML of the contents of table. So, I've been looking for a while, but I can't find an elegant soulution for my problem. What I need is: 1. get the XML from the function (domain.com/blah.php) 2. get data from the XML So, is it possible for me to use XML data as if i'm working with objects. Example of the data is:
<categories>
<category>
<ID>1</ID>
<Category_name>Hrana i pica</Category_name>
<Parent_ID>0</Parent_ID>
</category>
<category>
<ID>2</ID>
<Category_name>Kucne potrepstine</Category_name>
<Parent_ID>0</Parent_ID>
</category>
<category>
<ID>3</ID>
<Category_name>Ljepota i njega</Category_name>
<Parent_ID>0</Parent_ID>
</category>
<category>
<ID>4</ID>
<Category_name>Djecji svijet</Category_name>
<Parent_ID>0</Parent_ID>
</category>
<category>
<ID>5</ID>
<Category_name>Cvijece</Category_name>
<Parent_ID>0</Parent_ID>
</category>
<category>
<ID>6</ID>
<Category_name>Akcijska prodaja</Category_name>
<Parent_ID>0</Parent_ID>
</category>
<category>
<ID>7</ID>
<Category_name>Alkoholna pica</Category_name>
<Parent_ID>1</Parent_ID>
</category>
<category>
<ID>8</ID>
<Category_name>Bezalkoholna 开发者_运维技巧pica</Category_name>
<Parent_ID>1</Parent_ID>
</category>
<category>
<ID>9</ID>
<Category_name>Delikatesa specijal</Category_name>
<Parent_ID>1</Parent_ID>
</category>
<category>
<ID>10</ID>
<Category_name>Delikatese / mesne preradevine</Category_name>
<Parent_ID>1</Parent_ID>
</category>
<category>
<ID>11</ID>
<Category_name>Dijabetski i zdrava hrana</Category_name>
<Parent_ID>1</Parent_ID>
</category>
<category>
<ID>12</ID>
<Category_name>Dorucak</Category_name>
<Parent_ID>1</Parent_ID>
</category>
<category>
<ID>13</ID>
<Category_name>Mlijecni, jaja i sir</Category_name>
<Parent_ID>1</Parent_ID>
</category>
<category>
<ID>14</ID>
<Category_name>Namirnice za pripremu jela</Category_name>
<Parent_ID>1</Parent_ID>
</category>
<category>
<ID>15</ID>
<Category_name>Pekarski proizvodi</Category_name>
<Parent_ID>1</Parent_ID>
</category>
<category>
<ID>16</ID>
<Category_name>Slatkisi i grickalice</Category_name>
<Parent_ID>1</Parent_ID>
</category>
<category>
<ID>17</ID>
<Category_name>Smrznuto</Category_name>
<Parent_ID>1</Parent_ID>
</category>
<category>
<ID>18</ID>
<Category_name>Svjeza riba</Category_name>
<Parent_ID>1</Parent_ID>
</category>
<category>
<ID>19</ID>
<Category_name>Svjeze meso</Category_name>
<Parent_ID>1</Parent_ID>
</category>
<category>
<ID>20</ID>
<Category_name>Svjeze voce i povrce</Category_name>
<Parent_ID>1</Parent_ID>
</category>
<category>
<ID>21</ID>
<Category_name>Ukiseljena i konzerv. hrana</Category_name>
<Parent_ID>1</Parent_ID>
</category>
<category>
<ID>22</ID>
<Category_name>Elektro pribor i medija</Category_name>
<Parent_ID>2</Parent_ID>
</category>
<category>
<ID>23</ID>
<Category_name>Higijenski i papirnati proizvodi</Category_name>
<Parent_ID>2</Parent_ID>
</category>
<category>
<ID>24</ID>
<Category_name>Kiosk</Category_name>
<Parent_ID>2</Parent_ID>
</category>
<category>
<ID>25</ID>
<Category_name>Knjige za odrasle</Category_name>
<Parent_ID>2</Parent_ID>
</category>
<category>
<ID>26</ID>
<Category_name>Kucanske potrepstine</Category_name>
<Parent_ID>2</Parent_ID>
</category>
<category>
<ID>27</ID>
<Category_name>Kucni ljubimci</Category_name>
<Parent_ID>2</Parent_ID>
</category>
<category>
<ID>28</ID>
<Category_name>Party program</Category_name>
<Parent_ID>2</Parent_ID>
</category>
<category>
<ID>29</ID>
<Category_name>Posudje i oprema za dom</Category_name>
<Parent_ID>2</Parent_ID>
</category>
<category>
<ID>30</ID>
<Category_name>Sezonski asortiman</Category_name>
<Parent_ID>2</Parent_ID>
</category>
<category>
<ID>31</ID>
<Category_name>Sportska odjeca i oprema</Category_name>
<Parent_ID>2</Parent_ID>
</category>
<category>
<ID>32</ID>
<Category_name>Sredstva za pranje i ciscenje</Category_name>
<Parent_ID>2</Parent_ID>
</category>
<category>
<ID>33</ID>
<Category_name>Skolski i uredski asortiman</Category_name>
<Parent_ID>2</Parent_ID>
</category>
<category>
<ID>34</ID>
<Category_name>Tekstil i obuca</Category_name>
<Parent_ID>2</Parent_ID>
</category>
<category>
<ID>35</ID>
<Category_name>Ukrasi i prigodni program</Category_name>
<Parent_ID>2</Parent_ID>
</category>
<category>
<ID>36</ID>
<Category_name>Uradi sam</Category_name>
<Parent_ID>2</Parent_ID>
</category>
<category>
<ID>37</ID>
<Category_name>Vrt i kamp</Category_name>
<Parent_ID>2</Parent_ID>
</category>
<category>
<ID>38</ID>
<Category_name>Dekorativna kozmetika i parfemi</Category_name>
<Parent_ID>3</Parent_ID>
</category>
<category>
<ID>39</ID>
<Category_name>Muska kozmetika</Category_name>
<Parent_ID>3</Parent_ID>
</category>
<category>
<ID>40</ID>
<Category_name>Njega kose</Category_name>
<Parent_ID>3</Parent_ID>
</category>
<category>
<ID>41</ID>
<Category_name>Njega lica za zene</Category_name>
<Parent_ID>3</Parent_ID>
</category>
<category>
<ID>42</ID>
<Category_name>Njega tijela</Category_name>
<Parent_ID>3</Parent_ID>
</category>
<category>
<ID>43</ID>
<Category_name>Njega zubi</Category_name>
<Parent_ID>3</Parent_ID>
</category>
<category>
<ID>44</ID>
<Category_name>Djecja galanterija</Category_name>
<Parent_ID>4</Parent_ID>
</category>
<category>
<ID>45</ID>
<Category_name>Djecja hrana</Category_name>
<Parent_ID>4</Parent_ID>
</category>
<category>
<ID>46</ID>
<Category_name>Djecja kozmetika i higijena</Category_name>
<Parent_ID>4</Parent_ID>
</category>
<category>
<ID>47</ID>
<Category_name>Djecji svijet - ostalo</Category_name>
<Parent_ID>4</Parent_ID>
</category>
<category>
<ID>48</ID>
<Category_name>Igracke</Category_name>
<Parent_ID>4</Parent_ID>
</category>
<category>
<ID>49</ID>
<Category_name>Knjige za djecu</Category_name>
<Parent_ID>4</Parent_ID>
</category>
<category>
<ID>50</ID>
<Category_name>Tekstil odjevni za bebe</Category_name>
<Parent_ID>4</Parent_ID>
</category>
<category>
<ID>51</ID>
<Category_name>Trudnice i dojilje</Category_name>
<Parent_ID>4</Parent_ID>
</category>
<category>
<ID>52</ID>
<Category_name>Cvijece i bilje</Category_name>
<Parent_ID>5</Parent_ID>
</category>
<category>
<ID>53</ID>
<Category_name>Cvjecarski pribor</Category_name>
<Parent_ID>5</Parent_ID>
</category>
<category>
<ID>54</ID>
<Category_name>Zemlja</Category_name>
<Parent_ID>5</Parent_ID>
</category>
<category>
<ID>55</ID>
<Category_name>Proizvodi na akciji</Category_name>
<Parent_ID>6</Parent_ID>
</category>
So, what I would like to be able to do, is for example query all of the categories with the same Parent_ID.
Any ideas? (Sorry if it's a dumb question, but I just can't figure this out)
How to download a file over HTTP: http://www.qtforum.org/article/29846/qhttp-problem-with-the-timeout.html
The basic gist here is to use QUrl and QHttp classes. Start the HTTP request and connect to the QHttp object's done
signal to act on the file when the download is complete.
How to read an XML file: http://www.qtforum.org/article/27624/how-to-read-a-xml-file.html
You can match nodes in XML using xpath expressions:
number(/category/Parent_ID)=1 # for Parent_ID of 1.
To evaluate an XPath expression in Qt, see How do I run XPath queries in QT?
精彩评论