Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Adriano - 26/10/2010
- // Metodo para retornar un XML con XPATH
- NSString *getStringXPathQuery(NSData *document, NSString *query)
- {
- xmlXPathContextPtr xpathCtx;
- xmlXPathObjectPtr xpathObj;
- xmlDocPtr doc;
- /* Load XML document */
- doc = htmlReadMemory([document bytes], [document length], "", NULL, HTML_PARSE_NOWARNING | HTML_PARSE_NOERROR);
- if (doc == NULL)
- {
- NSLog(@"Unable to parse.");
- return nil;
- }
- /* Create xpath evaluation context */
- xpathCtx = xmlXPathNewContext(doc);
- if(xpathCtx == NULL)
- {
- NSLog(@"Unable to create XPath context.");
- return nil;
- }
- /* Evaluate xpath expression */
- xpathObj = xmlXPathEvalExpression((xmlChar *)[query cStringUsingEncoding:NSUTF8StringEncoding], xpathCtx);
- if(xpathObj == NULL) {
- NSLog(@"Unable to evaluate XPath.");
- return nil;
- }
- xmlNodeSetPtr nodes = xpathObj->nodesetval;
- if (!nodes)
- {
- NSLog(@"Nodes was nil.");
- return nil;
- }
- return nodes->->nodeTab[0]->content;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement