开发者

How to get a DTD's public and system IDs with NSXMLParser

开发者 https://www.devze.com 2023-01-11 06:41 出处:网络
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. T

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.dt开发者_StackOverflow中文版d">

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?


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

0

精彩评论

暂无评论...
验证码 换一张
取 消