2
我有這樣的XML文件:現在如何通過kissxml解析器解析xml的子節點值?
<Menu>
<item value="boiled">
<image value="boiling1recipe">boiling1.jpg</image>
<recipeImage>png1.png</recipeImage>
<recipeImage>png2.png</recipeImage>
<recipeImage>png3.png</recipeImage>
<recipeImage>png4.png</recipeImage>
</item>
<item value="boiled">
<image value="boiling2recipe">boiling2.jpeg</image>
<recipeImage>png5.png</recipeImage>
<recipeImage>png6.png</recipeImage>
<recipeImage>png7.png</recipeImage>
<recipeImage>png8.png</recipeImage>
</item>
<item value="rosted">
<image value="roasted1recipe">roasted1.jpeg</image>
<recipeImage>png8.png</recipeImage>
<recipeImage>png9.png</recipeImage>
<recipeImage>png10.png</recipeImage>
<recipeImage>png11.png</recipeImage>
</item>
<item value="rosted">
<image value="roasted2recipe">roasted2.jpeg</image>
<recipeImage>png12.png</recipeImage>
<recipeImage>png13.png</recipeImage>
<recipeImage>png1.png</recipeImage>
<recipeImage>png2.png</recipeImage>
</item>
</Menu>
, 我解析它像這樣:
DDXMLNode *node = [item attributeForName:@"value"];
if ([[node stringValue] isEqual:@"boiled"]) {
[listOfBoiledItems addObject:model];
DDXMLNode *node1 = [item attributeForName:@"value"];
if ([[node1 stringValue] isEqual:@"boiling1recipe"]) {
[listOfRecipies1 addObject:model];
}
else if ([[node1 stringValue] isEqual:@"boiling2recipe"]) {
[listOfRecipies2 addObject:model];
}
}
else if ([[node stringValue] isEqual:@"rosted"]) {
[listOfRostedItems addObject:model];
DDXMLNode *node1 = [item attributeForName:@"value"];
if ([[node1 stringValue] isEqual:@"roasted1recipe"]) {
[listOfRecipies6 addObject:model];
}
else if ([[node1 stringValue] isEqual:@"roasted2recipe"]) {
[listOfRecipies7 addObject:model];
}
}
這裏, 編譯器讀取父節點值即「煮」和「rosted」,而不是讀取智利節點值,即「沸騰1調配」,「沸騰2調配」,「烘烤1調配」和「烘烤2調配」。 什麼可能是問題,意味着我做錯了什麼? 請指導我第一次做解析。
需要釋放字符串嗎? – why 2013-03-04 09:25:56