Playing around with SWXMLHash, I am trying to pull out an element and then get its info. My xml file is large and I'd like to split up the parsing in smaller functions.
For example, this is from the GitHub page:
let xml = """
<root>
<catalog>
<book><author>Bob</author></book>
<book><author>John</author></book>
<book><author>Mark</author></book>
</catalog>
</root>
"""
self.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
This correctly results in "Bob, John, Mark"
But if I first pull out the catalog, all names are nil:
let catalog = parsedXML?["root"]["catalog"]
let name1 = catalog?["book"][0]["author"].element?.text // nil
let name2 = catalog?["book"][1]["author"].element?.text // nil
let name3 = catalog?["book"][2]["author"].element?.text // nil
Why is this, what am I missing?