分離我有下面的XML架構我試圖遍歷:XML:通過內部節點嵌套節點解析和部分
<routes>
<route>
<group>Group Name - Will be iPhone section name</group>
<item>
<name>Route Name - Will be iphone cell lable</name>
<url>Route URL - View Did select lable</url>
</item>
<item>
<name>Route Name - Will be iphone cell lable</name>
<url>Route URL - View Did select lable</url>
</item>
<item>
<name>Route Name - Will be iphone cell lable</name>
<url>Route URL - View Did select lable</url>
</item>
<item>
<name>Route Name - Will be iphone cell lable</name>
<url>Route URL - View Did select lable</url>
</item>
</route>
<route>
<group>Group 2 - Will be iPhone section name</group>
<item>
<name>Route Name - Will be iphone cell lable</name>
<url>Route URL - View Did select lable</url>
</item>
<item>
<name>Route Name - Will be iphone cell lable</name>
<url>Route URL - View Did select lable</url>
</item>
</route>
</routes>
現在大部分都在項目相當多的項目 - 和Group節點將是該部分的標題爲UITableView的
繼承人如何我解析(錯誤地)的XML的時刻:
(這裏是xNode_ declaraions :)
static NSString *xNode_route [email protected]"//route";
static NSString *xNode_group [email protected]"group";
static NSString *xNode_item= @"//item";
static NSString *xNode_name = @"name";
static NSString *xNode_url = @"url";
下面是解析的代碼:
CXMLDocument *doc = [[CXMLDocument alloc] initWithData:dataReply options:0 error:nil];
NSArray *route = [doc nodesForXPath:xNode_route error:nil];//Root node
for (CXMLElement *item in route)
{
AssessObject *newobj2 = [[AssessObject alloc] init];
NSArray *arryGroup = [item elementsForName:xNode_group];
for(CXMLElement *assGroup in arryGroup)
{
newobj2.assGroup = assGroup.stringValue;
NSLog(@"Assessment Group: %@", assGroup.stringValue);
}
[groupArray addObject:newobj2];
}
NSArray *items = [doc nodesForXPath:xNode_item error:nil];//Root node
for (CXMLElement *item in items)
{
AssessObject *newobj = [[AssessObject alloc] init];
NSArray *arryName = [item elementsForName:xNode_name];
for(CXMLElement *assName in arryName)
{
newobj.assName = assName.stringValue;
NSLog(@"Assessment Name: %@", assName.stringValue);
}
NSArray *arryUrl = [item elementsForName:xNode_url];
for(CXMLElement *assUrl in arryUrl)
{
newobj.assUrl = assUrl.stringValue;
NSLog(@"Assessment URL: %@", assUrl.stringValue);
}
[totalArray addObject:newobj];
}
}
在它要通過所有的項目X有組的量的時刻,所以某處循環不正確。所以如果有6個組,它會顯示6次重複的項目。
所以這是第一部分,第二部分實際上是如何將陣列分成組並將正確的項目放入組中?
哪個解析器使用烏爾...我知道通過的NSXMLParser ... – mAc
我使用CXML解析器 – TMB87