Сначала я импортировал #import "GDataXMLNode.h"
в .h файл. Теперь это мой XML
, который я должен проанализировать с помощью парсера GDataXML
.Я не могу разобрать данные xml, используя GDataXML
<SiteStats>
<visitor>1</visitor>
<uniqueVisitor>1</uniqueVisitor>
<orderCount>0</orderCount>
<revenue>null</revenue>
<conversionRate>0</conversionRate>
<newProduct>3</newProduct>
<outOfStockProduct>0</outOfStockProduct>
</SiteStats>
Теперь одно замечание состоит в том, что мой этот xml поступает из Интернета. Поэтому я использовал делегата NSUrlConnection
для извлечения данных xml.
- (void)connectionDidFinishLoading:(NSURLConnection *)connection {
responseString = [[NSString alloc] initWithData:receivedData encoding:NSUTF8StringEncoding];
NSLog(@"Response: %@",responseString);
// other stuff here...
}
Здесь я получаю responseString
, а затем я разобрать его, используя следующий код. Но я не могу разобрать его.
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);
}
}
я могу получить это значение, когда я 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>"}
Но я использую NSLog(@"%@",getData);
я не получаю никаких данных в getData
массиве.
Может кто-нибудь сказать мне, где проблема? Заранее спасибо.
где ошибка? возможно, также вывести вывод вашего NSLog –
'NSLog (@"% @ ", getData);' print '(null)' .Пожалуйста, сообщите, как кто-нибудь мне помогает. –
@ XSlash Я редактировал свой код. –