Skip to content

Instantly share code, notes, and snippets.

@drmohundro
Last active August 24, 2020 16:36
Show Gist options
  • Save drmohundro/960cde2ed8d0568b128543c6f039d817 to your computer and use it in GitHub Desktop.
Save drmohundro/960cde2ed8d0568b128543c6f039d817 to your computer and use it in GitHub Desktop.
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

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