ÈçºÎʹÓÃObjective C½âÎöHTMLºÍXML
ʹÓÃObjective-C½âÎöHTML»òÕßXML£¬ÏµÍ³×Ô´øÓÐÁ½ÖÖ·½Ê½Ò»¸öÊÇͨ¹ýlibxml£¬Ò»¸öÊÇͨ¹ýNSXMLParser¡£²»¹ýÕâÁ½ÖÖ·½Ê½¶¼ÐèÒª×Ô¼ºÐ´ºÜ¶à±àÂëÀ´´¦ÀíץȡÏÂÀ´µÄÄÚÈÝ£¬¶øÇÒ²»ÊǺÜÖ±¹Û¡£
ÓÐÒ»¸ö±È½ÏºÃµÄÀà¿âhpple£¬ËüÊÇÒ»¸öÇáÁ¿¼¶µÄ°ü×°¿ò¼Ü£¬¿ÉÒԺܺõĽâ¾öÕâ¸öÎÊÌâ¡£ËüÊÇÓÃXPathÀ´¶¨Î»ºÍ½âÎöHTML»òÕßXML¡£
°²×°²½Ö裺
-¼ÓÈë libxml2 µ½ÄãµÄÏîÄ¿ÖÐ
Menu Project->Edit Project Settings
ËÑË÷ “Header Search Paths”
Ìí¼ÓÐ嵀 search path “${SDKROOT}/usr/include/libxml2″
Enable recursive option
-¼ÓÈë libxml2 library µ½ÄãµÄÏîÄ¿
Menu Project->Edit Project Settings
ËÑË÷ “Other Linker Flags”
Ìí¼ÓÐ嵀 search flag “-lxml2″
-½«ÏÂÃæhppleµÄÔ´´úÂë¼ÓÈëµ½ÄãµÄÏîÄ¿ÖÐ:
HTFpple.h
HTFpple.m
HTFppleElement.h
HTFppleElement.m
XPathQuery.h
XPathQuery.m
-XPathѧϰµØÖ·http://www.w3schools.com/XPath/default.asp
ʾÀý´úÂ룺
#import "TFHpple.h"
NSData *data = [[NSData alloc] initWithContentsOfFile:@"example.html"];
// Create parser
xpathParser = [[TFHpple alloc] initWithHTMLData:data];
//Get all the cells of the 2nd row of the 3rd table
NSArray *elements = [xpathParser search:@"//table[3]/tr[2]/td"];
// Access the first cell
TFHppleElement *element = [elements objectAtIndex:0];
// Get the text within the cell tag
NSString *content = [element content];
[xpathParser release];
[data release];
ÁíÍ⣬»¹ÓÐÒ»¸öÀàËƵĽâ¾ö·½°¸¿ÉÒԲο¼
ElementParser http://github.com/Objective3/ElementParser
Ïà¹ØÎĵµ£º
ÔÚc++ primeÊéÖп´µ½¹ý£¬ÔÚDLLºÍlibÖп´µ½¹ý£¬µ«ÊÇÿ´Î¿´¹ý¾Í²»ÇóÉõ½âµØһɨ¶ø¹ý¡£ÐÄÀïÖªµÀÓÐextern cÕâ¸öÓï¾ä£¬È´²»ÖªµÀ¸ÃÓÃÔÚÄÄÀÓÖÄÜÆðµ½Ê²Ã´×÷Óᣰ¦£¬ÏëÏë×Ô¼ºÒ²ËãÊÇд¹ý²»ÉÙCODEµÄÈËÁË£¬¿ÉÕâÖÖÑÛ¸ßÊֵ͵Ä벡ȴ´Óû¸Ä±ä¹ý¡£½ñÌìͻȻÏëÆðexternÕâ¸ö¹Ø¼ü×Ö£¬Ëì¾ö¶¨²»ÄÜÔÙÕâôÀË ......
HTML ÊÇ Web ͳһÓïÑÔ£¬ÕâЩÈÝÄÉÔÚ¼âÀ¨ºÅÀïµÄ¼òµ¥±êÇ©£¬¹¹³ÉÁËÈç½ñµÄ Web¡£1991 Ä꣬Tim Berners-Lee
±àдÁËÒ»·Ý½Ð×ö “HTML ±êÇ©”µÄÎĵµ£¬ÀïÃæ°üº¬ÁË´óÔ¼20¸öÓÃÀ´±ê¼ÇÍøÒ³µÄ HTML ±êÇ©¡£ËûÖ±½Ó½èÓà SGML
µÄ±ê¼Ç¸ñʽ£¬Ò²¾ÍÊǺóÀ´ÎÒÃÇ¿´µ½µÄ HTML ±ê¼ÇµÄ¸ñʽ¡£±¾ÎĽ²ÊöÁË HTML ÕâÃÅ Web ±ê¼ÇÓïÑԵķ¢Õ¹¼òÊ·¡£
......
HTML×Ö·ûʵÌå(Character Entities)
ÓÐЩ×Ö·ûÔÚHTMLÀïÓÐÌرðµÄº¬Ò壬±ÈÈçСÓÚºÅ<¾Í±íʾHTML TagµÄ¿ªÊ¼£¬Õâ¸öСÓÚºÅÊDz»ÏÔʾÔÚÎÒÃÇ×îÖÕ¿´µ½µÄÍøÒ³ÀïµÄ¡£ÄÇÈç¹ûÎÒÃÇÏ£ÍûÔÚÍøÒ³ÖÐÏÔʾһ¸öСÓںţ¬¸ÃÔõô°ìÄØ£¿
Õâ¾ÍҪ˵µ½HTML×Ö·ûʵÌå(HTML Character Entities)ÁË¡£
Ò»¸ö×Ö·ûʵÌå(Character Entity)·Ö³ÉÈý²¿·Ö£ºµÚÒ»²¿· ......
<select name="CluefromType" id="CluefromType" style="width: 182px" onchange="return CluefromOtherTypeSelected();">
<option value="Êг¡×ß·Ã">
Êг¡×ß·Ã
< ......