下面是我的谷歌API請求XML結果:解析谷歌通過iOS版搜索API XML結果的Objective-C 2.0
<entry gd:kind="shopping#product">
<author>
<name>Bloomingdale's</name>
</author>
<title>7 For All Mankind "Ginger" Wide Leg Jeans in Lightweight Mercer Wash</title>
<s:product>
<s:author>
<s:name>Bloomingdale's</s:name>
<s:accountId>8020</s:accountId>
</s:author>
<s:title>7 For All Mankind "Ginger" Wide Leg Jeans in Lightweight Mercer Wash</s:title>
<s:description>7 for all Mankind "Ginger" jeans in lightweight mercer wash. A wide-leg fit.</s:description>
<s:brand>7 For All Mankind</s:brand>
<s:gtin>12345680753539</s:gtin>
<s:images>
<s:image link="http://images.bloomingdales.com/is/image/BLM/products/2/optimized/1144762_fpx.tif?wid=287&qlt=90"/>
<s:image link="http://1.0.0.0/"/>
<s:image link="http://0.0.0.5/"/>
</s:images>
</s:product>
</entry>
這裏是我的NSXMLParser代碼來解析XML:
@implementation ItemViewController
- (void)parser:(NSXMLParser *)parser
didStartElement:(NSString *)elementName
namespaceURI:(NSString *)namespaceURI
qualifiedName:(NSString *)qName
attributes:(NSDictionary *)attributeDict
{
if ([elementName isEqual:@"s:product"]) {
NSLog(@"found Product!");
if (!"s:product")
productScanned = [[NSMutableArray alloc] init];
return;
}
if ([elementName isEqual:@"s:gtin"]) {
// set ItemNumber as the GTIN of the productScanned
itemNumber = [[NSMutableString alloc] init];
}
if ([elementName isEqual:@"s:title"]) {
// set ItemDesc as the item description of the productScanned
itemDesc = [[NSMutableString alloc] init];
}
if ([elementName isEqual:@"s:brand"]) {
// set ItemBrand as the brand description of the productScanned
itemBrand = [[NSMutableString alloc] init];
}
if ([elementName isEqual:@"s:name"]) {
// set ItemStore as the store location of the productScanned
itemStore = [[NSMutableString alloc] init];
}
// Create array of Image Tags
if ([elementName isEqual:@"s:images"]) {
NSLog(@"found Images!");
if (!itemImageURLArray)
itemImageURLArray = [[NSMutableArray alloc] init];
return;
if ([elementName isEqualToString:@"s:image"]) {
// itemImagesArray is an NSMutableArray instance variable
if (!itemImagesArray)
itemImagesArray = [[NSMutableArray alloc] init];
NSString *thisLink = [attributeDict objectForKey:@"link"];
if (thisLink)
// do something
return;
}
}
itemImageURL = [itemImagesArray objectAtIndex:0];
}
爲什麼我的成績回報所有元素信息除了<s:images>
和<s:image>
埃爾對此語句?
更好。幫我理解爲什麼我的數組解析<s:images>
沒有將這些元素加載到我的*itemImageURL
指針中?
什麼行'如果( 「S:影像」!)'是什麼意思? – Anna 2011-05-25 03:08:30
Typo in code ...已被'if(!itemImageURLArray)'替換爲' Thx for捕捉那個,Anna – brussels0828 2011-05-25 03:17:34