// 4. Parsing Data // 4.1 Creating an XML Parser: SAX Nsxmlparser *parser = [[Nsxmlparser alloc]initwithdata:data]; // 4.2 Setting up proxies Parser. delegate = self ; // 4.3 start parsing, blocking [Parser parse];
//1. When you start parsing XML documents-(void) Parserdidstartdocument: (Nsxmlparser *) parser{NSLog (@"%s", __func__);}//2. Start parsing an element-(void) Parser: (Nsxmlparser *) parser didstartelement: (NSString *) elementname NamespaceURI: (NSString *) NamespaceURI QualifiedName: (NSString *) QName attributes: (nsdictionary<nsstring *,nsstring *> *) attributedict{NSLog (@"start parsing%@---%@", elementname,attributedict); //filter the root element if([ElementName isequaltostring:@"Videos"]) { return; } //Dictionary Turn Model[Self.videos addobject:[xmgvideo mj_objectwithkeyvalues:attributedict];}//3. An element parsing is complete-(void) Parser: (Nsxmlparser *) parser didendelement: (NSString *) elementname NamespaceURI: (NSString *) NamespaceURI QualifiedName: (NSString *) qname{NSLog (@"End parsing%@", elementname);}//4. End parsing-(void) Parserdidenddocument: (Nsxmlparser *) parser{NSLog (@"%s", __func__);}
Ios-oc-xml parsing-Nsxmlparser