Joshua Olson Joshua Olson - 3 months ago 28
Swift Question

SWXMLHash compact root element

I have a question I hope will be quick. I am parsing XML returned by eBay’s API using SWXMLHash for Swift. Some of the returns get quite verbose.

such as:


How would I go about compacting this to say:


is there a way to specify this in this instantiation? I have tried (which obviously did not work):

let xml = SWXMLHash.config {
config in
config.shouldProcessLazily = true
config.shouldProcessNamespaces = true
rootElementName = "findCompletedItemsResponse"


I would suggest doing something like:

let rootXml = xml["findCompletedItemsResponse"]["searchResults"]
// ...
let sellerID = rootXml["item"]...["sellerID"].element?.text

Each indexed level can be saved off into a variable - it is just an instance of XMLIndexer that has been indexed down a certain level.

Hope this helps!