• <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
            91精品国产91热久久久久福利| 亚洲中文字幕久久精品无码APP| 国产成人精品久久一区二区三区 | 久久99国产精品久久99| 久久精品国产99国产精品澳门| 色综合色天天久久婷婷基地| 久久国产视频网| 色欲综合久久中文字幕网| 久久久久综合网久久| 综合久久久久久中文字幕亚洲国产国产综合一区首 | 热久久视久久精品18| 久久久久亚洲精品天堂| 久久久久无码中| 久久99国产综合精品免费| 久久久久一本毛久久久| 国产精品九九九久久九九| 7777精品伊人久久久大香线蕉| 久久亚洲国产午夜精品理论片| 亚洲国产精品一区二区三区久久 | 国内精品免费久久影院| 人妻精品久久无码区| 亚洲精品高清一二区久久| 久久青青草原精品影院| 日韩精品久久久肉伦网站 | 97视频久久久| 热久久视久久精品18| 久久精品18| 国内精品欧美久久精品| 丁香五月综合久久激情| 久久国产精品-国产精品| 日韩AV无码久久一区二区| 久久久久久久波多野结衣高潮| 久久国产三级无码一区二区| 99久久国产热无码精品免费久久久久 | 日本WV一本一道久久香蕉| 人人狠狠综合88综合久久| 久久久久国产| 亚洲国产一成久久精品国产成人综合| 久久久久国色AV免费观看| 久久e热在这里只有国产中文精品99 | 国产成人无码精品久久久久免费|