1 | /****************************************************************************
|
---|
2 | **
|
---|
3 | ** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
|
---|
4 | ** All rights reserved.
|
---|
5 | ** Contact: Nokia Corporation ([email protected])
|
---|
6 | **
|
---|
7 | ** This file is part of the documentation of the Qt Toolkit.
|
---|
8 | **
|
---|
9 | ** $QT_BEGIN_LICENSE:FDL$
|
---|
10 | ** Commercial Usage
|
---|
11 | ** Licensees holding valid Qt Commercial licenses may use this file in
|
---|
12 | ** accordance with the Qt Commercial License Agreement provided with the
|
---|
13 | ** Software or, alternatively, in accordance with the terms contained in a
|
---|
14 | ** written agreement between you and Nokia.
|
---|
15 | **
|
---|
16 | ** GNU Free Documentation License
|
---|
17 | ** Alternatively, this file may be used under the terms of the GNU Free
|
---|
18 | ** Documentation License version 1.3 as published by the Free Software
|
---|
19 | ** Foundation and appearing in the file included in the packaging of this
|
---|
20 | ** file.
|
---|
21 | **
|
---|
22 | ** If you have questions regarding the use of this file, please contact
|
---|
23 | ** Nokia at [email protected].
|
---|
24 | ** $QT_END_LICENSE$
|
---|
25 | **
|
---|
26 | ****************************************************************************/
|
---|
27 |
|
---|
28 | /*!
|
---|
29 | \example xmlpatterns/trafficinfo
|
---|
30 | \title TrafficInfo Example
|
---|
31 |
|
---|
32 | Shows how XQuery can be used extract information from WML documents provided by a WAP service.
|
---|
33 |
|
---|
34 | \section1 Overview
|
---|
35 |
|
---|
36 | The WAP service used in this example is \l{Trafikanten}{wap.trafikanten.no}
|
---|
37 | that is run by the Norwegian governmental agency for public transport in
|
---|
38 | Oslo. The service provides real time information about the departure of
|
---|
39 | busses, trams and undergrounds for every station in the city area.
|
---|
40 |
|
---|
41 | This example application displays the departure information for a specific
|
---|
42 | station and provides the feature to filter for a special bus or tram line.
|
---|
43 |
|
---|
44 | \image trafficinfo-example.png
|
---|
45 |
|
---|
46 | \section1 Retrieving the Data
|
---|
47 |
|
---|
48 | Without the knowledge of XQuery, one would use QNetworkAccessManager to
|
---|
49 | query the WML document from the WAP service and then using the QDom
|
---|
50 | classes or QXmlStreamReader classes to iterate over the document and
|
---|
51 | extract the needed information.
|
---|
52 | However this approach results in a lot of glue code and consumes valuable
|
---|
53 | developer time, so we are looking for something that can access XML
|
---|
54 | documents locally or over the network and extract data according to given
|
---|
55 | filter rules. That's the point where XQuery enters the stage!
|
---|
56 |
|
---|
57 | If we want to know when the underground number 6 in direction
|
---|
58 | \Aring\c{}sjordet is passing the underground station in Nydalen on November
|
---|
59 | 14th 2008 after 1pm, we use the following URL:
|
---|
60 |
|
---|
61 | \c{http://wap.trafikanten.no/F.asp?f=03012130&t=13&m=00&d=14.11.2008&start=1}
|
---|
62 |
|
---|
63 | The parameters have the following meanings:
|
---|
64 | \list
|
---|
65 | \o \e{f} The unique station ID of Nydalen.
|
---|
66 | \o \e{t} The hour in 0-23 format.
|
---|
67 | \o \e{m} The minute in 0-59 format.
|
---|
68 | \o \e{d} The date in dd.mm.yyyy format.
|
---|
69 | \o \e{start} Not interesting for our use but should be passed.
|
---|
70 | \endlist
|
---|
71 |
|
---|
72 | As a result we get the following document:
|
---|
73 |
|
---|
74 | \quotefile examples/xmlpatterns/trafficinfo/time_example.wml
|
---|
75 |
|
---|
76 | So for every departure we have a \c <a> tag that contains the time as a
|
---|
77 | text element, and the following text element contains the line number
|
---|
78 | and direction.
|
---|
79 |
|
---|
80 | To encapsulate the XQuery code in the example application, we create a
|
---|
81 | custom \c TimeQuery class. This provides the \c queryInternal() function
|
---|
82 | that takes a station ID and date/time as input and returns the list of
|
---|
83 | times and directions:
|
---|
84 |
|
---|
85 | \snippet examples/xmlpatterns/trafficinfo/timequery.cpp 1
|
---|
86 |
|
---|
|
---|