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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T14:55:29+00:00 2026-05-28T14:55:29+00:00

At first i have imported #import GDataXMLNode.h in .h file. Now this is my

  • 0

At first i have imported #import "GDataXMLNode.h" in .h file. Now this is my XML which i have to parse using GDataXML parser.

<SiteStats>
   <visitor>1</visitor>
   <uniqueVisitor>1</uniqueVisitor>
   <orderCount>0</orderCount>
   <revenue>null</revenue>
   <conversionRate>0</conversionRate>
   <newProduct>3</newProduct>
   <outOfStockProduct>0</outOfStockProduct>
</SiteStats>

Now, one thing to notice is that my this xml is coming from web. So I have used NSUrlConnection delegate to retrieve xml data.

- (void)connectionDidFinishLoading:(NSURLConnection *)connection {
    responseString = [[NSString alloc] initWithData:receivedData encoding:NSUTF8StringEncoding];
    NSLog(@"Response: %@",responseString);
    // other stuff here...
}

Here I get the responseString and then I parse it using the following code. But I’m not able to parse it.

 xmlDocument = [[GDataXMLDocument alloc] initWithXMLString:responseString options:0 error:&errorOnStore];
if (nil == xmlDocument)    {
    NSLog(@"could not load xml file");
}
else    {
    NSLog(@"Loading desire xml");
    NSLog(@"%@", xmlDocument.rootElement);
    NSArray *getData = [[xmlDocument rootElement] elementsForName:@"SiteStats"];
    NSLog(@"%@",getData);
    records = [[NSMutableArray alloc] init];
    //[records retain];
    if(getData.count !=0 ){
        NSLog(@"data has");
    }
    //storing the car model in the mutable array
    for(GDataXMLElement *e in getData){
        NSLog(@"Enering in the xml file");
        [records addObject:e];

        NSString *Visitor = [[[e elementsForName:@"visitor"] objectAtIndex:0] stringValue];
        NSLog(@"Visitor : %@",Visitor);

        NSString *UVisitor = [[[e elementsForName:@"uniqueVisitor"] objectAtIndex:0] stringValue];
        NSLog(@"Unique Visitor : %@",UVisitor);
    }
}

I can get this value when i NSLog(@"%@", xmlDocument.rootElement);

 GDataXMLElement 0x1a4290: {type:1 name:SiteStats xml:"<SiteStats><visitor>4</visitor><uniqueVisitor>3</uniqueVisitor><orderCount>0</orderCount><revenue>0</revenue><conversionRate>0</conversionRate><newProduct>3</newProduct><outOfStockProduct>0</outOfStockProduct></SiteStats>"}

But i use NSLog(@"%@",getData); I do not get any data in getData array.

Can anybody tell me where is the problem? Thank you in advance.

  • 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-28T14:55:30+00:00Added an answer on May 28, 2026 at 2:55 pm
    xmlDocument = [[GDataXMLDocument alloc] initWithXMLString:responseString options:0 error:&errorOnStore];
    if (nil == xmlDocument)    
    {
        NSLog(@"could not load xml file");
    }
    else    
    {
        NSLog(@"Loading desire xml");
        NSLog(@"%@", xmlDocument.rootElement);
    
        // skip this bits, you're trying to retrieve wrong element
        //NSArray *getData = [[xmlDocument rootElement] elementsForName:@"SiteStats"];
        //NSLog(@"%@",getData);
        records = [[NSMutableArray alloc] init];
        //[records retain];
        //if(getData.count !=0 )
        //{
            //NSLog(@"data has");
        //}
        //storing the car model in the mutable array
        //for(GDataXMLElement *e in getData)
        //{
            //NSLog(@"Enering in the xml file");
            //[records addObject:e];
    
            NSString *Visitor = [[[xmlDocument.rootElement elementsForName:@"visitor"] objectAtIndex:0] stringValue];
            NSLog(@"Visitor : %@",Visitor);
    
            NSString *UVisitor = [[[xmlDocument.rootElement elementsForName:@"uniqueVisitor"] objectAtIndex:0] stringValue];
            NSLog(@"Unique Visitor : %@",UVisitor);
        //}
    }
    

    EDIT:
    NSArray *getData = [[xmlDocument rootElement] elementsForName:@"SiteStats"]; in this line, you’re trying to retrieve wrong element, element “SiteStats” is already the root element, so when you do that bit of code, what you’re trying to do is looking for “SiteStats” inside of “SideStats”

    <SiteStats>
       <SiteStats>
           <visitor>1</visitor>
           <uniqueVisitor>1</uniqueVisitor>
           <orderCount>0</orderCount>
           <revenue>null</revenue>
           <conversionRate>0</conversionRate>
           <newProduct>3</newProduct>
           <outOfStockProduct>0</outOfStockProduct>
       </SiteStats>
    </SiteStats>
    

    Your orignal code is likely to work if your XML looks something like above

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

Sidebar

Related Questions

So I have already imported one XML-ish file with 3000 elements and parsed them
First I have a PHP file that gets data and file from a HTML
I have my first professional assignment of making a website in which a photographer's
i have a DetailViewController and a Messages class(this is a TableViewController class). I parse
Why import org.apache.commons.lang.StringUtils cannot be imported in android by default. Do i have to
I have a txt file that I’m trying to import as flat file into
I am trying to import data into rails (3.1) and I have created this
I have some large csv file, with about 200 header names (the first one
I have denormalized data (coming from a file) that needs to be imported into
This is my very first attempt at including ads in my app. I have

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.