• <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
            亚洲欧美国产日韩综合久久| 亚洲va久久久噜噜噜久久男同| 国产Av激情久久无码天堂| 漂亮人妻被中出中文字幕久久| 久久久久久无码国产精品中文字幕| 久久精品无码av| 久久中文字幕人妻熟av女| 日韩人妻无码精品久久久不卡| 国产欧美一区二区久久| 狠狠久久综合| 久久精品国产99国产精品导航 | 99久久精品国产免看国产一区| 国产午夜福利精品久久2021| 国产成人精品久久综合| 国产69精品久久久久APP下载| 国内精品久久人妻互换| 亚洲精品视频久久久| 狠狠色婷婷久久一区二区三区| 欧洲国产伦久久久久久久| 久久精品蜜芽亚洲国产AV| 亚洲天堂久久久| 91精品国产91久久| 精品免费久久久久久久| 亚洲欧美一区二区三区久久| 久久青青草原国产精品免费| 色欲久久久天天天综合网| 青青青青久久精品国产h久久精品五福影院1421 | 久久久精品久久久久影院| 久久99精品久久久久子伦| 天堂无码久久综合东京热| 久久国产高清字幕中文| 成人午夜精品无码区久久| 久久精品国产亚洲av水果派| 久久九九久精品国产免费直播| 久久综合狠狠综合久久综合88 | 粉嫩小泬无遮挡久久久久久| 久久久国产精华液| 性做久久久久久免费观看| 狠狠精品久久久无码中文字幕 | 精品综合久久久久久88小说| 精品国产91久久久久久久|