A voir également:
- C#-Xml Recupérer élément xml par son id
- Xml viewer - Télécharger - Édition & Programmation
- Https //id.sonyentertainmentnetwork.com/id/management/ ✓ - Forum PS4
- Recuperer video youtube - Guide
- Comment recuperer son compte facebook piraté - Guide
- Email id - Forum Consommation et internet
3 réponses
Désolé j'ai oublier le lien pour le tuto :) https://yanngarit.wordpress.com/2010/04/02/c-xml-parsing-dun-fichier-xml/
chuka
Messages postés
965
Date d'inscription
samedi 11 octobre 2008
Statut
Membre
Dernière intervention
29 juillet 2010
377
Modifié par chuka le 15/06/2010 à 22:19
Modifié par chuka le 15/06/2010 à 22:19
Salut,
y'a peut-etre plus simple....mais c'est peut-etre une piste:
Tu utilises une liste ordonnée...comme cela tu peux l'avoir par index ou string....
J'ai pas testé..mais ca devrait marcher....;)
@+
Ce n'est pas parce que certaines choses semblent inexplicables, qu'il faut faire semblant de les expliquer!
y'a peut-etre plus simple....mais c'est peut-etre une piste:
using System.Collections.Specialized;
public static OrderedDictionary DocList(string filename)
{
XmlDocument document = new XmlDocument();
try
{
document.Load(filename);
}
catch (Exception)
{
throw;
}
XmlNode node = document.DocumentElement;
try
{
XmlNodeList nodeList = node.SelectNodes("book");
OrderedDictionary o = new OrderedDictionary();
foreach (XmlNode n in nodeList)
{
o.Add(n.Attributes["id"].Value, n);
}
return o;
}
catch (Exception)
{
throw;
}
}
public Book BookParsing(string filename, string id)
{
Book book = new Book();
OrderedDictionary nodeList = DocList(filename);
try
{
book.Author += (nodeList[id] as XmlNode).SelectNodes("author").Item(0).InnerText;
book.Title += (nodeList[id] as XmlNode).SelectNodes("title").Item(0).InnerText;
book.Genre += (nodeList[id] as XmlNode).SelectNodes("genre").Item(0).InnerText;
book.Price += (nodeList[id] as XmlNode).SelectNodes("price").Item(0).InnerText;
book.Publish_date += (nodeList[id] as XmlNode).SelectNodes("publish_date").Item(0).InnerText;
book.Description += (nodeList[id] as XmlNode).SelectNodes("description").Item(0).InnerText;
}
catch (Exception)
{
throw;
}
return book;
}
public Book BookParsing(string filename, int id)
{
Book book = new Book();
OrderedDictionary nodeList = DocList(filename);
try
{
book.Author += (nodeList[id] as XmlNode).SelectNodes("author").Item(0).InnerText;
book.Title += (nodeList[id] as XmlNode).SelectNodes("title").Item(0).InnerText;
book.Genre += (nodeList[id] as XmlNode).SelectNodes("genre").Item(0).InnerText;
book.Price += (nodeList[id] as XmlNode).SelectNodes("price").Item(0).InnerText;
book.Publish_date += (nodeList[id] as XmlNode).SelectNodes("publish_date").Item(0).InnerText;
book.Description += (nodeList[id] as XmlNode).SelectNodes("description").Item(0).InnerText;
}
catch (Exception)
{
throw;
}
return book;
}
Tu utilises une liste ordonnée...comme cela tu peux l'avoir par index ou string....
J'ai pas testé..mais ca devrait marcher....;)
@+
Ce n'est pas parce que certaines choses semblent inexplicables, qu'il faut faire semblant de les expliquer!