objective c xml½âÎö
½ñÌìÔÚCCÉÏ¿´µ½evangelÔÚÕÐÈË£¬ÉÏÃæдÁËÒ»ÌõÊý¾Ý½âÎö£¬ÎÒÏëÓ¦¸Ã¾ÍÊǶÔXMLµÄ½âÎö°É£¬ÔÝÇÒÕâÑùÀí½âÁË£¬ºÇºÇ¡£ÏÂÎçËÑË÷ÁËÒ»µã¶«Î÷×Ô¼ºÅªÁËÒ»¸öXMLÈ»ºó¶Á¶Á¿´¿´£¬ÏÖÔÚ½ö½öÊǶÁ³öÁËһЩ¶«Î÷£¬Ïȱ£´æ´úÂ룬´ýºóÐø¸üУ¡
Õâ¸öÊÇÎÒ´´½¨µÄxmlÎļþ£¬ÓÃÓÚ²âÊÔÓõģº
<?xml version="1.0" encoding="UTF-8"?>
<book>
<book1>
<author>zhangsan</author>
<title>Hello this is book1</title>
<content>book1 is very good for testing!</content>
</book1>
<book2>
<author>lisi</author>
<title>Hello this is book2</title>
<content>book2 is very good for testing!</content>
</book2>
<book3>
<author>wangwu</author>
<title>Hello this is book3</title>
<content>book3 is very good for testing!</content>
</book3>
</book>
¶Ôxml½øÐнâÎöÐèҪʹÓÃNSXMLParserÀ࣬Ê×ÏÈÉùÃ÷Ò»¸öNSXMLParser¶ÔÏó
NSXMLParser *xmlRead;
NSString *path = [[NSBundle mainBundle] pathForResource:@"test" ofType:@"xml"];
NSFileHandle *file = [NSFileHandle fileHandleForReadingAtPath:path];
NSData *data = [file readDataToEndOfFile];//µÃµ½xmlÎļþ
[file closeFile];
xmlRead = [[NSXMLParser alloc] initWithData:data];//³õʼ»¯NSXMLParser¶ÔÏó
[data release];
[xmlRead setDelegate:self];//ÉèÖÃNSXMLParser¶ÔÏóµÄ½âÎö·½·¨´úÀí
BOOL success = [xmlRead parse];//µ÷ÓôúÀí½âÎöNSXMLParser¶ÔÏ󣬿´½âÎöÊÇ·ñ³É¹¦
//½âÎöÆ÷£¬´ÓÁ½¸ö½áµãÖ®¼ä¶ÁÈ¡ÄÚÈÝ
- (void)parser:(NSXMLParser *)parser foundCharacters:(NSString *)string {
NSLog(string);
}
//»ñµÃ½áµã½áβµÄÖµ
- (void)parser:(NSXMLParser *)parser didEndElement:(NSString *)elementName
namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName {
NSLog(elementName);
}
//»ñµÃ½áµãÍ·µÄÖµ
- (void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName
Ïà¹ØÎĵµ£º
·´ÉäÊÇ Java ÓïÑÔ±»ÊÓΪ¶¯Ì¬»ò×¼¶¯Ì¬ÓïÑÔµÄÒ»¸ö¹Ø¼üÐÔÖÊ£¬½áºÏ·´ÉäºÍ XML »á°ïÖúÎÒÃǸü¿ì¡¢¸ü·½±ãµØʵÏÖһЩ¶¯Ì¬´úÂ룬´Ó¶ø½â¾ö±à³ÌÖпÉÄÜÓöµ½µÄ²»È·¶¨ÎÊÌâ¡£±¾ÎĽ«½áºÏ·´ÉäÓë XML ¶Ô Java ±à³ÌµÄ¶¯Ì¬ÐÔ½øÐÐÉîÈëdz³öµÄÌÖÂÛ¡£ÔÚÀí½â±¾ÎĵÄ˼ÏëÖ®ºó£¬Äú¿ÉÒÔ½«ÆäÓ¦Óõ½³ÌÐòÖÐÒÔ´´½¨Áé»îµÄ´úÂë¡£
ÒýÑÔ
ÔÚÏÖʵÉú»îÖУ¬¾³£»á·¢ ......
·Ç³£»ù±¾¹ØÓÚCÓïÑÔµÄÎÊÌâ,Ò»¸öÐÅÏ¢Àà(¼ÆËã»ú,×ÊѶ¹¤³Ì,µç×Ó¹¤³Ì, ͨÐŹ¤³Ì)רҵµÄ±¾¿Æ±ÏÒµÉúÓ¦¸Ã´ïµ½µÄˮƽ¡£ÌâÄ¿²»ÄÑ,È«²¿¶¼ÄÜ¿ìËٵشðÍ꣬µ±È»Ò²ÐèÒªÒ»¶¨µÄ֪ʶ´¢±¸¡£
¶ÔÓÚ´ó¶àÊýÈË£¬ÎÒÃÇÔ¤ÆÚÄã¿ÉÄÜ´ð´í 3) 4) 15)Ì⣬ËùÒÔ´ð´í3µÀÒÔÄڵģ¬ÎÒÃÇÈÏΪÄãºÜ°ô
´ð´í5µÀÌâÒÔÄÚ£¬ÎÒÃÇÈÏΪÄ㻹²»´í(Ä㻹¿ÉÄÜ´ð ......
Ïêϸ²Î¿¼´ð°¸
µÚ1Ìâ: (b)
volatile×ÖÃæÒâ˼ÊÇÒ×ÓÚ»Ó·¢µÄ¡£Õâ¸ö¹Ø¼ü×ÖÀ´ÃèÊöÒ»¸ö±äÁ¿Ê±£¬Òâζ×Å ¸ø¸Ã±äÁ¿¸³Öµ(дÈë)Ö®ºó£¬ÂíÉÏÔÙ¶ÁÈ¡£¬Ð´ÈëµÄÖµÓë¶ÁÈ¡µÄÖµ¿ÉÄܲ»Ò»Ñù,ËùÒÔ˵Ëü"ÈÝÒ×»Ó·¢"µÄ¡£
ÕâÊÇÒòΪÕâ¸ö±äÁ¿¿ÉÄÜÒ»¸ö¼Ä´æÆ÷£¬Ö±½ÓÓëÍⲿÉ豸ÏàÁ¬£¬ÄãдÈëÖ®ºó£¬¸Ã¼Ä´æÆ÷Ò²ÓпÉÄܱ»ÍⲿÉ豸µÄд²Ù×÷Ëù¸Ä±ä;»òÕ ......
À©Õ¹±ê¼ÇÓïÑÔXML£¨eXtensible Markup Language£©£¬ÊÇÓÉW3C×éÖ¯Öƶ¨µÄ¡£×öΪÓÃÓÚÌæ´úHTMLÓïÑÔµÄÒ»ÖÖÐÂÐ͵ıê¼ÇÓïÑÔ£¬XMLÄÚ²¿ÓÐןܶà»ù±¾±ê×¼£¬XML¾ÍÊÇͨ¹ýÓëÕâЩÏà¹Ø±ê×¼µØ½áºÏ£¬Ó¦ÓÃÓÚ¿Æѧ¼ÆËã¡¢µç×Ó³ö°æ¡¢¶àýÌåÖÆ×÷ºÍµç×ÓÉÌÎñµÄ¡£C££×÷ΪһÖÖÐÂÐ͵ijÌÐòÓïÑÔ£¬ÊÇ.Net¿ò¼ÜµÄÒ»¸öÖØÒª×é³É²¿·Ö£¬ËûºÍXMLµÄ¹ØϵÆÄÉî¡£±¾ÎÄ¾Í´Ó ......
ÔÚPerlÖнâÎöXMLµÄ·½·¨×î³£¼ûµÄ¾ÍÊÇʹÓà XML::DOM
ºÍ XML::SimpleÁË¡£
XML::DOM¹ýÓÚÅӴ󣬶øÇÒ½âÎö½á¹ûÊÇÒ»¸öDOMÊ÷£¬²Ù×÷Ò²²»·½±ã¡£
¶ÔÓÚСÐÍÇÒ²»¸´ÔÓµÄXMLÎļþ£¬XML::DOMÕæÊÇɱ¼¦ÓÃÅ£µ¶¡£
Õâʱ¾ÍÂÖµ½Çá±ãµÄXML::SimpleÉϳ¡ÁË¡£
XML::SimpleÈçÆäÃû£¬ÕæµÄºÜ¼òµ¥¡£¼ÙÉèXMLÄÚÈÝÈçÏ£º
<opt>
<user login= ......