Bonsoir,

J'essai de recuperer les attributs d'un element de mon fichier XML dont la structure est la suivante

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
- <commands>
-<command id="84" crypt="0">
  <NbreSecEnCours>4</NbreSecEnCours>
  <IdSession NomAppli="MSOutlook_APP02" NameMach="APPS-MLH-P01"
GuidSession="69c1575e-b3b7-4695-98b6-ab9c2cc5de98">7</IdSession>
  <IdSession NomAppli="VMClient" NameMach="APPS-MLH-P01"
GuidSession="69c1575e-b3b7-4695-98b6-ab9c2cc5de98">7</IdSession>
  <IdSession NomAppli="CRM" NameMach="APPS-MLH-P01"
GuidSession="bf6dfd59-cdae-4197-b9ac-213ebeef83f2">9</IdSession>
  <IdSession NomAppli="MSOutlook_APP02" NameMach="APPS-MLH-P01"
GuidSession="bf6dfd59-cdae-4197-b9ac-213ebeef83f2">9</IdSession>
  </command>
  </commands>

mais malheureusement je n'y parviens pas voici comment j'aborde le probleme en dessous le contenu de mon fichier pour parser
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
- (void)parser:(NSXMLParser *)parser
didStartElement:(NSString *)elementName
  namespaceURI:(NSString *)namespaceURI
 qualifiedName:(NSString *)qName
    attributes:(NSDictionary *)attributeDict
{
    currentElement = [elementName copy];
    //currentElement = [attributeDict copy];
    //NSLog(@"%@", currentElement);
    if ([elementName isEqualToString:@"command"]) {
        item = [[NSMutableDictionary alloc]init];
        //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];
 
 
    }
 
}
 
// Found Character
- (void) parser:(NSXMLParser *)parser foundCharacters:(NSString *)string
{
    if ([currentElement isEqualToString:@"NbreSecEnCours"]) {
        [currentNbreSecEnCours appendString:string];
 
    }
    if ([currentElement isEqualToString:@"IdSession"]) {
        [currentIdSession appendString:string];
 
    }
 
}
 
// End Element
- (void) parser:(NSXMLParser *)parser
  didEndElement:(NSString *)elementName
   namespaceURI:(NSString *)namespaceURI
  qualifiedName:(NSString *)qName
{
    if ([elementName isEqualToString:@"command"]) {
        //[item setObject:currentNode forKey:@"Username"];
        [item setObject:currentNbreSecEnCours forKey:@"NbreSecEnCours"];
        [item setObject:currentIdSession forKey:@"IdSession"];
        [commandes addObject:item];
        NSLog(@"[didEndElement]commandes: %@",commandes);
    }
}
//------------------------------------------------------------------
//-(NSString*)getElementValue:(NSString*)Node{
-(NSMutableArray*)getElementValue{
    //NSString *nodeValue;
    NSString *nbreSecEnCours;
    NSString *idSession;
 
    NSMutableArray *results = [[NSMutableArray alloc]init];
    for (NSMutableDictionary *val in commandes) {
                nbreSecEnCours= [val objectForKey:@"NbreSecEnCours"];
         nbreSecEnCours = [ nbreSecEnCours stringByReplacingOccurrencesOfString:@"\n" withString:@""];
         nbreSecEnCours = [ nbreSecEnCours stringByReplacingOccurrencesOfString:@"\t" withString:@""];
        [results addObject: nbreSecEnCours];
        NSLog(@"NombreSession:%@",nbreSecEnCours);
 
        idSession = [val objectForKey:@"IdSession"];
        idSession = [idSession stringByReplacingOccurrencesOfString:@"\n" withString:@""];
       idSession = [idSession stringByReplacingOccurrencesOfString:@"\t" withString:@""];
        [results addObject:idSession];
 
    }
    //return nodeValue;
    NSLog(@"results= %@",results);
    return results;
}

J'ai aussi une deuxieme preoccupation , pour le projet sur lequel je suis entrain de travailler je dois parser un bon nombre de fichier car recuperer via une serveur Web distant j'aimerais savoir s'il est possible de faire un parseur gernerique pour ne pas avoir à creer autant de fichier pour parser que de fichier XML recu .

Merci d'avance .
Je suis Novice en Objective-C celà fait juste deux semaine que je connais le langage donc si mes questions vous semblent idiotes soyez indulgent