Bonjour;
J'ai la méthode suivante pour récupérer la valeur d'un attribut particulier selon son chemin dans l'arborescence:
Mon problème est que pour les fichiers xml complexe (avec des namespaces par exemple ou plusieurs balises au même niveau) cette methode ne me retourne rien.
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 public static ArrayList SearchXPathNavAttribute(string xPathString, string attribute) { // Initilisation des variables XPathDocument xpathDoc; XPathNavigator xpathNavigator; XPathNodeIterator xpathNodeIterator; XPathExpression expr; ArrayList listOfAttributes = new ArrayList(); // Parcours du fichier XML try { xpathDoc = new XPathDocument(XMLFilePath); xpathNavigator = xpathDoc.CreateNavigator(); expr = xpathNavigator.Compile(xPathString); xpathNodeIterator = xpathNavigator.Select(expr); while (xpathNodeIterator.MoveNext()) { // On récupère l'attribut listOfAttributes.Add(xpathNodeIterator.Current.GetAttribute(attribute, "")); } } catch (Exception e) { System.Console.WriteLine(e); } return listOfAttributes; }
Dois-je ajouter une instruction pour ignorer les namespaces de mes fichier xml?
Partager