503(服务器不可用)加载本地 XHTML 文件时发生 WebException
所以我目前正在开发一个 ePub 阅读器应用程序,并且我一直在阅读一堆常规 XML 文件,这与 System.Xml 和 XmlDocument 很好:
XmlDocument xmldoc = new XmlDocument();
xmldoc.Load(Path.Combine(Directory.GetCurrentDirectory(), "META-INF/container.xml"));
XmlNodeList xnl = xmldoc.GetElementsByTagName("rootfile");
但是,现在我正在尝试打开包含实际内容的 XHTML 文件书籍文本,它们是 XHTML 文件。现在我真的不知道两者之间的区别,但我使用此代码收到以下错误(在同一文档中,使用相同的 XmlDocument 和 XmlNodeList 变量)
xmldoc.Load(Path.Combine(Directory.GetCurrentDirectory(), "OEBPS/part1.xhtml"));
“WebException 未处理:远程服务器返回错误: (503) 服务器不可用”
这是一个本地文档,所以我不明白为什么会出现此错误?任何帮助将不胜感激。 :)
如果有帮助的话,我在这里有完整的源代码: http://drop.io/epubtest
(我知道 ePubConstructor.ParseDocument()
方法非常混乱,我只是想让它在我将其分成类之前让它工作)
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)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
尝试从 XHTML 文件中删除 DOCTYPE,可能您有指向外部 DTD 的链接。
Try to remove the DOCTYPE from the XHTML file, probably you have link to an external DTD.
尝试以下未经测试的代码:
Try the following untested code:
尝试以下代码:
XmlDocument xmldoc = new XmlDocument();
doc.XmlResolver = null; // 这会忽略 DTD
xmldoc.Load(Path.Combine(Directory.GetCurrentDirectory(), "META-INF/container.xml"));
XmlNodeList xnl = xmldoc.GetElementsByTagName("rootfile");
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");