Date
1 - 6 of 6
How to return data for NXSMLParserDelegate's -parser:resolveExternalEntityName:systemID:
Steve Mills
What is the expected value of the returned NSData supposed to be for this method? The docs says "An NSData object that contains the resolution of the given external entity." To me, that means that for entity "nbsp", I should return " " as:
[@" " dataUsingEncoding:NSUTF8StringEncoding] But the parser just stops parsing after that and never calls any delegate methods. The parser fails and has error: The operation couldn't be completed. (NSXMLParserErrorDomain error 111.) Of course, error 111 isn't listed in the NSXMLParserError enum. It's all so cryptic. Oh, but if I implement -parser:parseErrorOccurred:, that gives me error 26, NSXMLParserUndeclaredEntityError. Still, pretty cryptic when it comes to documenting what is expected of -parser:resolveExternalEntityName:systemID: Can anyone decipher what Apple really means? I even tried just returning plain ol' unescaped text in the data, [@"x" dataUsingEncoding:NSUTF8StringEncoding] and got the same result. -- Steve Mills Drummer, Mac geek |
|
Glenn L. Austin
On Dec 11, 2019, at 8:52 AM, Steve Mills via Groups.Io <sjmills@...> wrote:Have you tried returning a full XML entity, e.g. "<string> </string>"? That would be my next experiment... -- Glenn L. Austin, Computer Wizard and Race Car Driver <>< <http://www.austinsoft.com> |
|
Steve Mills
On Dec 11, 2019, at 10:25:45, Glenn L. Austin <glenn@...> wrote:
Same error. Thanks for the suggestion. -- Steve Mills Drummer, Mac geek |
|
Steve Mills
I also wonder (thanks to the lack of documentation) if I should be supplying some standard urls in the allowedExternalEntityURLs property of the NSXMLParser. Would that cause the parser to automatically resolve standard entities? If so, what urls would do that? I haven't been able to find them on sites like w3.org or w3schools.com.
-- Steve Mills Drummer, Mac geek |
|
Keary Suska
IRC, NSXMLParser is pretty vanilla, and back in the day it was recommended to use an xml parsing library directly rather than NSXMLParser if you have to work with anything except basic XML. Does not seem like Apple has improved it since then. That being said, technically, there are only a small set of “standard” entities: <, >, ', " and &. All other entities must be declared.
toggle quoted message
Show quoted text
FWIW, the commonly accepted solution seems to be to pre-convert entities before passing passing to NSXMLParser. As long as the result is valid utf-8, it won’t choke the parser. The most comprehensive discussion I could find was this one: https://stackoverflow.com/questions/2370842/resolving-html-entities-with-nsxmlparser-on-iphone which may or may not have an alternative solution. HTH, Keary Suska Esoteritech, Inc. On Dec 11, 2019, at 6:40 AM, Steve Mills via Groups.Io <sjmills@...> wrote: |
|
Steve Mills
On Dec 11, 2019, at 12:21:27, Keary Suska <cocoa-dev@...> wrote:
Thanks for this. I ended up pre- and post-processing entities that aren't normally handled by the parser or the delegate in other places, because I simply want them to persist. Yeah, NSXMLParser and friends are pretty lame when it comes down to doing anything not involving elements and plain text. -- Steve Mills Drummer, Mac geek |
|