Récupérer valeur dans XML
Bonjour, d'abord je débute en XML et C#... d'où ce post :oops:
Suivant cet XML :
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
|
<PROPOSALS version="13">
<PROPOSAL Number="200704010" Caption="le nom">
<ShowCaption>1</ShowCaption>
<Indice>0</Indice>
<ProposalType>0</ProposalType>
<DateCreate>12/04/2007 10:58:53</DateCreate>
<DateLastModif>31/07/2009 13:41:55</DateLastModif>
<WriteBy>Adeline</WriteBy>
<CaptionUser1>Chargee affaires :</CaptionUser1>
<User1>Michel</User1>
<CaptionUser2>Charge etudes :</CaptionUser2>
<User2>Adeline</User2>
<TownProposal>WAZIERS</TownProposal>
<ClassCategorie>PLAFOND</ClassCategorie>
<ClassFolder>47 W</ClassFolder>
(..)
</PROPOSAL>
</PROPOSALS> |
Je chercher à prende telle ou telle donnée. Alors je fais comme le code suivant qui fonctionne mais je sents à plein nez que c'est très très mauvais. Avez vous une solution plus optimisée afin que je débute sur de meilleure base ? :
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
|
XPathDocument XPathDocu = new XPathDocument(Fichier);
XPathNavigator Navigator;
XPathNodeIterator Nodes;
Navigator = XPathDocu.CreateNavigator();
/*----- LECTURE INFO DE BASE-----*/
XPathExpression xpe = Navigator.Compile("//PROPOSAL/ProposalHour");
XPathNodeIterator ni = Navigator.Select(xpe);
while (ni.MoveNext())
{
m_fTotalHour = float.Parse(ni.Current.Value);
}
CultureInfo provider = CultureInfo.InvariantCulture;
provider = new CultureInfo("fr-FR");
xpe = Navigator.Compile("//PROPOSAL/StartWork");
ni = Navigator.Select(xpe);
while (ni.MoveNext())
{
datStart = DateTime.ParseExact(ni.Current.Value, "d", provider);
} |
Merci