I'm sorry for bumping this old thread but I recently started working on this again and have come up with a new problem/question for everyone here.
I decided to go back and change the way the characters are stored. In the past they were plain-text, one line = one value with no descriptions. They are now XML. This is my first time working with XML (in any language) but I think the character file is working 100% because there's no repeating value.
I want to create the world file as XML too. However, I have a problem. Let's say the world file looks something like this:
Code:
<world>
<0001>
<Description>A description of the first room</description>
<exits>north, south</exits>
<north exit>0002</north exit>
<south exit>0003</south exit>
</0001>
<0002>
<Description>A description of the second room</description>
<exits>south</exits>
<south exit>0001</south exit>
</0002>
. . .
</world>
And so on, and so forth. From what I understand, when I do a search of the XML file it's going to stop at the first match. So if I search for "description" it's going to come to 0001's, read that description and that's it. It'll stop even if I want 0002's, or any other's. Same with any of the other values.
This is how I have it set up to return a value from the character file. The incoming String node is what value I'm looking for (strength, health, password, name, whatever).
Code:
public String getData(String node)
{
characterReader = new XmlTextReader(file);
characterReader.WhitespaceHandling = WhitespaceHandling.None;
characterReader.Namespaces = false;
String data = "";
while (characterReader.Read())
{
if (characterReader.NodeType == XmlNodeType.Element)
{
if (characterReader.LocalName.Equals(node))
{
data = characterReader.ReadString();
break;
}
}
}
characterReader.Close();
// Finally, return with the data we were after.
return data;
}
So, does anyone know how to overcome the problem I'm going to face designing the world file in XML?