1
-<stat>
<visitor>4</visitor>
<uniqueVisitor>2</uniqueVisitor>
<order>41</order>
<revenue>20658</revenue>
<conversionRate>48</conversionRate>
<newProduct>25</newProduct>
<outOfStockProduct>11</outOfStockProduct>
</stat>

From this xml i want to get the element name "visitor" & "uniqueVisitor" and their corresponding values using GDataXML parser.

Till now i have done these.

xmlFileLocation = [NSURL URLWithString:@"someurl....abc.php"];
NSData *xmlData = [[NSMutableData alloc] initWithContentsOfURL:xmlFileLocation];
xmlDocument = [[GDataXMLDocument alloc]initWithData:xmlData options:0 error:&error];
if (nil == xmlDocument)    {
    NSLog(@"could not load Branch.xml file");
}
else    {
    NSLog(@"Loading desire xml url for dashboard");
    [self GDataXmlParser];
}

Using a tutorial i have done this till now. But now i want all of these element name and their corresponding values

-(void)GDataXmlParser{

NSArray *getData = [[xmlDocument rootElement]elementsForName:@"stat"];
records = [[NSMutableArray alloc]init];

        tempArray = [[NSMutableArray alloc]init];
        for(GDataXMLElement *e in getData){

         // What i have to do here????
        }

}

Yamen Emon
  • 139
  • 3
  • 12

2 Answers2

0

look at the answer

     NSLog(@"%@", xmlDocument.rootElement);
    records = [[NSMutableArray alloc] init];
    NSLog(@"Enering in the xml file");
    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);

for more see the link I am not able to parse xml data using GDataXML

Community
  • 1
  • 1
Emon
  • 958
  • 3
  • 10
  • 28
-1

Follow this link for tutorial :http://iphonebyradix.blogspot.com/2011/03/using-gdata-to-parse-xml-file.html

-(void) GDataXmlParser 
{        
    xmlDocument = [[GDataXMLDocument alloc]initWithData:xmlData 
                                                options:0 
                                                  error:nil];

    NSArray *temp = [xmlDocument.rootElement elementsForName:@"stat"];
    NSMutableArray *records = [[NSMutableArray alloc]init];
    for(GDataXMLElement *e in temp)
    {
        [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);
    }
}

Hope it helps you. Happy iCoding.

Costique
  • 23,712
  • 4
  • 76
  • 79
Suraj Mirajkar
  • 1,369
  • 10
  • 23
  • hi please try the link mentioned at top of my answer which will sort your problem. – Suraj Mirajkar Jan 24 '12 at 10:09
  • You are wrong man.So answer should be like my answer because when you will `NSArray *temp = [xmlDocument.rootElement elementsForName:@"stat"];` and `NSLog(@"%@",temp)` then you will get empty array because....see the link....http://stackoverflow.com/questions/8986363/i-am-not-able-to-parse-xml-data-using-gdataxml – Emon Jan 25 '12 at 04:46
  • :http://iphonebyradix.blogspot.com/2011/03/using-gdata-to-parse-xml-file.html Try this link hope it will help – Suraj Mirajkar Jan 25 '12 at 04:50