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 3788200
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T11:57:40+00:00 2026-05-19T11:57:40+00:00

This is similar to my previous question. I didn’t get an answer, maybe by

  • 0

This is similar to my previous question. I didn’t get an answer, maybe by changing the question I might get an answer.

Here is my parsing code:

-(void) parser:(NSXMLParser *) parser  didStartElement:(NSString *) elementName  
                                          namespaceURI:(NSString *) namespaceURI  
                                         qualifiedName:(NSString *) qName   
                                            attributes:(NSDictionary *) attributeDict 
{
    if ([elementName isEqualToString:kimgurl]
        || [elementName isEqualToString:kone_x]
        || [elementName isEqualToString:kone_y]
        || [elementName isEqualToString:kone_radius]
        || [elementName isEqualToString:ktwo_x]
        || [elementName isEqualToString:ktwo_y]
        || [elementName isEqualToString:ktwo_radius]) 
    {
        elementFound = YES;
        theItems = [[Items alloc] init];
    }
}


- (void)parser:(NSXMLParser *)parser didEndElement:(NSString *)elementName
                                      namespaceURI:(NSString *)namespaceURI
                                     qualifiedName:(NSString *)qName 
{   
    if([elementName isEqualToString:kimgurl])
    {
        theItems.imageURL = self.currentValue;
        [self.currentValue setString:@""];
    }

    else if([elementName isEqualToString:kone_x])
    {
        theItems.iOne_X = self.currentValue;
        [self.currentValue setString:@""];
    }

    else if([elementName isEqualToString:kone_y])
    {
        theItems.iOne_Y = self.currentValue;
        [self.currentValue setString:@""];
    }

    else if([elementName isEqualToString:kone_radius])
    {
        theItems.iOne_Radius = self.currentValue;
        [self.currentValue setString:@""];
    }

    else if([elementName isEqualToString:ktwo_x])
    {
        theItems.iTwo_X = self.currentValue;
        [self.currentValue setString:@""];
    }

    else if([elementName isEqualToString:ktwo_y])
    {
        theItems.iTwo_Y = self.currentValue;
        [self.currentValue setString:@""];
    }

    else if([elementName isEqualToString:ktwo_radius])
    {
        theItems.iTwo_Radius = self.currentValue;
        [self.currentValue setString:@""];
    }

}

-(void) parserDidEndDocument:(NSXMLParser *)parser 
{   
    NSLog(@"enddocument: %@", theItems.imageURL);
}


-(void)parser:(NSXMLParser *) parser foundCharacters:(NSString *)string 
{
    if (elementFound == YES) {
        if(!currentValue)
        {
            currentValue = [NSMutableString string];
        }

        [currentValue appendString: string];
    }
}

When I get to parserDidEndDocument. The theItems class is empty.

Here is Items.h

#import <Foundation/Foundation.h>


 @interface Items : NSObject {
     @private
     //parsed data
     NSString *imageURL;
     NSString *iOne_X;
     NSString *iOne_Y;
     NSString *iOne_Radius;
     NSString *iTwo_X;
     NSString *iTwo_Y;
     NSString *iTwo_Radius;
 }

@property (nonatomic, retain) NSString *imageURL;
@property (nonatomic, retain) NSString *iOne_X;
@property (nonatomic, retain) NSString *iOne_Y;
@property (nonatomic, retain) NSString *iOne_Radius;
@property (nonatomic, retain) NSString *iTwo_X;
@property (nonatomic, retain) NSString *iTwo_Y;
@property (nonatomic, retain) NSString *iTwo_Radius;


@end

here is Items.m

#import "Items.h"


@implementation Items
@synthesize imageURL;
@synthesize iOne_X;
@synthesize iOne_Y;
@synthesize iOne_Radius;
@synthesize iTwo_X;
@synthesize iTwo_Y;
@synthesize iTwo_Radius;

-(void)dealloc
{
    [imageURL release];
    [iOne_X release];
    [iOne_Y release];
    [iOne_Radius release];
    [iTwo_X release];
    [iTwo_Y release];
    [iTwo_Radius release];  
    [super dealloc];
}
@end

here is my RootViewController.h

#import <UIKit/UIKit.h>

@class Items;

@interface RootViewController : UIViewController <NSXMLParserDelegate> {
    NSMutableData *downloadData;
    NSURLConnection *connection;

    BOOL elementFound;
    NSMutableString *currentValue;
    NSMutableDictionary *pictures;

    //---xml parsing---
    NSXMLParser *xmlParser;

    Items *theItems;
    NSMutableArray *aItems;

}

@property (nonatomic, retain) Items *theItems;
@property (nonatomic, retain) NSMutableArray *aItems;
@property (nonatomic, retain) NSMutableString *currentValue;

@property (nonatomic, retain) NSMutableData *downloadData;
@property (nonatomic, retain) NSURLConnection *connection;

@end

xml file example

<?xml version="1.0" encoding="utf-8"?>
<data>
    <test>
        <url>url</url>
        <one_x>83</one_x>
        <one_y>187</one_y>
        <one_radius>80</one_radius>
        <two_x>183</two_x>
        <two_y>193</two_y>
        <two_radius>76</two_radius>
    </test>
</data>
  • 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-19T11:57:41+00:00Added an answer on May 19, 2026 at 11:57 am

    It looks like there are a couple of potential problems. In your didStartElement method you are alloc/init’ing a new Items object for every element and overwriting your previous one. Perhaps you can move the Items init into your –parserDidStartDocument: method. When you init, it should also look more like this:

    Items *items = [[Items alloc] init];
    self.theItems = items;
    [items release];

    Then you’ll have the correct retain count when you are done.

    I’d also recommend changing your NSString @property declarations to be copy instead of retain. The code:

    theItems.imageURL = self.currentValue;
    [self.currentValue setString:@""];
    

    … isn’t doing what you think. theItems.imageURL is going to be pointing at your NSMutableString and then you clear the mutable string right after which means imageURL is pointing at an empty mutable string. Then after all of the other iterations, all of them are pointing at the same NSMutableString which is empty. If you change the @property declarations to copy, then it’ll set imageURL to an immutable NSString copy of the contents of self.currentValue.

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

Sidebar

Related Questions

This is similar to a previous question , but the answers there don't satisfy
This is similar to my previous question but it didnt work with the Kindle
This is very similar to a previous question (and may be the exact same
I know this question is similar to several previous ones, but I can't find
I need to split this/similar string to get the VALUE <a href=javascript:void(0); id=def_ name=color
I found this similar question here , but this is really old. Was it
Similar to this previous question , I am having a problem with text alignment
This question is similar to my previous question but not the same ... please
I currently had a problem similar to this previous question: Why would our Java
this question is similar to my previous hover question ( converting css hover to

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.