0

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:

 xml["findCompletedItemsResponse"][“searchResults"][“item”]...[“sellerID"].element?.text

How would I go about compacting this to say:

xml[rootVar][“item”]...[“sellerID"].element?.text

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"
}.parse(response);
Joshua Olson
  • 5
  • 1
  • 3

1 Answers1

0

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!

David Mohundro
  • 11,922
  • 5
  • 40
  • 44
  • Yep. Thank you! New to XML with Swift and got too focused on the forest I did not see the obvious tree. Your SWXMLHash is very well created. Thank you for sharing not only this wonderful tool but also your support as well! – Joshua Olson Nov 16 '16 at 04:16