XPath how to select the first element without loading the whole xml?
Im using libxml2 on the iPhone with the nice Method: PerformXMLXPathQuery from Cocoa with Love. The problem is how to find out witch xml got sent without first parsing the whole document... I tried to use the @"/" query to retrieve the first element as written on the introduction of Cocoa with Love but unfortunately, the PerformXMLXPathQuery crashes cause of this query!
When I use the @"/*" command the who开发者_如何学Gole tree gets parsed, which is very inefficient in terms of time and memory consumption..
Any Ideas how this works?
Thanks Markus
I'm not sure how tight your performance requirements are, but using a SAX parser, such as NSXMLParser, would enable you to quit parsing after you processed the element you're looking for. See the
- (void)abortParsing
method on the parser, and
– parser:didStartElement:namespaceURI:qualifiedName:attributes:
– parser:didEndElement:namespaceURI:qualifiedName:
on the NSXMLParserDelegate protocol.
精彩评论