-
Notifications
You must be signed in to change notification settings - Fork 203
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Parsing XML with namespaces #30
Comments
Thanks for the suggestion - I like the idea and it should be relatively easy to support. Just thinking out loud, but my initial thought is to add an optional options parameter to |
I have no problem with that. I think that would also be my approach. you reckon how long will it take to add this functionality? |
Sorry for the delayed response - I didn't even see your question regarding how long it would take. It honestly should be a pretty quick change. I actually had another thought regarding a variation in the API - I thought a fluent API where a config parameter was passed to an action might make a little more sense, like so: SWXMLHash.configure {
config in
config.shouldProcessNamespaces = true
}.parse(xml) That way, it would be easy to add additional configuration options to set ahead of time as opposed to adding multiple parameters to the parse method. As an aside, it might be a better way to handle the lazy parsing, too. Quick question for you - are you currently targeting the new Swift 2.0 in beta or are you still on Swift 1.2 (currently released)? I've set up a branch for 2.0 and can make the changes there, but if this would help you on 1.2, I can make the change there and then merge it over. |
We are still using swift 1.2 |
This change introduces a new fluent configuration method as a way of hopefully making it easy and straightforward to introduce new configuration options in the future. The first config option introduced in this commit is "shouldProcessNamespaces" which is forwarded on to the NSXMLParser instance (related to issue #30). There is also a config option for lazy XML parsing which can be used instead of calling "lazy" versus "parse".
I've created #34 to track this work - there are tests that pass. The general usage is:
I'd like to keep the pull request open for a little while to see if anyone has any additional input on using the |
I just merged my #34 to master - the above code snippet should provide what you're looking for. Thanks for the report! |
Swift 3 & Linux support (not for merging)
Currently, there is no way to set the XMLParser shouldProcessNamespaces to true. So when accessing an element, the complete tagname with namespace needs to be passed. e.g xml["f:animal"] instead of just xml["animal"]
In the example in the code, it would be nice if instead of this
xml["root"]["h:table"]["h:tr"]["h:td"][0].element!.text!
we will have this
xml["root"]["table"]["tr"]["td"][0].element!.text!
The text was updated successfully, but these errors were encountered: