I'm trying to parse a XML document that stores data for a map in my 2D game. I'm trying to take this step by step, I've loaded the file, create a new document parser, and picked a start tag and attribute I want to pull. However when I check to see what the value of the attribute should be (25) it comes out as zero. Telling me that i'm missing something and it's not pulling the XML value.
This is the XML file being parsed: http://pastebin.com/tpUU1Wtv
void LoadMap(string filename)
{
enforce( filename != "" , "Filename is invalid!" );
xmlData = cast(string) read(filename);
enforce( xmlData != "", "Read file Failed!" );
}
void ParseMap()
{
auto xml = new DocumentParser(xmlData);
xml.onStartTag["map"] = (ElementParser e)
{
mapWidth = to!int(e.tag.attr["width"]);
};
xml.parse();
writeln("Map Width: ", mapWidth);
}
The current xml module seems to be a bit buggy, an alternative is being worked on, I believe.
The reason your code doesn't work is that for some reason the parser ignores the outer, enclosing tag. Which in your case is "map". If you wrap your map tag in a dummy tag, then suddenly it does work.
<dummy>
<map...>
...
</map>
</dummy>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With