• <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://m.shnenglu.com/CuteSoft_Client/CuteEditor/Load.ashx?type=style&file=SyntaxHighlighter.css);@import url(/css/cuteeditor.css);
            posted on 2011-12-18 17:57 逛奔的蝸牛 閱讀(789) 評論(0)  編輯 收藏 引用 所屬分類: Cocoa
            91精品婷婷国产综合久久| 久久男人Av资源网站无码软件| 久久精品国产一区二区三区日韩| 国产精品久久久久久影院| 久久91这里精品国产2020| 亚洲va久久久噜噜噜久久| 99久久国产综合精品五月天喷水 | 2020久久精品亚洲热综合一本| 久久亚洲精品无码VA大香大香| 99国产精品久久久久久久成人热| 亚洲欧美日韩久久精品| 97久久精品无码一区二区| 久久夜色精品国产噜噜亚洲a| 久久亚洲国产精品一区二区| 午夜视频久久久久一区 | 久久亚洲sm情趣捆绑调教| 狠狠色丁香久久婷婷综合五月| 久久露脸国产精品| 女人香蕉久久**毛片精品| 久久久久亚洲精品日久生情| 久久综合久久伊人| 久久精品中文字幕一区| 狠色狠色狠狠色综合久久| 欧美黑人又粗又大久久久| 久久久久亚洲AV成人网人人软件 | 久久久久高潮毛片免费全部播放| 性做久久久久久免费观看| 久久精品国产精品亚洲人人| 国产精品永久久久久久久久久| 久久久国产精品网站| 国产婷婷成人久久Av免费高清| 久久无码人妻一区二区三区午夜| 久久妇女高潮几次MBA| 久久九九兔免费精品6| 亚洲精品乱码久久久久久| 亚洲AV无码久久精品狠狠爱浪潮| 99久久国产综合精品女同图片| 久久精品人妻中文系列| 亚洲狠狠婷婷综合久久久久| 人妻少妇久久中文字幕| 久久精品黄AA片一区二区三区|