我有一些带有一些id的XML,并且每一个都有一个数据,我试图解析所有的XML,所以最终我会得到这样的对象:
A1Object[a1,a1,a1,a1]
A2Object[a2,a2,a2,a2]
问题是首先解析A1,A2 ......
xml:
<response>
<tmm>
<tm id="A1"><DocumentElement>
<cell>
<name>Tom</name>
<lastName>LastNameTom</lastName>
</cell>
<cell>
<name>Tom1</name>
<lastName>LastNameTom1</lastName>
</cell>
</tm>
<tm id="A2">
<cell>
<carType>5</carType>
<catId>4545</carId>
</cell>
<cell>
<carType>6</carType>
<catId>565656</carId>
</cell>
</tm>
<tm id="A3">...</tm>
</tmm>
</response>
我为每个对象(a1,a2 ......)提供了与他的领域的交互
我正在尝试下一件事:
if (xmlDocument != nil)
{
NSArray *nodes = [xmlDocument nodesForXPath:@"//cell" error: nil];
if (nodes != nil)
{
for (CXMLNode *node in nodes)
{
A1 *a1Object = [[A1 alloc] init];
for (int i = 0; i < [node childCount]; i++)
{
CXMLNode *child = [node childAtIndex: i];
NSString *str = [child stringValue];
if ([[child name] isEqualToString: @"name"])
{
a1Object.A1FacilityId = ([str length] > 0) ? str : nil;
}
if ([[child name] isEqualToString: @"lastName"])
{
a1Object.A1FacilityStreetName = ([str length] > 0) ? str : nil;
}
}
[self.A1s addObject:a1Object];
[a1Object release];
}
}
}
我如何能够改善这一点,所以我最终得到它:
A1Object[a1,a1,a1,a1]
A2Object[a2,a2,a2,a2