• <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>

            逛奔的蝸牛

            我不聰明,但我會很努力

               ::  :: 新隨筆 ::  ::  :: 管理 ::

            There's a class called NSXMLParser. It's used to parse XML files. However, NSXMLParser is stupid. All it knows how to do is parse XML, but it doesn't know what it's supposed to do with the information it finds.

            Enter a delegate. A delegate is like a nanny. Since the XMLParser doesn't have a clue what to do with the information it finds, it goes and asks its delegate about each and every thing: "Hey! I started parsing a document! Am I supposed to do anything?" "Hey! I found some CDATA! What am I supposed to do with it!" "Hey! I found another tag!" "Hey! I found a closing tag!", and so on. All of these "Hey!" statements are delegate methods, or in other words, they are optional methods that a delegate object may choose to implement. Usually (but not always), the object that creates the NSXMLParser is also the delegate, but that doesn't have to be the case.

            So you might have something like this:

            NSXMLParser * parser = [[NSXMLParser alloc] initWithContentsOfURL:someURLToAnXMLFile];
            [parser setDelegate:self];
            [parser parse];
            [parser release];

            Then in that same object (self), you might have some of these methods:

            - (void)parserDidStartDocument:(NSXMLParser *)parser {
             
            //the parser started this document. what are you going to do?
            }

            - (void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qualifiedName attributes:(NSDictionary *)attributeDict {
             
            //the parser found an XML tag and is giving you some information about it
             
            //what are you going to do?
            }

            - (void)parser:(NSXMLParser *)parser foundCharacters:(NSString *)string {
             
            //the parser found some characters inbetween an opening and closing tag
             
            //what are you going to do?
            }

            - (void)parserDidEndDocument:(NSXMLParser *)parser {
             
            //the parser finished. what are you going to do?
            }

            There are a whole bunch of these methods listed in the documentation. Simply go to the NSXMLParser class reference, and they're all listed under the "Delegate Methods" section. Once you get the hang of it, NSXMLParser is pretty easy to use. It is a SAX Parser, which means it's event-driven parser. It finds stuff, and it tells you about it.


            From: http://stackoverflow.com/questions/1089737/parsing-xml-in-cocoa

            @import url(http://www.shnenglu.com/CuteSoft_Client/CuteEditor/Load.ashx?type=style&file=SyntaxHighlighter.css);@import url(/css/cuteeditor.css);
            posted on 2011-12-18 17:57 逛奔的蝸牛 閱讀(787) 評論(0)  編輯 收藏 引用 所屬分類: Cocoa
            久久久精品无码专区不卡| 久久精品成人免费看| 国产精品美女久久福利网站| 久久亚洲精品无码VA大香大香| 久久人人爽人人爽人人片AV高清| 久久精品国产亚洲av影院| 久久99精品久久久久久9蜜桃| 77777亚洲午夜久久多人| 久久精品国产69国产精品亚洲| 人妻无码久久精品| 国产欧美一区二区久久| 久久精品日日躁夜夜躁欧美| 国产三级观看久久| 欧美一区二区三区久久综 | 久久久久亚洲av成人网人人软件| 久久久久久国产精品免费无码| 久久久国产精华液| 日韩欧美亚洲综合久久影院d3| 成人久久免费网站| 亚洲国产成人久久综合野外 | 久久久久这里只有精品| 99国产精品久久| 亚洲av成人无码久久精品| 青青草国产97免久久费观看| 久久综合丝袜日本网| 精品久久人妻av中文字幕| 亚洲精品蜜桃久久久久久| 久久99热这里只频精品6| 伊人久久亚洲综合影院| 久久久久久久久久免免费精品| 99久久精品国产一区二区| 久久本道伊人久久| 久久国产乱子伦精品免费强| 热re99久久6国产精品免费| 色婷婷久久综合中文久久蜜桃av | 久久久久久久久无码精品亚洲日韩| 久久99热这里只频精品6| 伊人精品久久久久7777| 久久婷婷五月综合97色直播| 亚洲人成网站999久久久综合 | 久久天天日天天操综合伊人av|