discuss-gnustep
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

objective c NSXMLParser delegate class doesn't trigger delegate methods


From: umen
Subject: objective c NSXMLParser delegate class doesn't trigger delegate methods
Date: Sun, 3 Feb 2013 06:11:10 -0800 (PST)

i following simple  tutorial
<http://wiki.cs.unh.edu/wiki/index.php/Parsing_XML_data_with_NSXMLParser>  
on the web to parse xml with NSXMLParser. 
the delegate object does init , but never trigger the NSXMLParser delegate
methods . 
what im doing wrong ? 
im using GNUSetup on windows . 

here is where i call the parser :

    -(BOOL) loadXmlPath :(NSString*)filePathXml:(NSString*) filePathWrite
    {
        if([fileMgr fileExistsAtPath:filePathXml] == YES)
        {
                NSLog(@"%@",filePathXml);               
                NSURL *xmlURL = [NSURL fileURLWithPath:filePathXml]; 
                NSXMLParser *nsXmlParser = [[NSXMLParser alloc]
initWithContentsOfURL:xmlURL];
                if(nsXmlParser)
                {
                         NSLog(@"done setup parser");
                }
                else
                {
                         NSLog(@"fail setup parser");
                }
                // create and init our delegate
                XMLParser *parser = [[XMLParser alloc] initXMLParser];
                [nsXmlParser setShouldProcessNamespaces:NO]; // We don't care 
about
namespaces
                [nsXmlParser setShouldReportNamespacePrefixes:NO]; //
                [nsXmlParser setShouldResolveExternalEntities:NO]; // We just 
want data,
no other stuff
                // set delegate
                [nsXmlParser setDelegate:parser];
                // parsing...
                BOOL success = [nsXmlParser parse];
                  // test the result
                if (success) {
                         NSLog(@"parsing document!");
                         // get array of users here
                } else {
                    if ([nsXmlParser parserError]) {
                                NSError *err = [nsXmlParser parserError];
                                NSString *serror = [err localizedDescription];
                                NSLog(@"Error parsing document!%@\n",serror);
                        }
                        NSLog(@"Error parsing document!");
                }
        }
        return NO;
    }


XmlParser.h

    #import <Foundation/Foundation.h>
    
    @interface XMLParser : NSObject 
    {
        NSXMLParser *parser;
         
    
    }
    -(XMLParser *) initXMLParser;
    -(void)parser:(NSXMLParser *)parser didStartElement:(NSString
*)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString
*)qName attributes:(NSDictionary *)attributeDict;
    - (void)parser:(NSXMLParser *)parser foundCharacters:(NSString *)string;
    - (void)parser:(NSXMLParser *)parser didEndElement:(NSString
*)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString
*)qName;
     
    @end


XmlParser.m 


    #import "XMLParser.h"
    @implementation XMLParser
    
     
    
    - (XMLParser *) initXMLParser {
       self = [super init];
        NSLog(@"Init xml parser");
       
      return self;
    }
    
      
    - (void)parser:(NSXMLParser *)parser didStartElement:(NSString
*)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString
*)qName attributes:(NSDictionary *)attributeDict {
     
         NSLog(@"Enter parser 1");
        if ( [elementName isEqualToString:@"name"]) {
        NSLog(@"%@",elementName);
      
            return;
        }
     
        if ( [elementName isEqualToString:@"person"] ) {
       
            return;
        }
     
        if ( [elementName isEqualToString:@"lastName"] ) {
            
            return;
        }
        
    }
    
    - (void)parser:(NSXMLParser *)parser foundCharacters:(NSString *)string
{
        NSLog(@"Enter parser 2");
       
    }
    
    - (void)parser:(NSXMLParser *)parser didEndElement:(NSString
*)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString
*)qName {
        NSLog(@"Enter parser 3");
        
        if (( [elementName isEqualToString:@"addresses"]) ||
            ( [elementName isEqualToString:@"address"] )) return;
     
        if ( [elementName isEqualToString:@"person"] ) {
          
            return;
        }
        
    }
    
    @end


its never reach to the parser methods . but its do reach to the
initXMLParser .
what do i do wrong here ?
also im getting in the :[err localizedDescription]
this msg : 

> NSXMLParserErrorDomain 3

what does  it mean ?

 



--
View this message in context: 
http://gnustep.8.n7.nabble.com/objective-c-NSXMLParser-delegate-class-doesn-t-trigger-delegate-methods-tp32522.html
Sent from the GNUstep - General mailing list archive at Nabble.com.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]