Xcode 使用NSXMLParser解析XML属性

Xcode 使用NSXMLParser解析XML属性,xcode,uitableview,attributes,nsxmlparser,Xcode,Uitableview,Attributes,Nsxmlparser,我正在搜索解析此简化xml文件的N个标记中的所有属性“unit1”和“unit2”,然后将它们放在UITableView中: <xml> <meta></meta> <time1> <product> <value1 id="id1Time1" unit1="unit1Time1" number1="number1Time1"/> <value2 id="id2Time1" unit2="unit2Time1" num

我正在搜索解析此简化xml文件的N个标记中的所有属性“unit1”和“unit2”,然后将它们放在UITableView中:

<xml>
<meta></meta>
<time1>
<product>
<value1 id="id1Time1" unit1="unit1Time1" number1="number1Time1"/>
<value2 id="id2Time1" unit2="unit2Time1" number2="number2Time1"/>
</product>
</time1>
<time2>
<product>
<value1 id="id1Time2" unit1="unit1Time2" number1="number1Time2"/>
<value2 id="id2Time2" unit2="unit2Time2" number2="number2Time2"/>
</product>
</time2>
...
<timeN>
<product>
<value1 id="id1TimeN" unit1="unit1TimeN" number1="number1TimeN"/>
<value2 id="id2TimeN" unit2="unit2TimeN" number2="number2TimeN"/>
</product>
</timeN>
</xml>
要使用value1和value2填充UITableView,我正在使用:

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return [arrayUnit1 count]; // <--- I Know, here is the problem!
}

好的,解析是完美的,我也可以记录每N个stringValues,但在我的UITableView中,我只能看到最后一行arrayUnit N的值(在本例中为unit1TimeN和unit2TimeN)。那么,如何用数组中的每个值,所有N个值填充表呢?也许我还需要实现-(void)parser:(NSXMLParser*)parser didEndElement:?谢谢

从此处删除此行

arrayUnit1=[[NSMutableArray alloc]init]

并在分配解析器时将其放在其他地方。。
这将删除数组中所有以前的元素并为其分配新内存,因此您将只看到添加的最后一个元素

从此处删除此行

arrayUnit1=[[NSMutableArray alloc]init]

并在分配解析器时将其放在其他地方。。
这将删除数组中所有以前的元素并为其分配新内存,因此您将只看到添加的最后一个元素

您要在每个已解析的元素上重新分配一个新数组,只需分配一次数组:

if (!arrayUnit1)
   arrayUnit1 = [[NSMutableArray alloc] init];

您要在每个解析的元素上重新分配一个新数组,只需分配一次数组:

if (!arrayUnit1)
   arrayUnit1 = [[NSMutableArray alloc] init];

代码中的
value1
与xml中的
number1
相同吗?对不起,我已经编辑过了,value1是value1…;=)代码中的
value1
与xml中的
number1
相同吗?对不起,我已经编辑过了,value1是value1…;=)
if (!arrayUnit1)
   arrayUnit1 = [[NSMutableArray alloc] init];