开发者

how to identify that XML parsing has been finished?

how can i identify that XML parsing has开发者_如何学Go been finished? any method is there to be called at the end of parsing all data?


Assuming that you use NSXMLParser:

- (void)parserDidEndDocument:(NSXMLParser *)parser

Sent by the parser object to the delegate when it has successfully completed parsing.


Use this method and when you reach the enclosing end element process it accordingly

(void)parser:(NSXMLParser *)parser didEndElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName 


Most standard XML parsers either create a complete DOM or explicitly expose the SAX API (http://www.saxproject.org/quickstart.html). The SAX API has a specific endDocument() method after which you can assume that the document has been completely read. The DOM methods do not have a universal API but a typical example is given by XOM (http://www.xom.nu) with a call:

Document doc = new Builder().build(myInstream);

This either completes satisfactorily or throws an exception.

There are other tools such as StAX (http://stax.codehaus.org/Home) which allow partial parsing.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜