• <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
            .精品久久久麻豆国产精品 | 91久久成人免费| 久久精品国产只有精品66| 欧美久久久久久精选9999| 午夜精品久久久久久久无码| 久久精品久久久久观看99水蜜桃| 性欧美大战久久久久久久久| 狠狠色婷婷综合天天久久丁香| 欧洲性大片xxxxx久久久| 亚洲精品高清国产一线久久| 色综合久久综合网观看| 伊人久久大香线蕉av一区| 久久亚洲国产精品一区二区| 久久久噜噜噜久久中文字幕色伊伊| 久久国产精品成人影院| 亚洲国产成人精品无码久久久久久综合 | 中文字幕人妻色偷偷久久| 国产精品欧美亚洲韩国日本久久| 一本久久免费视频| 超级碰久久免费公开视频| 久久精品aⅴ无码中文字字幕不卡 久久精品aⅴ无码中文字字幕重口 | 久久人人爽人人澡人人高潮AV | 久久精品中文字幕一区 | 国产亚洲精久久久久久无码77777| 久久这里只有精品久久| 久久综合久久自在自线精品自 | 久久天天躁狠狠躁夜夜avapp| 久久e热在这里只有国产中文精品99| 久久久无码精品亚洲日韩蜜臀浪潮| 伊人久久亚洲综合影院| 香蕉99久久国产综合精品宅男自 | 欧美精品久久久久久久自慰| 热99RE久久精品这里都是精品免费 | 狠狠色丁香久久婷婷综合五月| 伊色综合久久之综合久久| 久久精品中文字幕一区| 中文字幕亚洲综合久久2| 久久美女网站免费| 国产精品无码久久久久| 国产日韩久久免费影院 | 日本强好片久久久久久AAA |