XML parsing in D

I am trying to parse an XML document that stores data for a map in my 2D game. I am trying to do this step by step, I downloaded the file, create a new document parser and selected the start tag and the attribute that I want to extract. However, when I check what the attribute value should be (25) it appears as zero. Telling me that I missed something and it won't pull in the XML value.

This XML file is being processed: 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);
}

      

+3


source to share


2 answers


The current xml module seems to be a bit buggy, in my opinion the alternative works.

The reason your code is not working is because for some reason the parser ignores the outer tag that contains the tags. Which in your case is a "map". If you put your map tag into a dummy tag, then suddenly it works.



<dummy>
   <map...>
    ...
   </map>
</dummy>

      

+3


source


Does YAML use a parameter? D-YAML?



+1


source







All Articles