1 |
|
---|
2 | void wrapInFunction()
|
---|
3 | {
|
---|
4 |
|
---|
5 | //! [0]
|
---|
6 | #include <QtXmlPatterns>
|
---|
7 | //! [0]
|
---|
8 |
|
---|
9 |
|
---|
10 | //! [1]
|
---|
11 | QT += xmlpatterns
|
---|
12 | //! [1]
|
---|
13 |
|
---|
14 | //! [2]
|
---|
15 | xmlpatterns myQuery.xq
|
---|
16 | //! [2]
|
---|
17 |
|
---|
18 | //! [3]
|
---|
19 | declare namespace c = "http://cookbook/namespace";
|
---|
20 | doc('cookbook.xml')//c:recipe/c:title
|
---|
21 | //! [3]
|
---|
22 |
|
---|
23 | //! [4]
|
---|
24 | declare default element namespace "http://cookbook/namespace";
|
---|
25 | doc('cookbook.xml')//recipe/title
|
---|
26 | //! [4]
|
---|
27 |
|
---|
28 | //! [5]
|
---|
29 | <title xmlns="http://cookbook/namespace">Quick and Easy Mushroom Soup</title>
|
---|
30 | <title xmlns="http://cookbook/namespace">Cheese on Toast</title>
|
---|
31 | <title xmlns="http://cookbook/namespace">Hard-Boiled Eggs</title>
|
---|
32 | //! [5]
|
---|
33 |
|
---|
34 | //! [6]
|
---|
35 | xmlpatterns file.xq
|
---|
36 | //! [6]
|
---|
37 |
|
---|
38 | //! [7]
|
---|
39 | doc('cookbook.xml')//@xml:*
|
---|
40 | //! [7]
|
---|
41 |
|
---|
42 | //! [8]
|
---|
43 | doc('cookbook.xml')//@*:name
|
---|
44 | //! [8]
|
---|
45 |
|
---|
46 | //! [9]
|
---|
47 | declare default element namespace "http://cookbook/namespace";
|
---|
48 | doc('cookbook.xml')/cookbook/@*
|
---|
49 | //! [9]
|
---|
50 |
|
---|
51 | //! [10]
|
---|
52 | declare default element namespace "http://cookbook/namespace";
|
---|
53 | doc("cookbook.xml")/cookbook/recipe[title = "Hard-Boiled Eggs"]
|
---|
54 | //! [10]
|
---|
55 |
|
---|
56 | //! [11]
|
---|
57 | declare default element namespace "http://cookbook/namespace";
|
---|
58 | doc('cookbook.xml')//method[string-length(.) = 0]
|
---|
59 | //! [11]
|
---|
60 |
|
---|
61 | //! [12]
|
---|
62 | declare default element namespace "http://cookbook/namespace";
|
---|
63 | doc('cookbook.xml')//method[string-length() = 0]
|
---|
64 | //! [12]
|
---|
65 |
|
---|
66 | //! [13]
|
---|
67 | declare default element namespace "http://cookbook/namespace";
|
---|
68 | doc('cookbook.xml')/cookbook/recipe[2]
|
---|
69 | //! [13]
|
---|
70 |
|
---|
71 | //! [14]
|
---|
72 | declare default element namespace "http://cookbook/namespace";
|
---|
73 | doc('cookbook.xml')/cookbook/recipe[position() = 2]
|
---|
74 | //! [14]
|
---|
75 |
|
---|
76 | //! [15]
|
---|
77 | declare default element namespace "http://cookbook/namespace";
|
---|
78 | doc('cookbook.xml')/cookbook/recipe[position() > 1]
|
---|
79 | //! [15]
|
---|
80 |
|
---|
81 | //! [16]
|
---|
82 | declare default element namespace "http://cookbook/namespace";
|
---|
83 | doc('cookbook.xml')/cookbook/recipe[last()]
|
---|
84 | //! [16]
|
---|
85 |
|
---|
86 | //! [17]
|
---|
87 | declare default element namespace "http://cookbook/namespace";
|
---|
88 | doc('cookbook.xml')/cookbook/recipe[last() - 1]
|
---|
89 | //! [17]
|
---|
90 |
|
---|
91 | //! [18]
|
---|
92 | doc('cookbook.xml')//recipe
|
---|
93 | //! [18]
|
---|
94 |
|
---|
95 | //! [19]
|
---|
96 | doc('cookbook.xml')//recipe/title
|
---|
97 | //! [19]
|
---|
98 |
|
---|
99 | //! [20]
|
---|
100 | <recipe/>
|
---|
101 | //! [20]
|
---|
102 |
|
---|
103 | //! [21]
|
---|
104 | <html xmlns="http://www.w3.org/1999/xhtml/"
|
---|
105 | xml:id="{doc("other.html")/html/@xml:id}"/>
|
---|
106 | //! [21]
|
---|
107 |
|
---|
108 | //! [22]
|
---|
109 | doc('cookbook.xml')/descendant-or-self::element(recipe)/child::element(title)
|
---|
110 | //! [22]
|
---|
111 |
|
---|
112 | //! [23]
|
---|
113 | <cookbook>
|
---|
114 | //! [23]
|
---|
115 |
|
---|
116 | //! [24]
|
---|
117 | <cookbook xmlns="http://cookbook/namespace">
|
---|
118 | //! [24]
|
---|
119 |
|
---|
120 | //! [25]
|
---|
121 | for $i in doc("cookbook.xml")//@xml:*
|
---|
122 | return <p>{$i}</p>
|
---|
123 | //! [25]
|
---|
124 |
|
---|
125 | //! [26]
|
---|
126 | for $i in doc("cookbook.xml")//@*:name
|
---|
127 | return <p>{$i}</p>
|
---|
128 | //! [26]
|
---|
129 |
|
---|
130 | //! [27]
|
---|
131 | declare default element namespace "http://cookbook/namespace";
|
---|
132 | for $i in doc("cookbook.xml")/cookbook/@*
|
---|
133 | return <p>{$i}</p>
|
---|
134 | //! [27]
|
---|
135 |
|
---|
136 | //! [28]
|
---|
137 | <p xml:id="MushroomSoup"/>
|
---|
138 | <p xml:id="CheeseOnToast"/>
|
---|
139 | <p xml:id="HardBoiledEggs"/>
|
---|
140 | //! [28]
|
---|
141 |
|
---|
142 | //! [29]
|
---|
143 | <p name="Fresh mushrooms"/>
|
---|
144 | <p name="Garlic"/>
|
---|
145 | <p name="Olive oil"/>
|
---|
146 | <p name="Milk"/>
|
---|
147 | <p name="Water"/>
|
---|
148 | <p name="Cream"/>
|
---|
149 | <p name="Vegetable soup cube"/>
|
---|
150 | <p name="Ground black pepper"/>
|
---|
151 | <p name="Dried parsley"/>
|
---|
152 | <p name="Bread"/>
|
---|
153 | <p name="Cheese"/>
|
---|
154 | <p name="Eggs"/>
|
---|
155 | //! [29]
|
---|
156 |
|
---|
157 | //! [30]
|
---|
158 | <p xmlns="http://cookbook/namespace" count="3"/>
|
---|
159 | //! [30]
|
---|
160 |
|
---|
161 | //! [31]
|
---|
162 | <method xmlns="http://cookbook/namespace"/>
|
---|
163 | //! [31]
|
---|
164 |
|
---|
165 | //! [32]
|
---|
166 | declare default element namespace "http://cookbook/namespace";
|
---|
167 | doc('cookbook.xml')//recipe[string-length(method) = 0]
|
---|
168 | //! [32]
|
---|
169 |
|
---|
170 | //! [33]
|
---|
171 | <recipe xmlns="http://cookbook/namespace" xml:id="HardBoiledEggs">
|
---|
172 | <title>Hard-Boiled Eggs</title>
|
---|
173 | <ingredient name="Eggs" quantity="3" unit="eggs"/>
|
---|
174 | <time quantity="3" unit="minutes"/>
|
---|
175 | <method/>
|
---|
176 | </recipe>
|
---|
177 | //! [33]
|
---|
178 |
|
---|
179 | //! [34]
|
---|
180 | declare default element namespace "http://cookbook/namespace";
|
---|
181 | doc('cookbook.xml')/cookbook/recipe[method[empty(step)]]
|
---|
182 | //! [34]
|
---|
183 |
|
---|
184 | //! [35]
|
---|
185 | declare default element namespace "http://cookbook/namespace";
|
---|
186 | doc('cookbook.xml')/cookbook/recipe[not(normalize-space(method))]
|
---|
187 | //! [35]
|
---|
188 |
|
---|
189 | //! [36]
|
---|
190 | <e>{sum((1, 2, 3))}</e>
|
---|
191 | //! [36]
|
---|
192 |
|
---|
193 | //! [37]
|
---|
194 | <e>6</e>
|
---|
195 | //! [37]
|
---|
196 |
|
---|
197 | //![38]
|
---|
198 | declare variable $insertion := "example";
|
---|
199 | <p class="important {$insertion} obsolete"/>
|
---|
200 | //![38]
|
---|
201 |
|
---|
202 | //! [39]
|
---|
203 | <p class="important example obsolete"/>
|
---|
204 | //! [39]
|
---|
205 |
|
---|
206 | //! [40]
|
---|
207 | declare default element namespace "http://cookbook/namespace";
|
---|
208 | let $docURI := 'cookbook.xml'
|
---|
209 | return if(doc-available($docURI))
|
---|
210 | then doc($docURI)//recipe/<resept>{./node()}</resept>
|
---|
211 | else <resept>Failed to load {$docURI}</resept>
|
---|
212 | //! [40]
|
---|
213 |
|
---|
214 | //! [41]
|
---|
215 | <span>1</span>
|
---|
216 | <span>3</span>
|
---|
217 | <span>5</span>
|
---|
218 | <span>7</span>
|
---|
219 | <span>9</span>
|
---|
220 | <span>b</span>
|
---|
221 | <span>d</span>
|
---|
222 | <span>f</span>
|
---|
223 | //! [41]
|
---|
224 |
|
---|
225 | //! [42]
|
---|
226 | <span>1</span>
|
---|
227 | //! [42]
|
---|
228 |
|
---|
229 | //! [43]
|
---|
230 | let $doc := doc('doc.txt')
|
---|
231 | return $doc/doc/p[1]/span[1]
|
---|
232 | //! [43]
|
---|
233 |
|
---|
234 | //! [44]
|
---|
235 | for $a in doc('doc.txt')/doc/p/span[1]
|
---|
236 | return $a
|
---|
237 | //! [44]
|
---|
238 |
|
---|
239 | //! [45]
|
---|
240 | doc('doc.txt')/doc/p/span[1]
|
---|
241 | //! [45]
|
---|
242 |
|
---|
243 | //! [46]
|
---|
244 | doc('doc.txt')//p/<p>{span/node()}</p>
|
---|
245 | //! [46]
|
---|
246 |
|
---|
247 | //! [47]
|
---|
248 | <p>78</p>
|
---|
249 | <p>9a</p>
|
---|
250 | <p>12</p>
|
---|
251 | <p>bc</p>
|
---|
252 | <p>de</p>
|
---|
253 | <p>34</p>
|
---|
254 | <p>56</p>
|
---|
255 | <p>f0</p>
|
---|
256 | //! [47]
|
---|
257 |
|
---|
258 | //! [48]
|
---|
259 | for $a in doc('doc.txt')//p
|
---|
260 | return <p>{$a/span/node()}</p>
|
---|
261 | //! [48]
|
---|
262 |
|
---|
263 | //! [49]
|
---|
264 | <p>12</p>
|
---|
265 | <p>34</p>
|
---|
266 | <p>56</p>
|
---|
267 | <p>78</p>
|
---|
268 | <p>9a</p>
|
---|
269 | <p>bc</p>
|
---|
270 | <p>de</p>
|
---|
271 | <p>f0</p>
|
---|
272 | //! [49]
|
---|
273 |
|
---|
274 | //! [100]
|
---|
275 | <?xml version="1.0" encoding="UTF-8"?>
|
---|
276 | <cookbook>
|
---|
277 | <recipe xml:id="MushroomSoup">
|
---|
278 | <title>Quick and Easy Mushroom Soup</title>
|
---|
279 | <ingredient name="Fresh mushrooms"
|
---|
280 | quantity="7"
|
---|
281 | unit="pieces"/>
|
---|
282 | <ingredient name="Garlic"
|
---|
283 | quantity="1"
|
---|
284 | unit="cloves"/>
|
---|
285 | <ingredient name="Olive oil"
|
---|
286 | quantity="2"
|
---|
287 | unit="tablespoons"/>
|
---|
288 | <ingredient name="Milk"
|
---|
289 | quantity="200"
|
---|
290 | unit="milliliters"/>
|
---|
291 | <ingredient name="Water"
|
---|
292 | quantity="200"
|
---|
293 | unit="milliliters"/>
|
---|
294 | <ingredient name="Cream"
|
---|
295 | quantity="100"
|
---|
296 | unit="milliliters"/>
|
---|
297 | <ingredient name="Vegetable soup cube"
|
---|
298 | quantity="1/2"
|
---|
299 | unit="cubes"/>
|
---|
300 | <ingredient name="Ground black pepper"
|
---|
301 | quantity="1/2"
|
---|
302 | unit="teaspoons"/>
|
---|
303 | <ingredient name="Dried parsley"
|
---|
304 | quantity="1"
|
---|
305 | unit="teaspoons"/>
|
---|
306 | <time quantity="20"
|
---|
307 | unit="minutes"/>
|
---|
308 | <method>
|
---|
309 | <step>1. Slice mushrooms and garlic.</step>
|
---|
310 | <step>2. Fry mushroom slices and garlic with olive oil.</step>
|
---|
311 | <step>3. Once mushrooms are cooked, add milk, cream water. Stir.</step>
|
---|
312 | <step>4. Add vegetable soup cube.</step>
|
---|
313 | <step>5. Reduce heat, add pepper and parsley.</step>
|
---|
314 | <step>6. Turn off the stove before the mixture boils.</step>
|
---|
315 | <step>7. Blend the mixture.</step>
|
---|
316 | </method>
|
---|
317 | </recipe>
|
---|
318 | <recipe xml:id="CheeseOnToast">
|
---|
319 | <title>Cheese on Toast</title>
|
---|
320 | <ingredient name="Bread"
|
---|
321 | quantity="2"
|
---|
322 | unit="slices"/>
|
---|
323 | <ingredient name="Cheese"
|
---|
324 | quantity="2"
|
---|
325 | unit="slices"/>
|
---|
326 | <time quantity="3"
|
---|
327 | unit="minutes"/>
|
---|
328 | <method>
|
---|
329 | <step>1. Slice the bread and cheese.</step>
|
---|
330 | <step>2. Grill one side of each slice of bread.</step>
|
---|
331 | <step>3. Turn over the bread and place a slice of cheese on each piece.</step>
|
---|
332 | <step>4. Grill until the cheese has started to melt.</step>
|
---|
333 | <step>5. Serve and enjoy!</step>
|
---|
334 | </method>
|
---|
335 | </recipe>
|
---|
336 | <recipe xml:id="HardBoiledEggs">
|
---|
337 | <title>Hard-Boiled Eggs</title>
|
---|
338 | <ingredient name="Eggs"
|
---|
339 | quantity="3"
|
---|
340 | unit="eggs"/>
|
---|
341 | <time quantity="3"
|
---|
342 | unit="minutes"/>
|
---|
343 | <method/>
|
---|
344 | </recipe>
|
---|
345 | </cookbook>
|
---|
346 | //! [100]
|
---|
347 |
|
---|
348 | }
|
---|
349 |
|
---|