So I’m having trouble converting my game over to XML/Linq, which I need to do because the project has expanded. It seems like such a simple problem, but the XML file I’ve loaded into my content is not found. If I try to load the XML file from the directory, it works fine, but how do I load from the Content files I’ve included in the project?
Do I need to somehow apply Content.Load to be able to access the file, or flag the file differently? I’ve currently got the flags set to Content (not compile), Content Importer is XML Content – XNA Framework, Content Processor – No Processing Required, Copy to Output Directory – Copy Always.
Thanks for the help. I feel a bit dumb having to ask. I put 3 z’s next to the line in question. Thanks again!
class GameObject
{
public string objectType;
public string objectID;
public bool isActive;
}
struct option
{
public string optionName;
public string type;
public string command;
}
class TitleScreen : GameObject
{
XDocument TitleData;
public int totalOptions;
List<option> optionsShared = new List<option>();
int currentDrawObject;
public void Init(string TitleID)
{
objectType = "TitleScreen";
objectID = "Title";
isActive = true;
zzz TitleData = XDocument.Load("TitleData.xml"); zzz
var options =
from x in TitleData.Descendants("option")
select new
{
type = x.Descendants("otype").First().Value,
optionName = x.Descendants("oname").First().Value,
command = x.Descendants("ocommand").First().Value
};
foreach (var x in options)
{
optionsShared.Add( new option
{optionName = x.optionName,
type = x.type,
command = x.command
});
}
foreach (var option in options)
{
totalOptions += 1;
}
}
public void Draw(SpriteBatch sb, SpriteFont sf)
{
currentDrawObject = 0;
sb.Begin();
foreach (var option in optionsShared)
{
currentDrawObject += 1;
sb.DrawString(sf, option.optionName, new Vector2(50, 100 * currentDrawObject), Color.White);
}
sb.End();
}
}
you have to mark your xml file “TitleData.xml” as Content and Always Copy.
be carefull if you set this xml in a specific folder in output you will have to specify path
that is
in debug mode you can see setting a break point application path to know how to get good path