Joshua Olson Joshua Olson - 1 year ago 103
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"

Answer Source

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!

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download