• Announcements

    • khawk

      Download the Game Design and Indie Game Marketing Freebook   07/19/17

      GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.
Sign in to follow this  
Followers 0
TheAsterite

How do you read an xml file into code?

12 posts in this topic

Hello,

I'm trying to read in an xml config file with a little information such as screen width, height, and stuff like that, but I'm having a hard time of knowing where to start. I installed an xml parser called Xerces, but there's really no documentation for beginners of the api, and all I'm doing is getting frustrated.

So my question is what's an easy xml parser to pick up with some good tutorials and documentation?
0

Share this post


Link to post
Share on other sites
[quote name='TheAsterite' timestamp='1315369535' post='4858477']
Hello,

I'm trying to read in an xml config file with a little information such as screen width, height, and stuff like that, but I'm having a hard time of knowing where to start. I installed an xml parser called Xerces, but there's really no documentation for beginners of the api, and all I'm doing is getting frustrated.

So my question is what's an easy xml parser to pick up with some good tutorials and documentation?
[/quote]
If your aiming for windows I would use [url="http://msdn.microsoft.com/en-us/data/bb190600"]MSXML[/url]. Good examples and good documentation.
1

Share this post


Link to post
Share on other sites
[quote name='TheAsterite' timestamp='1315369535' post='4858477']
So my question is what's an easy xml parser to pick up with some good tutorials and documentation?
[/quote]

I just started using [url="http://www.grinninglizard.com/tinyxmldocs/index.html"]TinyXML[/url] as I rather like the license, it's tiny, and it works alongside my existing code. There are examples/tutorials on that doc page.
0

Share this post


Link to post
Share on other sites
[quote name='ApochPiQ' timestamp='1315373589' post='4858492']
What language are you using?
[/quote]

I'm using c++, and I'd like to keep it platform independent.
0

Share this post


Link to post
Share on other sites
[quote name='TheAsterite' timestamp='1315376054' post='4858498']
[quote name='ApochPiQ' timestamp='1315373589' post='4858492']
What language are you using?
[/quote]

I'm using c++, and I'd like to keep it platform independent.
[/quote]
I've really enjoyed using [url="http://pugixml.org/"]pugixml[/url]. I particularly like the fact that it has [url="http://www.w3schools.com/xpath/"]XPath[/url] support. Of course, your needs may vary, and pugixml may not be for you, but I would heartily recommend it. It's just 3 files (2 if you take out the configuration header), so I've easily just added it to my project and am using it successfully.
0

Share this post


Link to post
Share on other sites
Thanks for all the suggestions, I'll look into some of these tomorrow.


What I'm trying to do is really basic, it's just to load a simple config file for a game engine, such as height, width, fov, stuff like that.
0

Share this post


Link to post
Share on other sites
[quote name='TheAsterite' timestamp='1315377106' post='4858503']
Thanks for all the suggestions, I'll look into some of these tomorrow.


What I'm trying to do is really basic, it's just to load a simple config file for a game engine, such as height, width, fov, stuff like that.
[/quote]
Just a little code example of what my code is kind of like with pugixml and XPath:

[code]#include <iostream>


#include "pugixml.hpp"

int main()
{
try
{
pugi::xml_document doc;
pugi::xml_parse_result result = doc.load_file("filename.xml");

// only if the loading was successful
if (result)
{
int width = 0;
int height = 0;
std::string title;

pugi::xpath_node node = doc.select_single_node("/Window/Width/@Value");
if (node)
{
width = node.attribute().as_int();
}

node = doc.select_single_node("/Window/Height/@Value");
if (node)
{
height = node.attribute().as_int();
}

node = doc.select_single_node("/Window/Title/@Value");
if (node)
{
title = node.attribute().value();
}
}
else
{
std::cout << "Error: " << result.description() << std::endl;
std::cout << "Error offset: " << result.offset << std::endl;
}
}
catch (std::exception& e)
{
std::cerr << "Exception: " << e.what() << std::endl;
}
}[/code]

It's fairly straightforward and simple. Just thought I'd give a little demo. Of course, like I said, pugixml may not meet your needs the best though (but it sure meets mine!), so be sure to look at the others and just do a little comparison.

Disclaimer: The code above hasn't actually been tested.
0

Share this post


Link to post
Share on other sites
I have been using TinyXML and RapidXml myself. They both worked fine for small tasks.
I don't think they support XPath though, and they don't support the DTD language.
0

Share this post


Link to post
Share on other sites
[quote name='TheAsterite' timestamp='1315377106' post='4858503']
Thanks for all the suggestions, I'll look into some of these tomorrow.

What I'm trying to do is really basic, it's just to load a simple config file for a game engine, such as height, width, fov, stuff like that.
[/quote]

Do you want your XML file to be read at run time or compile time?
0

Share this post


Link to post
Share on other sites
I've used [url="http://www.liquid-technologies.com/xml-editor.aspx"]Liquid XML Editor[/url] in the past which has a pretty decent xml parsing feature plus all the other usual fetaures like data binding, validation etc
0

Share this post


Link to post
Share on other sites
Just an FYI:

Keywords you're looking for in your solution are Marshalling / Unmarshalling & Serialization / Deserialization which is a form of XML Data Binding. From what i'm understanding you want to deserialize / unmarshal the XML into an object reference then access it from there, rather than performing manual searches. A google search with these keyword terms will give you exactly what you're looking for :)
0

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0