This is an extension of a question I had beforehand
I have a specific function that I want to run, and it is located inside an XML File:
Console.WriteLine("Text for test, {0}, {1}", testWord, testWord2);
The text is stored in an XML file:
<?xml version="1.0" encoding="utf-8" ?> <root> <world> <region name="TestRegion"> <area name="TestArea"> <building name="Outside"> <room name="TutorialRoom"> <textToDisplay>"Text for test, {0},{1}"</textToDisplay> <extraString>testWord,tesWord2</extraString> </room> </building> </area> </region> </world> </root>
I can easily get the string data using LINQ
XElement xelement = XElement.Load("..\\..\\LocationDatabase.xml"); var textToDisplay= xelement.Elements("world") .Elements("region").Where(region => (string)region.Attribute("name") == "TestRegion") .Elements("area").Where(area => (string)area.Attribute("name") == "TestArea") .Elements("building").Where(building => (string)building.Attribute("name") == "Outside") .Elements("room").Where(room => (string)room.Attribute("name") == "TutorialRoom") .Elements("textToDisplay"); var extraString= xelement.Elements("world") .Elements("region").Where(region => (string)region.Attribute("name") == "TestRegion") .Elements("area").Where(area => (string)area.Attribute("name") == "TestArea") .Elements("building").Where(building => (string)building.Attribute("name") == "Outside") .Elements("room").Where(room => (string)room.Attribute("name") == "TutorialRoom") .Elements("extraString");
And this works completely fine. The issue I have is when I don't have a word in the XML file, but rather a property of a class. I have a singleton Player, and it has a autoproperty Name. To normally access it, I can just say:
Console.WriteLine("Your name is:", Player.Instance.Name);
But how do I, instead, keep this in the XML file? Like:
<?xml version="1.0" encoding="utf-8" ?> <root> <world> <region name="TestRegion"> <area name="TestArea"> <building name="Outside"> <room name="TutorialRoom"> <textToDisplay>"Your name is: {0}"</textToDisplay> <extraString>Player.Instance.Name</extraString> </room> </building> </area> </region> </world> </root>
When I use the past command, it simple thinks that whole section is a string, and outputs "Your name is: Player.Instance.Name"
Is there a way to solve this?
No comments:
Post a Comment