我正在使用TBXML來提取和導航XML樹,但是我需要一些東西來構建XML樹 - 相當簡單的有效。如何有效地構建XML元素
目前我正在寫這樣的可怕代碼。有沒有人有任何建議:
- (NSString *)buildTravellersListElement {
NSString *result = [NSString stringWithString:@""];
NSNumber *adultCount = [AppCache sharedAppCache].adultCount;
NSNumber *childCount = [AppCache sharedAppCache].childCount;
for (int i = 0; i < [adultCount intValue]; i++)
{
result = [result stringByAppendingFormat:@"<Traveller Age=\"25\"/>"];
}
for (int i = 0; i < [childCount intValue]; i++)
{
result = [result stringByAppendingFormat:@"<Traveller Age=\"6\"/>"];
}
return result; }
@TheLearner:請參閱更新的答案... – Jhaliya 2011-04-05 11:14:04