Reputation: 134684
So I'm currently working on an ePub reader application, and I've been reading through a bunch of regular XML files just fine with System.Xml and XmlDocument:
XmlDocument xmldoc = new XmlDocument();
xmldoc.Load(Path.Combine(Directory.GetCurrentDirectory(), "META-INF/container.xml"));
XmlNodeList xnl = xmldoc.GetElementsByTagName("rootfile");
However, now I'm trying to open the XHTML files that contain the actual book text, and they're XHTML files. Now I don't really know the difference between the two, but I'm getting the following error with this code (in the same document, using the same XmlDocument and XmlNodeList variable)
xmldoc.Load(Path.Combine(Directory.GetCurrentDirectory(), "OEBPS/part1.xhtml"));
"WebException was unhandled: The remote server returned an error: (503) Server Unavailable"
It's a local document, so I'm not understanding why it's giving this error? Any help would be greatly appreciated. :)
I've got the full source code here if it helps: http://drop.io/epubtest
(I know the ePubConstructor.ParseDocument()
method is horribly messy, I'm just trying to get it working at the moment before I split it into classes)
Upvotes: 1
Views: 2142
Reputation: 1
Try the following code :
XmlDocument xmldoc = new XmlDocument();
doc.XmlResolver = null; // this ignores the DTD
xmldoc.Load(Path.Combine(Directory.GetCurrentDirectory(), "META-INF/container.xml"));
XmlNodeList xnl = xmldoc.GetElementsByTagName("rootfile");
Upvotes: 0
Reputation: 161783
Try the following untested code:
XmlDocument xmldoc = new XmlDocument();
XmlReaderSettings settings = new XmlReaderSettings
{
XmlResolver = new XmlUrlResolver()
};
using (var reader = XmlReader.Create(
Path.Combine(Directory.GetCurrentDirectory(),
"OEBPS/part1.xhtml"), settings))
{
xmlDoc.Load(reader);
}
Upvotes: 0
Reputation: 7189
Try to remove the DOCTYPE from the XHTML file, probably you have link to an external DTD.
Upvotes: 2