【发布时间】:2008-11-02 04:51:01
【问题描述】:
我正在构建一个 WPF 应用程序。在该应用程序中,我使用 XmlReader 类来解析几个本地 XML 文件。我编写的代码在调试期间完美运行,但在我发布应用程序并安装后就失败了。
我在构建操作中将 XML 文档作为 CONTENT,并将它们设置为 COPY ALWAYS。我可以确认 XML 文档正在我的构建中部署,并且在安装后完好无损地保存在应用程序文件夹中。
让我更加困惑的是,我在这个应用程序中使用相同的 XmlReader 代码来解析来自外部网站的 RSS 提要没有问题。它只在本地 XML 文档上失败。
有谁知道为什么我的 XmlReader 在应用程序发布后无法解析本地 XML 文档?
这是我的 XmlReader 代码的一个小 sn-p 供参考:
XmlReaderSettings settings = new XmlReaderSettings();
settings.IgnoreComments = true;
settings.IgnoreProcessingInstructions = true;
settings.IgnoreWhitespace = true;
try
{
settingsReader = XmlReader.Create("Resources/data/TriviaQuestions.xml", settings);
nodeNum = 0;
while (settingsReader.Read())
{
switch (settingsReader.NodeType)
{
case XmlNodeType.Element:
if (settingsReader.HasAttributes)
{
for (int i = 0; i < settingsReader.AttributeCount; i++)
{
settingsReader.MoveToAttribute(i);
_feeds[nodeNum] = settingsReader.Value.ToString();
}
settingsReader.MoveToContent(); // Moves the reader back to the element node.
}
break;
case XmlNodeType.Text:
_questions[nodeNum] = settingsReader.Value;
nodeNum++;
break;
}
}
settingsReader.Close();
}
catch
{
}
这是我的 XML
<?xml version="1.0" encoding="utf-8" ?>
<Questions>
<Question feed="http://entertainment.msn.com/rss/topboxoffice/">What movie has the top box office sales in the US right now?</Question>
<Question feed="http://entertainment.msn.com/rss/topdvdrentals/">What is the top DVD rental in the US this week?</Question>
<Question feed="http://entertainment.msn.com/rss/topalbums/">Which of the following albums is currently topping the charts?</Question>
</Questions>
【问题讨论】:
-
这将有助于准确了解正在发生的故障类型,以便我们知道要寻找什么。