• <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 逛奔的蝸牛 閱讀(795) 評論(0)  編輯 收藏 引用 所屬分類: Cocoa
            久久久久久久免费视频| 色婷婷久久久SWAG精品| av无码久久久久不卡免费网站| 亚洲国产精品久久久天堂| 久久精品国产亚洲AV无码娇色| 情人伊人久久综合亚洲| 午夜精品久久影院蜜桃| 精品久久久久久| 99久久夜色精品国产网站 | 亚洲国产小视频精品久久久三级| 久久成人小视频| 免费观看久久精彩视频 | 亚洲AV无码久久精品狠狠爱浪潮| 精品久久777| 色妞色综合久久夜夜| 亚洲精品tv久久久久| 久久综合九色综合精品| 亚洲精品无码久久久久| 四虎影视久久久免费观看| 婷婷久久综合九色综合98| 久久久亚洲AV波多野结衣| 国产精品女同一区二区久久| 久久一日本道色综合久久| 伊人久久亚洲综合影院| 久久精品国产99久久香蕉| 99国产欧美精品久久久蜜芽| 国内精品伊人久久久久777| 综合久久精品色| 欧美久久综合九色综合| 久久www免费人成精品香蕉| 99久久婷婷国产综合精品草原| 久久精品国产亚洲精品2020| 亚洲精品无码久久千人斩| 亚洲精品国产字幕久久不卡| 久久久久久久97| 久久久久久无码Av成人影院| 久久天天躁狠狠躁夜夜avapp| 欧美黑人激情性久久| 国内精品久久人妻互换| 久久青草国产手机看片福利盒子| 久久精品国产免费|