• <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 逛奔的蝸牛 閱讀(789) 評論(0)  編輯 收藏 引用 所屬分類: Cocoa
            久久91精品国产91久| 国内精品久久久久影院免费| 日日狠狠久久偷偷色综合0| 久久久久亚洲AV无码去区首| 久久久久国产一级毛片高清板 | 欧美亚洲国产精品久久| 久久久久久久精品妇女99| 久久国产亚洲高清观看| 久久99精品国产99久久6| 无码人妻久久一区二区三区蜜桃| 久久精品国产亚洲AV高清热 | 精品久久久久香蕉网| 久久91精品国产91久久户| 久久精品国产72国产精福利| 久久综合给合久久狠狠狠97色69| 欧美综合天天夜夜久久| 久久久久亚洲av成人网人人软件 | 中文字幕亚洲综合久久菠萝蜜| 亚洲精品tv久久久久久久久| 久久国产午夜精品一区二区三区| 久久婷婷五月综合色高清| 日本久久中文字幕| 99久久国产综合精品成人影院 | 国产三级久久久精品麻豆三级 | 亚洲乱亚洲乱淫久久| 久久ZYZ资源站无码中文动漫| 伊人久久大香线蕉AV一区二区 | 国产韩国精品一区二区三区久久| 亚洲国产成人精品无码久久久久久综合| 久久久久久亚洲精品成人| 久久精品青青草原伊人| 性做久久久久久久久浪潮| 久久久WWW成人免费精品| 99久久精品国产一区二区三区| 潮喷大喷水系列无码久久精品| 亚洲AV无码久久寂寞少妇| 久久久噜噜噜久久中文字幕色伊伊 | 97精品伊人久久久大香线蕉| 亚洲天堂久久久| 久久婷婷五月综合色奶水99啪| 亚洲乱码日产精品a级毛片久久|