C# parse Fichier XML

J'ai un problème pour parser mon Fichier XML (RSS) en C#.
Je veux juste lire le "entrée" (la racine parent - "nourrir" - n'est pas pertinent).
Tous les "entrée" entrées sont presque la même, sauf la partie "état". Certaines entrées n'ont pas cette entrée.

Je tiens donc à le lire de la manière suivante:
"entrée" nœuds:

  1. mis à jour
  2. expire
  3. titre
  4. résumé
  5. état (s'il existe)

Des suggestions?
Je vous remercie beaucoup.

<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
<updated>2011-01-01T00:00:00+0100</updated>
<link href="http://www.domain.com" rel="self"/>
<author>
<name>Mr X</name>
<email>[email protected]</email>
</author>
<title>Some infos....</title>
<id>domain.com</id>
<entry>
<updated>2011-01-01T00:00:00Z</updated>
<expires>2011-01-02T00:00:00Z</expires>
<title>My first Title</title>
<id>First ID</id>
<link type="text/html" rel="alternate"
href="http://domain.com/firstElement"></link>
<summary>My first important summary</summary>
<rights>domain.com</rights>
<content type="xhtml">
<div xmlns="http://www.w3.org/1999/xhtml">
<div>
<img alt="second" width="32"
src="http://domain.com/firstElement.png"/>
</div>
</div>
</content>
</entry>
<entry>
<updated>2011-01-01T00:00:00Z</updated>
<expires>2011-01-02T00:00:00Z</expires>
<title>My second Title</title>
<state>active</state>
<id>Second ID</id>
<link type="text/html" rel="alternate"
href="http://domain.com/secondElement"></link>
<summary>My second important summary</summary>
<rights>domain.com</rights>
<content type="xhtml">
<div xmlns="http://www.w3.org/1999/xhtml">
<div>
<img alt="second" width="32"
src="http://domain.com/secondElement.png"/>
</div>
</div>
</content>
</entry>
</feed>{<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
<updated>2011-01-01T00:00:00+0100</updated>
<link href="http://www.domain.com" rel="self"/>
<author>
<name>Mr X</name>
<email>[email protected]</email>
</author>
<title>Some infos....</title>
<id>domain.com</id>
<entry>
<updated>2011-01-01T00:00:00Z</updated>
<expires>2011-01-02T00:00:00Z</expires>
<title>My first Title</title>
<id>First ID</id>
<link type="text/html" rel="alternate"
href="http://domain.com/firstElement"></link>
<summary>My first important summary</summary>
<rights>domain.com</rights>
<content type="xhtml">
<div xmlns="http://www.w3.org/1999/xhtml">
<div>
<img alt="second" width="32"
src="http://domain.com/firstElement.png"/>
</div>
</div>
</content>
</entry>
<entry>
<updated>2011-01-01T00:00:00Z</updated>
<expires>2011-01-02T00:00:00Z</expires>
<title>My second Title</title>
<state>active</state>
<id>Second ID</id>
<link type="text/html" rel="alternate"
href="http://domain.com/secondElement"></link>
<summary>My second important summary</summary>
<rights>domain.com</rights>
<content type="xhtml">
<div xmlns="http://www.w3.org/1999/xhtml">
<div>
<img alt="second" width="32"
src="http://domain.com/secondElement.png"/>
</div>
</div>
</content>
</entry>
</feed>

Mon code C#:

public void ParseXML(XmlDocument xmlFile)
{
ArrayList updated = new ArrayList();
ArrayList expires = new ArrayList();
ArrayList title = new ArrayList();
ArrayList summary = new ArrayList();
ArrayList state = new ArrayList();
ObservableCollection<TrafficInformation> trafInfo = new ObservableCollection<TrafficInformation>();
myCollection = trafInfo;
XmlNodeReader reader = new XmlNodeReader(xmlFile);
StringBuilder output = new StringBuilder();
while (reader.Read())
{
switch (reader.NodeType)
{
case XmlNodeType.Element:
if(reader.Name == "updated")
{
updated.Add(reader.ReadString());
}
if (reader.Name == "expires")
{
expires.Add(reader.ReadString());
}
if (reader.Name == "title")
{
title.Add(reader.ReadString());
}
if (reader.Name == "summary")
{
summary.Add(reader.ReadString());
}
if (reader.Name == "state")
{
state.Add(reader.ReadString());
}
break;
}
}
}

Dans ce cas, je n'ai pas de relation entre les données (si l'état n'existe pas).

Qu'avez-vous essayé? Où êtes-vous eu des difficultés? Quelle est la version de .NET vous aide?
Je suis en utilisant .net 4.0. Comment puis-je publier la forme d'un segment de code dans un commentaire?
Ne postez pas de code mis en forme dans les commentaires - au lieu de cela, éditez votre question et y ajouter des détails.
Ok. Merci pour l'info.
S'il vous plaît ne pas utiliser ArrayList - utilisation List<string> à la place. De cette façon, vous avez au moins le type de sécurité.

OriginalL'auteur user1011394 | 2011-11-19