Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4084800
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T18:29:11+00:00 2026-05-20T18:29:11+00:00

i want to read a HTML File with this command: parseHTML = [[NSXMLParser alloc]

  • 0

i want to read a HTML File with this command:

parseHTML = [[NSXMLParser alloc] initWithContentsOfURL:[NSURL URLWithString:[@"http://theurl.com"]];    
[parseHTML setDelegate:self];
[parseHTML parse];

in the didStartElement method i want to stop the actual parser after he found a specified string and parse a new site with these information:

- (void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qualifiedName attributes:(NSDictionary *)attributeDict
{
    if(somethingfound)
    {
            [parseHTML abortParsing];
            parseHTML2 = [[NSXMLParser alloc] initWithContentsOfURL:[NSURL URLWithString:[@"http://theurl.com" stringByAppendingString:product_link]]];
            [parseHTML2 setDelegate:self];
            [parseHTML2 parse];
    }
}

i get an irregular error:

Thread1: Program received signal: “EXC
BAD ACCESS”

any ideas?
regards


Hello Walter thanks for your comment, here is the complete implementation:
I hope it helps… :-/

FirstViewController.h

#import <UIKit/UIKit.h>

@interface FirstViewController : UIViewController <ZBarReaderDelegate, NSXMLParserDelegate>{

    UIImageView *resultImage;
    UITextView *resultText;
    NSString *product_link;
    NSXMLParser *parseHTML;
    NSXMLParser *parseHTML2;

}
@property (nonatomic, retain) IBOutlet UIImageView *resultImage;
@property (nonatomic, retain) IBOutlet UITextView *resultText;
@property (nonatomic, assign) IBOutlet NSString *product_link;
@property (nonatomic, assign) NSXMLParser *parseHTML;
@property (nonatomic, assign) NSXMLParser *parseHTML2;
@property (nonatomic, retain) NSMutableArray *myMutableArray;

- (IBAction) scanButtonTapped;

@end

FirtViewController.m

#import "FirstViewController.h"
#import "/System/Library/Frameworks/Foundation.framework/Headers/NSDebug.h"

@implementation FirstViewController


@synthesize resultImage, resultText;
@synthesize product_link;
@synthesize parseHTML, parseHTML2;


bool link_is_here = false;
bool allergy_is_here = false; 
bool parse_one_ok = true;
int hoch = 0;


- (IBAction) scanButtonTapped
{
    NSZombieEnabled = true;

    // ADD: present a barcode reader that scans from the camera feed
    ZBarReaderViewController *reader = [ZBarReaderViewController new];
    reader.readerDelegate = self;

    ZBarImageScanner *scanner = reader.scanner;
    // TODO: (optional) additional reader configuration here

    // EXAMPLE: disable rarely used I2/5 to improve performance
    [scanner setSymbology: ZBAR_I25
                   config: ZBAR_CFG_ENABLE
                       to: 0];

    // present and release the controller
    [self presentModalViewController: reader animated: YES];
    [reader release];
}

- (void) imagePickerController: (UIImagePickerController*) reader
 didFinishPickingMediaWithInfo: (NSDictionary*) info
{

    // ADD: get the decode results
    id<NSFastEnumeration> results = [info objectForKey: ZBarReaderControllerResults];
    ZBarSymbol *symbol = nil;
    for(symbol in results)
        break;

    // EXAMPLE: do something useful with the barcode data
    resultText.text = symbol.data;
    parseHTML = [[[NSXMLParser alloc] initWithContentsOfURL:[NSURL URLWithString:[@"http://URL.de/suche/?q=" stringByAppendingString:symbol.data]] ]autorelease];
    [parseHTML setDelegate:self];
    [parseHTML parse];

//    [parseHTML release];

    // EXAMPLE: do something useful with the barcode image
    resultImage.image =
    [info objectForKey: UIImagePickerControllerOriginalImage];

    // ADD: dismiss the controller (NB dismiss from the *reader*!)
    [reader dismissModalViewControllerAnimated: YES];
}


- (void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qualifiedName attributes:(NSDictionary *)attributeDict
{
    for(NSString *key in [attributeDict allKeys]) {
        if ([[attributeDict valueForKey:key] isEqualToString:@"some_string"]) {
            link_is_here = true;        
        }
        if ([key isEqualToString:@"href"] && link_is_here) {
            product_link = [attributeDict valueForKey:key];

//            [parseHTML abortParsing];

            parseHTML2 = [[NSXMLParser alloc] initWithContentsOfURL:[NSURL URLWithString:[@"http://URL.de" stringByAppendingString:product_link]]];
            [parseHTML2 setDelegate:self];
            [parseHTML2 parse];
            parse_one_ok = true;
            link_is_here = false;
        }
        if ([key isEqualToString:@"id"] && [[attributeDict valueForKey:key] isEqualToString:@"other_string"]) {
            allergy_is_here = true;
        }
        if ([key isEqualToString:@"title"] && allergy_is_here) {      
            NSLog(@"DO:  %@",[attributeDict valueForKey:key]);  
        }
        if ([key isEqualToString:@"id"] && [[attributeDict valueForKey:key] isEqualToString:@"string"]) {
            allergy_is_here = false;

            parse_one_ok = true;
            NSLog(@"Parser off");
            //close all parser
        }
     }
}
-(void) parserDidEndDocument:(NSXMLParser *)parser{
    [parseHTML setDelegate:nil];
    [parseHTML2 setDelegate:nil];
    [parseHTML release];
    if (parse_one_ok) {

        [parseHTML2 release];
    }
}

- (void)didReceiveMemoryWarning {
    // Releases the view if it doesn't have a superview.
    [super didReceiveMemoryWarning];

    // Release any cached data, images, etc that aren't in use.
}

- (void)viewDidUnload {
    // Release any retained subviews of the main view.
    // e.g. self.myOutlet = nil;
}


- (void)dealloc {
    [parseHTML release];
    [parseHTML2 release];
    self.product_link = nil;
    self.resultImage = nil;
    self.resultText = nil;
    [super dealloc];
}

@end

hey my declaration is in the header:

@interface FirstViewController : UIViewController <NSXMLParserDelegate>{
    NSString *product_link;
    NSXMLParser *parseHTML;
    NSXMLParser *parseHTML2;
}
@property (nonatomic, retain) IBOutlet NSString *product_link;
@property (nonatomic, retain) NSXMLParser *parseHTML;
@property (nonatomic, retain) NSXMLParser *parseHTML2;

and in the source:

@synthesize parseHTML, parseHTML2;
@synthesize product_link;

i get these exception in console:

-[NSCFString setDelegate:]: unrecognized selector sent to instance
0x1acad0

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-20T18:29:11+00:00Added an answer on May 20, 2026 at 6:29 pm

    When I have to parse two files at once I set up a second delegate for the second file. The delegate is a simple NSObject that adheres to the NSXML Parser Delegate protocol. (It has the parserDidStart, parserDidEnd, blah blah blah).

    Then in my didEndElement of my first parser I kick off the second parser with something like this

    SoundCloudParser *scParser = [[[SoundCloudParser alloc] init]autorelease];
    NSOperationQueue *queue = [[[NSOperationQueue alloc] init]autorelease];
    NSInvocationOperation *operation = [[NSInvocationOperation alloc] initWithTarget:scParser selector:@selector(parseXMLUrl:) object:currentArticle.uriString];
    [queue addOperation:operation];
    [operation release];  
    

    I do it on a separate thread which is why you have the queue in there. My ‘parseXMLUrl:looks just like a regular one, it just sets the delegate to my second delegate object instead of setting it toself`.

    One other thing you need to think about is that you are doing work at the didStartElement and I find that a lot of times I don’t have any values in my parsing variables until I get to didEndElement. That would be something else for you to check.

    UPDATE: In the future, if you are trying to build on something like ZBarSDK or another project, please say so. It would have saved me about half an hour of messing around with your code.
    Basically what we need to do is to set up a new delegate. Let’s call it newDelegate. Set it up as a regular NSObject and make it follow <NSXMLDelegate> protocol. It needs a mutableArray or a dictionary to store the data it will parse and it needs a function to kick it off. And that’s about it.
    So, let’s assume you have created newDelegate.h and newDelegate.m in your project and in newDelegate.h you have
    #import “Your_App_Delegate.h”
    @interface newDelegate : NSObject {

    NSMutableString *currentElement;
    NSMutableArray *currentArticle;
    }
    
    - (void)parseXMLUrl:(NSString *)URL;
    @end
    

    So, now in your didStartElement you would call the newDelegate like this:

    newDelegate *ndParser = [[[newDelegateParser alloc] init]autorelease];
    NSOperationQueue *queue = [[[NSOperationQueue alloc] init]autorelease];
    NSInvocationOperation *operation = [[NSInvocationOperation alloc] initWithTarget:ndParser selector:@selector(parseXMLUrl:) object:[NSString stringWithFormat:@"http://URL.de/%@",product_link]];
    [queue addOperation:operation];
    [operation release];    
    

    This would kick off the second parser and pass it the url to parse. You will need a way to get that data, so either store some results in your App Delegate or else change the parseXMLURL method of the second parser to return some value.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to read the html file.And for that I use System.IO.File.ReadAllText(path) .It can
I want to read the file path from html input type=file (the entry selected
I want to read a single file (the file is a html document) from
I want to read a word html file and grab any words which contain
I want to ask how can someone read keystrokes while in a html page
I have a text file. I want read that file. But In that if
I want to read line n1->n2 from file foo.c into the current buffer. I
I want to read data from a CFG (configuration file). How do I read
I want to produce a simple, static HTML file, that has one or more
So I made a UIWebView and I had it read a local help.html file.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.