Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
StackOverflow Question - SWXMLHash Test
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
@drmohundro
Copy link
Author

drmohundro commented Aug 24, 2020

Seems to work?

SWXMLHashPlayground playground 2020-08-24 11-34-41

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment