我正在使用XML提取的结果构建一个对象“Position”,它解析得很好 但我无法弄清楚何时在数组中添加此对象。 我希望在提取以下元素后添加对象
我这样做:
- (void) traverseElement:(TBXMLElement *)element {
position = [[Position alloc]init];
NSString *cp;
do {
TBXMLAttribute * attribute = element->firstAttribute;
BOOL foundElement = NO;
while (attribute) {
if ([[TBXML elementName:element] isEqualToString:@"referencecolis"]) {
[idClient addObject: [TBXML textForElement:element]];
};
if ([[TBXML elementName:element] isEqualToString:@"idagencedepart"]) {
[position setIdagencedepart:[TBXML textForElement:element]];
NSLog(@"idagencedepart : %@",position.idagencedepart);
};
if ([[TBXML elementName:element] isEqualToString:@"idagencefinale"]) {
[position setIdagencefinale:[TBXML textForElement:element]];
NSLog(@"idagencedfinale : %@",[TBXML textForElement:element]);
};
if ([[TBXML elementName:element] isEqualToString:@"iddestinataire"]) {
[position setIddestinataire:[TBXML textForElement:element]];
};
if ([[TBXML elementName:element] isEqualToString:@"idexpediteur"]) {
[position setIddestinataire:[TBXML textForElement:element]];
NSLog(@"idExpediteur : %@",[TBXML textForElement:element]);
};
if ([[TBXML elementName:element] isEqualToString:@"idTransporteurReexpedition"]) {
[position setIdtransporteurreexpedition:[TBXML textForElement:element]];
NSLog(@"idTransporteurReexpedition : %@",[TBXML textForElement:element]);
};
if ([[TBXML elementName:element] isEqualToString:@"typeadresse"] && [[TBXML textForElement:element]isEqualToString:@"1"] ) {
[position setTypeAdresse:[TBXML textForElement:element]];
NSLog(@"typeadresse : %@",[TBXML textForElement:element]);
};
if ([[TBXML elementName:element] isEqualToString:@"codepostal"]) {
cp = [[TBXML textForElement:element] substringWithRange:NSMakeRange(0,2)];
[position setCodePostal:cp];
NSLog(@"codePostal : %@",cp);
};
attribute = attribute->next;
[arrayPositions addObject:position];
}
if (element->firstChild)
[self traverseElement:element->firstChild];
} while ((element = element->nextSibling));
我无法设置一个布尔值来知道它是否被解析,因为一些元素被解析了两次。
任何帮助?