Allegro.cc - Online Community

Allegro.cc Forums » Programming Questions » Anyone know how to use rapidxml?

This thread is locked; no one can reply to it. rss feed Print
Anyone know how to use rapidxml?
DJLad16
Member #14,857
January 2013

I need to use the rapidxml parser so I can get a map a created on tiled into my game. But I have no idea what to do. I've included the things it says on the manual, but no other things help. There's also no tutorials at all on it. I would appreciate any help :D

Endgegner
Member #15,006
March 2013
avatar

Do you really need or just want to use RapidXml?

I haven't used RapidXml myself, so I can't say more about it, but I can recommend pugixml as an alternative. It is dead simple to use and it even has XPath support (RapidXml doesn't). XPath is a powerfull language for navigating XML documents.

Just download the pugixml sources from pugixml.org and include pugixml.hpp in your project.

Let this be your XML file:

<?xml version="1.0" encoding="UTF-8"?>
<monsters>
    <monster name="Tentacle Beast" evilness="12"/>
    <monster name="Zombie" evilness="10"/>
    <!-- Add more monsters here ... -->
</monsters>

Then you can parse it like that:

pugi::xml_document xmlDocument;
auto result = xmlDocument.load_file("path/to/file.xml");

if (result.status == pugi::status_ok) {
    auto monsters = xmlDocument.child("monsters");

    for (auto monster : monsters.children("monster")) {
        std::cout << "Name: " << monster.attribute("name").value() << std::endl;
        std::cout << "Evilness: " << monster.attribute("evilness").as_int() << std::endl;
    }
}
else {
    // Handle parsing and IO errors here ...
}

You can find much more examples in the pugixml documentation [pugixml.org].

Hope this helps.

Thomas Fjellstrom
Member #476
June 2000
avatar

You may also want to consider tinyxml2 [www.grinninglizard.com] if you are handling the xml->map yourself.

--
Thomas Fjellstrom - [website [www.strangesoft.net]] - [email] - [Allegro Wiki] - [Allegro TODO]
"If you can't think of a better solution, don't try to make a better solution." -- weapon_S
"The less evidence we have for what we believe is certain, the more violently we defend beliefs against those who don't agree" -- https://twitter.com/neiltyson/status/592870205409353730

Go to: