reader.ReadToFollowing() throws DirectoryNotFoundException
-
Hallo Leute!
Ich habe ein problem mit folgenden Code:using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Windows; using System.Windows.Controls; using System.Windows.Data; using System.Windows.Documents; using System.Windows.Input; using System.Windows.Media; using System.Windows.Media.Imaging; using System.Windows.Navigation; using System.Windows.Shapes; using System.Xml; using System.IO; using System.Collections; using System.Net; namespace WpfApplication1 { public class Channel { private string channel = null; private string party = null; private string service = null; private string channelName = null; private string channelID = null; private string activationState = null; private string channelState = null; public Channel() { this.channel = null; this.party = null; this.service = null; this.channelName = null; this.channelID = null; this.activationState = null; this.channelState = null; } public string getChannel() { return this.channel; } public void setChannel(string _channel) { this.channel = _channel; } public string getParty() { return this.party; } public void setParty(string _party) { this.channel = _party; } public string getService() { return this.service; } public void setService(string _service) { this.service = _service; } public string getChannelName() { return this.channelName; } public void setChannelName(string _channelName) { this.channelName = _channelName; } public string getChannelID() { return this.channelID; } public void setChannelID(string _channelID) { this.channelID = _channelID; } public string getActivationState() { return this.activationState; } public void setActivationSate(string _activationState) { this.activationState = _activationState; } public string getChannelState() { return this.channelState; } public void setChannelState(string _channelState) { this.channelState = _channelState; } } public partial class MainWindow : Window { public MainWindow() { InitializeComponent(); //ArrayList für die Channels erzeugen ArrayList channelList = new ArrayList(); //Objekt Channel erzeugen; Channel leChannel = new Channel(); //Anmeldung string username = "user"; string password = "pw"; string url = "http://gehtnurwichwasan"; WebClient webClient = new WebClient(); webClient.Credentials = new System.Net.NetworkCredential(username, password); using (XmlTextReader reader = new XmlTextReader(webClient.OpenRead(url))) { while (reader.Read()) { //beim ersten mal Muss das Element Channels übersprungen werden bool b = true; if (b) { reader.ReadToFollowing("Channels"); b = false; } //channel reader.ReadToFollowing("Channel"); string channel = reader.ReadElementContentAsString(); leChannel.setChannel(channel); //party reader.ReadToFollowing("Party"); string party = reader.ReadElementContentAsString(); leChannel.setParty(party); //service reader.ReadToFollowing("Service"); string service = reader.ReadElementContentAsString(); leChannel.setService(service); //channelName reader.ReadToFollowing("ChannelName"); string channelname = reader.ReadElementContentAsString(); leChannel.setChannelName(channelname); //channelID reader.ReadToFollowing("ChannelID"); string channelId = reader.ReadElementContentAsString(); leChannel.setChannelID(channelId); //activationState reader.ReadToFollowing("ActivationState"); string activationState = reader.ReadElementContentAsString(); leChannel.setActivationSate(activationState); //channelState reader.ReadToFollowing("ChannelState"); string channelState = reader.ReadElementContentAsString(); leChannel.setChannelState(channelState); //Objekt in ChannelList einfügen channelList.Add(leChannel); } reader.Close(); } } } }
Ich bekomme in Zeile 144 folgenden Fehler:
DirectoryNotFoundException
Could not find a part of the path 'c:\AdapterFramework\channelAdmin\ChannelAdmin.dtd'.Woran liegt das und wie bekomm ich den Fehler behoben?
Der Fehler taucht nach jeder reader.ReadTo.... Zeile aufüber den Windows Explorer erreiche ich die Datei auch nicht
aber warum will er überhaupt auf die Datei zugreifen?SCHONMAL VIELEN DANK!!
-
im Quelltext der xml steht folgendes:
<!DOCTYPE ChannelStatusResult SYSTEM "/AdapterFramework/channelAdmin/ChannelAdmin.dtd">
vielleicht hilft euch das ja weiter.
-
Woher hast du denn die XML-Datei? Und wenn dort eine DTD angegeben ist, dann benötigt es die auch!
Oder aber du entfernst manuell die DTD-Referenz aus der XML-Datei (falls es sich um eine lokale Datei handelt)...Edit: Sehe gerade, daß du ja die Datei wohl per HTTP holst.
Dann wirst du auch zuerst die DTD-Datei dir laden müssen (und entsprechend dem Pfad ablegen) oder aber die XML-Datei vor dem Lesen überarbeiten müssen...btw: Bist du überhaupt legitimiert, diese XML-Datei zu benutzen?
-
schonmal danke für deine hilfe
also kann ich auf die xml nur zugreifen wenn mir die dtd zur verfügung steht?
gibt es keine methode, welche die dtd automatisch bereit stellt?und die 2. möglichkeit ist dann die xml erst lokal zu speichern und die dtd raus zu nehmen? kann das nicht zu fehlern führen?
die xml wird von nem server bei mir zu hause erzeugt auf dem einiges läuft (ts, ftp, ...). in der xml kann ich mir von diesen "channels" diverse werte ausgeben lassen z.b. den channelstate der mir angibt ob alles läuft oder ein fehler aufgetreten ist. die xml wird permanent akutalisiert.
möchte mir nun etwas schreiben, dass die xml z.b. jede stunde prüft und mir wenn was schief läuft z.b. ne mail schickt.