Hi
want to tell you that i'm a beginner so be ...
i want to parse this XML File to get their tag and attributs
that is why i try to do that. that is my class for parsing the previous XML file
But in console i have this error and i'm not understand Why and how to do to resolve it
thanks
want to tell you that i'm a beginner so be ...
i want to parse this XML File to get their tag and attributs
Code:
<commands>
<command id="84" crypt="0">
<NbreSecEnCours>2</NbreSecEnCours>
<IdSession NomAppli="Notepad" NameMach="T2037" GuidSession="12729c94-1bf6-49ac-beca-e3c99609aded">2</IdSession>
<IdSession NomAppli="nslookup" NameMach="T2037" GuidSession="12729c94-1bf6-49ac-beca-e3c99609aded">2</IdSession>
</command>
</commands>
that is why i try to do that. that is my class for parsing the previous XML file
Code:
//--------------------------------------------------------------------
// Start of element
- (void)parser:(NSXMLParser *)parser
didStartElement:(NSString *)elementName
namespaceURI:(NSString *)namespaceURI
qualifiedName:(NSString *)qName
attributes:(NSDictionary *)attributeDict
{
currentElement = [elementName copy];
//currentElement = [attributeDict copy];
//NSLog(@"%@", currentElement);
item2 = [[NSMutableDictionary alloc]init];
item = [[NSMutableDictionary alloc]init];
if ([elementName isEqualToString:@"command"]) {
//item utilisé pour le stockage du nombre de session
//currentNode = [[NSMutableString alloc]init];
//Récupération du numéro de la requete
NSLog(@"id = %@",[attributeDict objectForKey:@"id"]);
currentNbreSecEnCours = [[NSMutableString alloc]init];
currentIdSession = [[NSMutableString alloc]init];
[item setObject:currentNbreSecEnCours forKey:@"NbreSecEnCours"];
[commandes addObject:item];
//[commandes addObject:item2];
XMLItems = [[NSMutableDictionary alloc]init];
}
if([elementName isEqualToString:@"IdSession"]){
//[item2 setObject:currentIdSession forKey:@"IdSession"];
NomAppli = [attributeDict objectForKey:@"NomAppli"];
NameMach = [attributeDict objectForKey:@"NameMach"];
GuidSession = [attributeDict objectForKey:@"GuidSession"];
[item2 setObject:NomAppli forKey:@"NomAppli"];
[item2 setObject:NameMach forKey:@"NameMach"];
[item2 setObject:GuidSession forKey:@"GuidSession"];
[commandes addObject:item2];
/*[commandes addObject:NomAppli];
[commandes addObject:NameMach];
[commandes addObject:GuidSession];*/
NSLog(@"[didStartElement]commandes: %@",commandes);
}
}
// Found Character
- (void) parser:(NSXMLParser *)parser foundCharacters:(NSString *)string
{
if ([currentElement isEqualToString:@"NbreSecEnCours"]) {
[currentNbreSecEnCours appendString:string];
NSLog(@"currentNbreSecEncours: %@", currentNbreSecEnCours);
}
if ([currentElement isEqualToString:@"IdSession"]) {
[currentIdSession appendFormat:string];
NSLog(@"currentIdSession: %@", currentIdSession);
}
}
// End Element
- (void) parser:(NSXMLParser *)parser
didEndElement:(NSString *)elementName
namespaceURI:(NSString *)namespaceURI
qualifiedName:(NSString *)qName attributes:(NSDictionary *)attributeDict
{
if ([elementName isEqualToString:@"command"]) {
//[item setObject:currentNode forKey:@"Username"];
[item setObject:currentNbreSecEnCours forKey:@"NbreSecEnCours"];
[commandes addObject:item];
}
if([elementName isEqualToString:@"IdSession"]){
[item2 setObject:currentIdSession forKey:@"IdSession" ];
NomAppli = [attributeDict objectForKey:@"NomAppli"];
NameMach = [attributeDict objectForKey:@"NameMach"];
GuidSession = [attributeDict objectForKey:@"GuidSession"];
NSLog(@"[didEndElement]commandes: %@",commandes);
}
}
//------------------------------------------------------------------
//-(NSString*)getElementValue:(NSString*)Node{
-(NSMutableArray*)getElementValue{
//NSString *nodeValue;
NSString *nbreSess;
NSString *idSession;
NSString *nomAppli;
NSString *nameMach;
NSString *guidSession;
NSMutableArray *results = [[NSMutableArray alloc]init];
NSLog(@"Commande=> %@",commandes);
for (NSMutableDictionary *val in commandes) {
nbreSess = [val objectForKey:@"NbreSecEnCours"];
nbreSess = [nbreSess stringByReplacingOccurrencesOfString:@"\n" withString:@""];
nbreSess = [nbreSess stringByReplacingOccurrencesOfString:@"\t" withString:@""];
[results addObject:nbreSess];
idSession = [val objectForKey:@"IdSession"];
idSession = [idSession stringByReplacingOccurrencesOfString:@"\n" withString:@""];
idSession = [idSession stringByReplacingOccurrencesOfString:@"\t" withString:@""];
[results addObject:idSession];
nomAppli = [val objectForKey:@"NomAppli"];
nomAppli = [nomAppli stringByReplacingOccurrencesOfString:@"\n" withString:@""];
nomAppli = [nomAppli stringByReplacingOccurrencesOfString:@"\t" withString:@""];
[results addObject:nomAppli];
nameMach = [val objectForKey:@"NameMach"];
nameMach = [nameMach stringByReplacingOccurrencesOfString:@"\n" withString:@""];
nameMach = [nameMach stringByReplacingOccurrencesOfString:@"\t" withString:@""];
[results addObject:nameMach];
guidSession = [val objectForKey:@"GuidSession"];
guidSession = [guidSession stringByReplacingOccurrencesOfString:@"\n" withString:@""];
guidSession = [guidSession stringByReplacingOccurrencesOfString:@"\t" withString:@""];
[results addObject:guidSession];
}
NSLog(@"Results=> %@",results);
//return nodeValue;
//return commandes;
return results;
}
But in console i have this error and i'm not understand Why and how to do to resolve it
Code:
2013-02-28 09:12:45.535 XMLTesteur-1.1[666:11303] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[__NSArrayM insertObject:atIndex:]: object cannot be nil'
*** First throw call stack:
(0x1ca0012 0x10dde7e 0x1c53b6a 0x1c53a20 0x85d7 0x561f 0x5a7e 0x10f1705 0x28920 0x288b8 0xe9671 0xe9bcf 0xe8d38 0x5833f 0x58552 0x363aa 0x27cf8 0x1bfbdf9 0x1bfbad0 0x1c15bf5 0x1c15962 0x1c46bb6 0x1c45f44 0x1c45e1b 0x1bfa7e3 0x1bfa668 0x2565c 0x233d 0x2265)
libc++abi.dylib: terminate called throwing an exception
(lldb)
thanks