added document

This commit is contained in:
Kazuhiro Hayashi 2019-10-02 23:32:38 +09:00
parent d483543ce2
commit 584d461515
2 changed files with 9 additions and 3 deletions

View File

@ -226,12 +226,12 @@ entity.names ?<< xml.ResultSet.Result.Hit[1].Name.text // assign if it has text
```swift ```swift
let numberOfHits = xml.ResultSet.Result.Hit.all?.count let numberOfHits = xml.ResultSet.Result.Hit.all?.count
``` ```
### Check error ### 8. Check error
```swift ```swift
print(xml.ResultSet.Result.TypoKey) // -> "TypoKey not found." print(xml.ResultSet.Result.TypoKey) // -> "TypoKey not found."
``` ```
### Access as SequenceType ### 9. Access as SequenceType
+ for-in + for-in
```swift ```swift
for element in xml.ResultSet.Result.Hit { for element in xml.ResultSet.Result.Hit {
@ -243,6 +243,12 @@ for element in xml.ResultSet.Result.Hit {
xml.ResultSet.Result.Hit.map { $0.Name.text } xml.ResultSet.Result.Hit.map { $0.Name.text }
``` ```
### 9. Generate XML document
```swift
print(Converter(xml.ResultSet).makeDocument())
```
## Work with Alamofire ## Work with Alamofire
SwiftyXMLParser goes well with [Alamofire](https://github.com/Alamofire/Alamofire). You can parse the response easily. SwiftyXMLParser goes well with [Alamofire](https://github.com/Alamofire/Alamofire). You can parse the response easily.

View File

@ -466,7 +466,7 @@ extension XML {
``` ```
let xml = try! XML.parse("<?xml version="1.0" encoding="UTF-8"?><doc><name key="value">text</name></doc>") let xml = try! XML.parse("<?xml version="1.0" encoding="UTF-8"?><doc><name key="value">text</name></doc>")
let elem = xml["doc"] let elem = xml.doc
print(Converter(elem).makeDocument()) print(Converter(elem).makeDocument())
// => <?xml version="1.0" encoding="UTF-8"?><name key="value">text</name> // => <?xml version="1.0" encoding="UTF-8"?><name key="value">text</name>