source: trunk/doc/src/snippets/code/doc_src_qtxmlpatterns.qdoc@ 651

Last change on this file since 651 was 651, checked in by Dmitry A. Kuminov, 15 years ago

trunk: Merged in qt 4.6.2 sources.

File size: 6.8 KB
Line 
1/****************************************************************************
2**
3** Copyright (C) 2010 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:LGPL$
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
14** a written agreement between you and Nokia.
15**
16** GNU Lesser General Public License Usage
17** Alternatively, this file may be used under the terms of the GNU Lesser
18** General Public License version 2.1 as published by the Free Software
19** Foundation and appearing in the file LICENSE.LGPL included in the
20** packaging of this file. Please review the following information to
21** ensure the GNU Lesser General Public License version 2.1 requirements
22** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
23**
24** In addition, as a special exception, Nokia gives you certain additional
25** rights. These rights are described in the Nokia Qt LGPL Exception
26** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
27**
28** GNU General Public License Usage
29** Alternatively, this file may be used under the terms of the GNU
30** General Public License version 3.0 as published by the Free Software
31** Foundation and appearing in the file LICENSE.GPL included in the
32** packaging of this file. Please review the following information to
33** ensure the GNU General Public License version 3.0 requirements will be
34** met: http://www.gnu.org/copyleft/gpl.html.
35**
36** If you have questions regarding the use of this file, please contact
37** Nokia at [email protected].
38** $QT_END_LICENSE$
39**
40****************************************************************************/
41
42
43void wrapInFunction()
44{
45
46//! [0]
47#include <QtXmlPatterns>
48//! [0]
49
50
51//! [1]
52QT += xmlpatterns
53//! [1]
54
55//! [2]
56xmlpatterns myQuery.xq
57//! [2]
58
59//! [3]
60declare namespace c = "http://cookbook/namespace";
61doc('cookbook.xml')//c:recipe/c:title
62//! [3]
63
64//! [4]
65declare default element namespace "http://cookbook/namespace";
66doc('cookbook.xml')//recipe/title
67//! [4]
68
69//! [5]
70<title xmlns="http://cookbook/namespace">Quick and Easy Mushroom Soup</title>
71<title xmlns="http://cookbook/namespace">Cheese on Toast</title>
72<title xmlns="http://cookbook/namespace">Hard-Boiled Eggs</title>
73//! [5]
74
75//! [6]
76xmlpatterns file.xq
77//! [6]
78
79//! [7]
80doc('cookbook.xml')//@xml:*
81//! [7]
82
83//! [8]
84doc('cookbook.xml')//@*:name
85//! [8]
86
87//! [9]
88declare default element namespace "http://cookbook/namespace";
89doc('cookbook.xml')/cookbook/@*
90//! [9]
91
92//! [10]
93declare default element namespace "http://cookbook/namespace";
94doc("cookbook.xml")/cookbook/recipe[title = "Hard-Boiled Eggs"]
95//! [10]
96
97//! [11]
98declare default element namespace "http://cookbook/namespace";
99doc('cookbook.xml')//method[string-length(.) = 0]
100//! [11]
101
102//! [12]
103declare default element namespace "http://cookbook/namespace";
104doc('cookbook.xml')//method[string-length() = 0]
105//! [12]
106
107//! [13]
108declare default element namespace "http://cookbook/namespace";
109doc('cookbook.xml')/cookbook/recipe[2]
110//! [13]
111
112//! [14]
113declare default element namespace "http://cookbook/namespace";
114doc('cookbook.xml')/cookbook/recipe[position() = 2]
115//! [14]
116
117//! [15]
118declare default element namespace "http://cookbook/namespace";
119doc('cookbook.xml')/cookbook/recipe[position() > 1]
120//! [15]
121
122//! [16]
123declare default element namespace "http://cookbook/namespace";
124doc('cookbook.xml')/cookbook/recipe[last()]
125//! [16]
126
127//! [17]
128declare default element namespace "http://cookbook/namespace";
129doc('cookbook.xml')/cookbook/recipe[last() - 1]
130//! [17]
131
132//! [18]
133doc('cookbook.xml')//recipe
134//! [18]
135
136//! [19]
137doc('cookbook.xml')//recipe/title
138//! [19]
139
140//! [20]
141<recipe/>
142//! [20]
143
144//! [21]
145 <html xmlns="http://www.w3.org/1999/xhtml/"
146 xml:id="{doc("other.html")/html/@xml:id}"/>
147//! [21]
148
149//! [22]
150doc('cookbook.xml')/descendant-or-self::element(recipe)/child::element(title)
151//! [22]
152
153//! [23]
154<cookbook>
155//! [23]
156
157//! [24]
158<cookbook xmlns="http://cookbook/namespace">
159//! [24]
160
161//! [25]
162for $i in doc("cookbook.xml")//@xml:*
163return <p>{$i}</p>
164//! [25]
165
166//! [26]
167for $i in doc("cookbook.xml")//@*:name
168return <p>{$i}</p>
169//! [26]
170
171//! [27]
172declare default element namespace "http://cookbook/namespace";
173for $i in doc("cookbook.xml")/cookbook/@*
174return <p>{$i}</p>
175//! [27]
176
177//! [28]
178<p xml:id="MushroomSoup"/>
179<p xml:id="CheeseOnToast"/>
180<p xml:id="HardBoiledEggs"/>
181//! [28]
182
183//! [29]
184<p name="Fresh mushrooms"/>
185<p name="Garlic"/>
186<p name="Olive oil"/>
187<p name="Milk"/>
188<p name="Water"/>
189<p name="Cream"/>
190<p name="Vegetable soup cube"/>
191<p name="Ground black pepper"/>
192<p name="Dried parsley"/>
193<p name="Bread"/>
194<p name="Cheese"/>
195<p name="Eggs"/>
196//! [29]
197
198//! [30]
199<p xmlns="http://cookbook/namespace" count="3"/>
200//! [30]
201
202//! [31]
203<method xmlns="http://cookbook/namespace"/>
204//! [31]
205
206//! [32]
207declare default element namespace "http://cookbook/namespace";
208doc('cookbook.xml')//recipe[string-length(method) = 0]
209//! [32]
210
211//! [33]
212<recipe xmlns="http://cookbook/namespace" xml:id="HardBoiledEggs">
213 <title>Hard-Boiled Eggs</title>
214 <ingredient name="Eggs" quantity="3" unit="eggs"/>
215 <time quantity="3" unit="minutes"/>
216 <method/>
217</recipe>
218//! [33]
219
220//! [34]
221declare default element namespace "http://cookbook/namespace";
222doc('cookbook.xml')/cookbook/recipe[method[empty(step)]]
223//! [34]
224
225//! [35]
226declare default element namespace "http://cookbook/namespace";
227doc('cookbook.xml')/cookbook/recipe[not(normalize-space(method))]
228//! [35]
229
230//! [36]
231<e>{sum((1, 2, 3))}</e>
232//! [36]
233
234//! [37]
235<e>6</e>
236//! [37]
237
238//![38]
239declare variable $insertion := "example";
240<p class="important {$insertion} obsolete"/>
241//![38]
242
243//! [39]
244<p class="important example obsolete"/>
245//! [39]
246
247//! [40]
248declare default element namespace "http://cookbook/namespace";
249let $docURI := 'cookbook.xml'
250return if(doc-available($docURI))
251 then doc($docURI)//recipe/<oppskrift>{./node()}</oppskrift>
252 else <oppskrift>Failed to load {$docURI}</oppskrift>
253//! [40]
254
255//! [41]
256<span>1</span>
257<span>3</span>
258<span>5</span>
259<span>7</span>
260<span>9</span>
261<span>b</span>
262<span>d</span>
263<span>f</span>
264//! [41]
265
266//! [42]
267<span>1</span>
268//! [42]
269
270//! [43]
271let $doc := doc('doc.txt')
272return $doc/doc/p[1]/span[1]
273//! [43]
274
275//! [44]
276for $a in doc('doc.txt')/doc/p/span[1]
277return $a
278//! [44]
279
280//! [45]
281doc('doc.txt')/doc/p/span[1]
282//! [45]
283
284//! [46]
285doc('doc.txt')//p/<p>{span/node()}</p>
286//! [46]
287
288//! [47]
289<p>78</p>
290<p>9a</p>
291<p>12</p>
292<p>bc</p>
293<p>de</p>
294<p>34</p>
295<p>56</p>
296<p>f0</p>
297//! [47]
298
299//! [48]
300for $a in doc('doc.txt')//p
301 return <p>{$a/span/node()}</p>
302//! [48]
303
304//! [49]
305<p>12</p>
306<p>34</p>
307<p>56</p>
308<p>78</p>
309<p>9a</p>
310<p>bc</p>
311<p>de</p>
312<p>f0</p>
313//! [49]
314
315}
316
Note: See TracBrowser for help on using the repository browser.