I am building a WPF application. Inside that application I am using the XmlReader class to parse several local XML files. The code I have written works perfectly during debugging, but fails once I publish the application and install it.
I have the XML documents as CONTENT in build action, and I have them set to COPY ALWAYS.I can confirm that the XML documents are being deployed in my build and are in tact in the application folder once installed.
What further confuses me is that I am using the same XmlReader code to parse RSS feeds from external websites in this application without problem. It only fails on the local XML documents.
Does anyone know why my XmlReader would fail to parse local XML documents once the application is published?
Here is a small snippet of my XmlReader code for referance:
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
{
}
Here is my 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>