questions of NSXMLParser

Discussion in 'iOS Programming' started by Ric0104, May 3, 2010.

  1. Ric0104 macrumors newbie

    Joined:
    May 3, 2010
    #1
    hi,everyone:

    when BOOL success = [firstParser parser]; nothing happend

    and i don't know why , i need some suggestion

    My code and XML :

    Code:
    <?xml version="1.0" encoding="windows-1250"?>
    <RootElement>
      <State>
        <Name>Arizona</Name>
        <Time>6 a.m.ñ2 a.m.</Time>
        <Time>6 a.m.</Time>
    	<Notes>This is a note for Ar</Notes>
      </State>
      <State>
        <Name>California</Name>
        <Time>CA Time.</Time>
        <Time>CA Time2.</Time>
        <Notes>This is a note for California</Notes>
      </State>
    </RootElement>
    Code:
    #import "XMLParserAppDelegate.h"
    #import "RootViewController.h"
    
    
    @implementation MyFirstXMLParserAppDelegate
    
    @synthesize window;
    @synthesize navigationController;
    
    
    #pragma mark -
    #pragma mark Application lifecycle
    
    - (void)applicationDidFinishLaunching:(UIApplication *)application {    
        
        // Override point for customization after app launch    
    	
    	[window addSubview:[navigationController view]];
        [window makeKeyAndVisible];
    }
    
    -(id)init{
    
    	self = [super init];
    	
    	
    	return self;
    }
    - (void)awakeFromNib {
        
    	
    	
    	printf("-------------");
    	
    	
    	NSString *paths = [[NSBundle mainBundle] resourcePath];
    	NSString *xmlFile = [paths stringByAppendingPathComponent:@"XMLTest.xml"];
    	if(xmlFile!=nil){
    		printf("00000000000000");
    	}
    	NSURL *xmlURL = [NSURL fileURLWithPath:xmlFile isDirectory:NO];
    	if(xmlURL!=nil){
    		printf("qqqqqqqqqqqqq00");
    	}
    	NSXMLParser *firstParser = [[NSXMLParser alloc] initWithContentsOfURL:xmlURL];
    	if(firstParser!=nil){
    		printf("aaaaaaaaaaaaaaaaa");
    	}
    	[firstParser setDelegate:self];
    	BOOL success = [firstParser parse];
    	if(success){
    	
    		printf("=================");
    	
    	}
    	if(!success){
    		[firstParser parse];
    		printf("99999999999999");
    		
    	}
    	
    }
    
    
    
    
    - (void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qualifiedName attributes:(NSDictionary *)attributeDict {
    	printf("\\jhjhhhhhhh");
    	if ([elementName isEqualToString:@"RootElement"]) {
    		
    	
    		printf("\\jhjhhhhhhh");
    	}
    }
    
    - (void)parserDidEndDocument:(NSXMLParser *)parser {
    	
    	[parser release];
    	
    }
    
    - (void)applicationWillTerminate:(UIApplication *)application {
    	// Save data if appropriate
    }
    
    
    #pragma mark -
    #pragma mark Memory management
    
    - (void)dealloc {
    	[navigationController release];
    	[window release];
    	[super dealloc];
    }
    
    
    @end
    
    
    thank you very much!!
     
  2. kainjow Moderator emeritus

    kainjow

    Joined:
    Jun 15, 2000
    #2
    What do you mean nothing happened? Are you sure your file URL is valid?
     
  3. Ric0104 thread starter macrumors newbie

    Joined:
    May 3, 2010
    #3
    I know why
    encoding="windows-1250"---->encoding="utf8"
     

Share This Page