503(服务器不可用)加载本地 XHTML 文件时发生 WebException

发布于 2024-09-03 01:26:48 字数 831 浏览 4 评论 0原文

所以我目前正在开发一个 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

新人笑 2024-09-10 01:26:49

尝试从 XHTML 文件中删除 DOCTYPE,可能您有指向外部 DTD 的链接。

Try to remove the DOCTYPE from the XHTML file, probably you have link to an external DTD.

小耗子 2024-09-10 01:26:49

尝试以下未经测试的代码:

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);
}

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);
}
っ〆星空下的拥抱 2024-09-10 01:26:49

尝试以下代码:

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");

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文