• <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 逛奔的蝸牛 閱讀(784) 評論(0)  編輯 收藏 引用 所屬分類: Cocoa
            久久精品人人槡人妻人人玩AV| 99久久www免费人成精品| 亚洲精品乱码久久久久久| 嫩草伊人久久精品少妇AV| 久久国产精品久久| 久久只这里是精品66| 久久99国产精品99久久| 一本久久综合亚洲鲁鲁五月天亚洲欧美一区二区 | 国产亚州精品女人久久久久久 | 人妻无码精品久久亚瑟影视| 777米奇久久最新地址| 欧美久久一区二区三区| 久久99国产精品99久久| 亚洲中文字幕无码久久综合网| 99久久精品国产毛片| 久久精品a亚洲国产v高清不卡| 日韩精品久久久久久久电影| 伊人久久免费视频| 国产成人久久AV免费| 狠狠色丁香久久婷婷综合_中| 99久久www免费人成精品| 国产精品久久久久久久久鸭| 久久久久久久久久久精品尤物 | 尹人香蕉久久99天天拍| 婷婷综合久久狠狠色99h| 人妻精品久久无码区| 伊人久久大香线蕉成人| 久久人人爽人爽人人爽av| 色综合久久88色综合天天| 国产韩国精品一区二区三区久久| 亚洲AV乱码久久精品蜜桃| 久久乐国产综合亚洲精品| 亚洲伊人久久成综合人影院| 国产免费久久精品丫丫| segui久久国产精品| 久久se这里只有精品| 国内精品久久久久久久影视麻豆| 久久国产亚洲精品麻豆| 中文精品久久久久国产网址| 亚洲午夜久久久精品影院| 91久久精品电影|