J'ai trouvé comment ajouter des nœuds à mon document rss dans la bonne structyre. J'ai maintenant besoin de le trier dans l'ordre pubDate et ensuite sortir à l'écran. En regardant les exemples en ligne, j'ai trouvé beaucoup de choses XDocument et Linq mais rien avec XmlDocument. Se gratter la tête pour savoir si je dois supprimer le code que j'ai et comment travailler dans XDocument avec les conseils d'ici ou continuer avec XMLDocument et trouver un moyen de trier. Avec XMLDocument, j'ai le code qui fonctionne exactement comme je veux, j'ai juste besoin que mon flux soit trié dans l'ordre pubDate quand il le crache à l'écran. Donc je pense que je m'en tiendrai là pour le moment. J'ai trouvé cet article http://support.microsoft.com/kb/555060 et un xslt quelqu'un posté dans Stack Overflow, mais je ne sais pas comment appeler le "XmlHelperFunctions" de mon code. Est-ce que XSLT est l'option la plus facile que j'ai, ou est-ce qu'il y a quelque chose de plus facile là-bas?XMLdocument Tri
Ceci est mon code:
XmlDocument xmlDoc = new XmlDocument();
xmlDoc.LoadXml(rssFeed.ToString());
XmlNodeList nl = xmlDoc.SelectNodes("/rss/channel/item");
foreach (XmlNode xn in nl)
{
string title = xn["title"].InnerText;
string link = xn["link"].InnerText;
string desc = xn["description"].InnerText;
string auth = xn["author"].InnerText;
string pdate = xn["pubDate"].InnerText;
XmlElement itemnode = xmlDoc.CreateElement("item");
itemnode.InnerXml = "<title></title><link></link><description></description><author></author><pubDate></pubDate>";
itemnode["title"].InnerText = title;
itemnode["link"].InnerText = link;
itemnode["description"].InnerText = desc;
itemnode["author"].InnerText = auth;
itemnode["pubDate"].InnerText = pdate;
xmlDoc.DocumentElement.SelectNodes("/rss/channel")[0].AppendChild(itemnode);
}
// Output to screen
xmlDoc.Save(Response.Output);
mon flux rss
<?xml version="1.0" encoding="utf-8"?>
<rss xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="2.0">
<channel>
<title>My RSS Feed</title>
<link>http://www.mylink.aspx</link>
<description>
</description>
<item>
<title>Top marks</title>
<link>http://www.mymarks.aspx</link>
<description>
<p>description field here</p>
</description>
<author>Viv</author>
<pubDate>Thu, 16 Aug 2012 12:10:54 GMT</pubDate>
</item>
<item>
<title>Costa Coffee</title>
<link>http://www.Costa.aspx</link>
<description>
<p>Costa Coffee have special offers.</p>
</description>
<author>Mike</author>
<pubDate>Thu, 23 Aug 2012 15:55:53 GMT</pubDate>
</item>
<item>
<title>Celebrate success</title>
<link>http://www.Celebrate.aspx</link>
<description>
<p>Lets all celebrate </p>
</description>
<author>Viv</author>
<pubDate>Thu, 22 Aug 2012 09:10:21 GMT</pubDate>
</item>
</channel>
</rss>
jetez un oeil à cela http://stackoverflow.com/questions/344737/sorting-xml-nodes-based-on-datetime-attribute-c-xpath – saj