xpathNavigator: retrouver un attribut des parents
Voici une partie de ma methode pour chercher un attribut selon une expression
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
| public static ArrayList SearchXPathNavAttribute(string xPathString, string attribute)
try
{
[...]
expr = xpathNavigator.Compile(xPathString);
// affecter le manager à l'expression de recherche
expr.SetContext(nsmgr);
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
} |
selon l'arboresence suivante:
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14
| <racine>
<fournisseur id="96" type="intern">
<referents>
<referent name="Client" ref="97" />
<referent name="Local" ref="101" />
</referents>
</fournisseur >
<fournisseur id="80" type="extern">
<referents>
<referent name="Client" ref="97" />
<referent name="Local" ref="20" />
</referents>
</fournisseur >
</racine> |
comment je peux récupèrer les ids des fournisseurs de type ="intern" qui ont le referent name="Client" ref="97".
J'ai commencé par l'expression suivante:
Code:
fournisseurList = XPathNav.SearchXPathNavAttribute]"/racine/fournisseur[@type = 'intern']/referents/referent[@name = 'Client' and @ref = '97']", "id");
Cela est bien sûr fau puisque je suis entrain de chercher l'attribut "id" dans la balise referent et non pas dans fournisseur
Merci pour votre aide