public void laggTillNy(string namn, string url, string category, string interval) { Rss method = new Rss(); XmlDocument doc = method.fetchDocument(url); string path = Directory.GetCurrentDirectory() + @"\" + category + @"\" + namn + @".xml"; XmlWriterSettings settings = new XmlWriterSettings(); settings.Indent = true; settings.IndentChars = (" "); int i = 0; XmlWriter xmlOut = XmlWriter.Create(path, settings); xmlOut.WriteStartDocument(); xmlOut.WriteStartElement("channel"); xmlOut.WriteElementString("interval", interval); xmlOut.WriteElementString("url", url); xmlOut.WriteElementString("lastSync", DateTime.Now.ToString()); foreach (XmlNode item in doc.DocumentElement.SelectNodes("channel/item")) { var title = item.SelectSingleNode("title"); var description = item.SelectSingleNode("description"); var enclosure = item.SelectSingleNode("enclosure/@url"); xmlOut.WriteStartElement("item"); xmlOut.WriteAttributeString("ID", "pod" + i); if (description.InnerText.Equals("")) { xmlOut.WriteElementString("description", "Unfortunately, no description is available."); } else { xmlOut.WriteElementString("description", description.InnerText); } xmlOut.WriteElementString("title", title.InnerText); xmlOut.WriteElementString("enclosure", enclosure.InnerText); xmlOut.WriteElementString("status", "Unlistened"); xmlOut.WriteEndElement(); i++; } xmlOut.WriteEndDocument(); xmlOut.Close(); }
public void AddNew(string name, string url, string category, string interval) { Rss rss = new Rss(); XmlDocument doc = rss.RssReader(url); string path = Directory.GetCurrentDirectory() + @"\" + category + @"\" + name + @".xml"; XmlWriterSettings settings = new XmlWriterSettings(); settings.Indent = true; settings.IndentChars = (" "); int i = 0; XmlWriter writeXml = XmlWriter.Create(path, settings); writeXml.WriteStartDocument(); writeXml.WriteStartElement("channel"); writeXml.WriteElementString("interval", interval); writeXml.WriteElementString("url", url); writeXml.WriteElementString("lastSync", DateTime.Now.ToString()); foreach (XmlNode item in doc.DocumentElement.SelectNodes("channel/item")) { var title = item.SelectSingleNode("title"); var description = item.SelectSingleNode("description"); var enclosure = item.SelectSingleNode("enclosure/@url"); writeXml.WriteStartElement("item"); writeXml.WriteAttributeString("ID", "pod" + i); if (description.InnerText.Equals("")) { writeXml.WriteElementString("description", "No description available"); } else { writeXml.WriteElementString("description", description.InnerText); } writeXml.WriteElementString("title", title.InnerText); writeXml.WriteElementString("enclosure", enclosure.InnerText); writeXml.WriteElementString("status", "Unlistened"); writeXml.WriteEndElement(); i++; } writeXml.WriteEndDocument(); writeXml.Close(); }
public void läggTillPod(String namn, String url, String kategori, String uppdatering) { Rss varRss = new Rss(); XmlDocument dokument = varRss.läggIhopDokument(url); String path = Directory.GetCurrentDirectory() + @"\" + kategori + @"\" + namn + @".xml"; int i = 0; XmlWriter xmlSkrivare = XmlWriter.Create(path); xmlSkrivare.WriteStartDocument(); xmlSkrivare.WriteStartElement("channel"); xmlSkrivare.WriteElementString("interval", uppdatering); xmlSkrivare.WriteElementString("url", url); xmlSkrivare.WriteElementString("lastSync", DateTime.Now.ToString()); foreach (XmlNode item in dokument.DocumentElement.SelectNodes("channel/item")) { var titel = item.SelectSingleNode("title"); var beskrivning = item.SelectSingleNode("description"); var stäng = item.SelectSingleNode("enclosure/@url"); xmlSkrivare.WriteStartElement("item"); xmlSkrivare.WriteAttributeString("ID", "pod" + i); if (beskrivning.InnerText.Equals("")) { xmlSkrivare.WriteElementString("description", "Tyvärr finns ingen beskrivning för podcasten."); } else { xmlSkrivare.WriteElementString("description", beskrivning.InnerText); } xmlSkrivare.WriteElementString("title", titel.InnerText); xmlSkrivare.WriteElementString("enclosure", stäng.InnerText); xmlSkrivare.WriteElementString("status", "Unlistened"); xmlSkrivare.WriteEndElement(); i++; } xmlSkrivare.WriteEndDocument(); xmlSkrivare.Close(); }