File tree 3 files changed +49
-1
lines changed 3 files changed +49
-1
lines changed Original file line number Diff line number Diff line change
1
+ ## v4.4.0 (February 4, 2018)
2
+
3
+ * Added ` filter ` support (via
4
+ [ #171 ] ( https://github.com/drmohundro/SWXMLHash/pull/174 ) and
5
+ [ #167 ] ( https://github.com/drmohundro/SWXMLHash/issues/170 ) )
6
+
1
7
## v4.3.6 (January 21, 2018)
2
8
3
9
* Fixed CDATA parsing in Linux (via
Original file line number Diff line number Diff line change @@ -313,6 +313,48 @@ func enumerate(indexer: XMLIndexer) {
313
313
enumerate (indexer : xml)
314
314
```
315
315
316
+ ### Filtering elements
317
+
318
+ Given:
319
+
320
+ ``` xml
321
+ <root >
322
+ <catalog >
323
+ <book id =\" bk101\" >
324
+ <author >Gambardella, Matthew</author >
325
+ <title >XML Developer's Guide</title >
326
+ <genre >Computer</genre ><price >44.95</price >
327
+ <publish_date >2000-10-01</publish_date >
328
+ </book >
329
+ <book id =\" bk102\" >
330
+ <author >Ralls, Kim</author >
331
+ <title >Midnight Rain</title >
332
+ <genre >Fantasy</genre >
333
+ <price >5.95</price >
334
+ <publish_date >2000-12-16</publish_date >
335
+ </book >
336
+ <book id =\" bk103\" >
337
+ <author >Corets, Eva</author >
338
+ <title >Maeve Ascendant</title >
339
+ <genre >Fantasy</genre >
340
+ <price >5.95</price >
341
+ <publish_date >2000-11-17</publish_date >
342
+ </book >
343
+ </catalog >
344
+ </root >
345
+ ```
346
+
347
+ The following will return return "Midnight Rain". Filtering can be by any part
348
+ of the ` XMLElement ` class or by index as well.
349
+
350
+ ``` swift
351
+ let subIndexer = xml! [" root" ][" catalog" ][" book" ]
352
+ .filter { elem, _ in elem.attribute (by : " id" )! .text == " bk102" }
353
+ .filter { _ , index in index >= 1 && index <= 3 }
354
+
355
+ print (subIndexer[0 ].element ? .text )
356
+ ```
357
+
316
358
### Error Handling
317
359
318
360
Using Swift 2.0's new error handling feature:
Original file line number Diff line number Diff line change 1
1
Pod ::Spec . new do |s |
2
2
s . name = 'SWXMLHash'
3
- s . version = '4.3.6 '
3
+ s . version = '4.4.0 '
4
4
s . summary = 'Simple XML parsing in Swift'
5
5
s . homepage = 'https://github.com/drmohundro/SWXMLHash'
6
6
s . license = { type : 'MIT' }
You can’t perform that action at this time.
0 commit comments