Last active
August 24, 2020 16:36
-
-
Save drmohundro/960cde2ed8d0568b128543c6f039d817 to your computer and use it in GitHub Desktop.
StackOverflow Question - SWXMLHash Test
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import SWXMLHash | |
let xml = """ | |
<root> | |
<catalog> | |
<book><author>Bob</author></book> | |
<book><author>John</author></book> | |
<book><author>Mark</author></book> | |
</catalog> | |
</root> | |
""" | |
var parsedXML: XMLIndexer? = nil | |
parsedXML = SWXMLHash.parse(xml) | |
let name1 = parsedXML?["root"]["catalog"]["book"][0]["author"].element?.text | |
let name2 = parsedXML?["root"]["catalog"]["book"][1]["author"].element?.text | |
let name3 = parsedXML?["root"]["catalog"]["book"][2]["author"].element?.text | |
let catalog = parsedXML?["root"]["catalog"] | |
let subname1 = catalog?["book"][0]["author"].element?.text | |
let subname2 = catalog?["book"][1]["author"].element?.text | |
let subname3 = catalog?["book"][2]["author"].element?.text |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Seems to work?