#import "GDataXMLNode.h"
最初に.hファイルをインポートしました。これが私のパーサー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>
ここで注意すべきことの1つは、このxmlがWebからのものであるということです。そのため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
誰かが問題がどこにあるか教えてもらえますか?前もって感謝します。