views:

9

answers:

1

I'm trying to retrieve the public and system IDs for a DTD in an XML document via NSXMLParser. While NSXMLParser in principal offers publicID and systemID selectors they don't seem to work for me. The doctype tag looks like this:

<!DOCTYPE Article PUBLIC "-//SoftQuad Software//DTD Journalist v2.0 20000501//EN" "file:///C:/Program%20Files/Corel/XMetaL%204/Author/Rules/journalist.dtd">

Here's my code (the file was opened via NSFileHandle's readDataToEndOfFile:

NSXMLParser *parser = [[NSXMLParser alloc] initWithData:data];
[parser setDelegate:self];
BOOL parseSuccessful = [parser parse];

In the delegate's parserDidStartDocument: I try to access the IDs:

NSLog(@"%@ : %@", [parser publicID], [parser systemID]);

But I only see

(null) : (null)

From the documentation:

You may invoke this method once a parsing operation has begun or after an error occurs.

So I'd think this should work already in parserDidStartDocument: but I tried to call these selectors in different delegate methods (like parser:didStartElement:namespaceURI:qualifiedName:attributes: but without success.

Any ideas what I'm doing wrong?

A: 

You might try out another parser.

http://www.robbiehanson.com/expat.html provides a drop-in replacement for NSXMLParser based on expat.

You might also find this article interesting, comparing the performance of various XML parsers on the iPhone.

http://www.raywenderlich.com/553/how-to-chose-the-best-xml-parser-for-your-iphone-project

Bill Garrison