Sign in to follow this  
C plus noob

How do you create and read in .xml files for your program?

Recommended Posts

Drew_Benton    1861
Quote:
Original post by stanVman
Could I use tinyXML to save and open HighScore struct's for my game?


Yes, if you wanted to. XML is just a format for data to be held in. Technically, you can store anything in XML, I've seen maps, models, html data, etc... used before. Now that's not going to say it's the *best* method, but it's do-able.

If you want to use XML with a high score table, you'd want to first design the format it will be taking on, such as:

<root>
<Entry>
<Name>Unknown</Name>
<Score>1000</Score>
<Rank>1</Rank>
</Entry>

<Entry>
<Name>Unknown 2</Name>
<Score>1000</Score>
<Rank>2</Rank>
</Entry>
</root>

Then it's just a matter of using TinyXML to properly parse that data and extract it. Not much to it really, keep in mind that there are alternatives that might be quicker and more suited for highscores though.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster   
Guest Anonymous Poster
Why optimise the High Score code for Speed?

P.S. You could also use an embedded SQL which might be better.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster   
Guest Anonymous Poster
---Add a High score---

INSERT INTO HighScore
(Name, Score)
VALUES
('%Name%', %LatestScore%)


---Display HighScore---
SELECT TOP 10 Name, Score
FROM HighScore
ORDER BY Score DESC



http://www.sqlite.org/

Share this post


Link to post
Share on other sites
Guest Anonymous Poster   
Guest Anonymous Poster
i use microsoft xml sdk. i forget where i got it. i think
latest version is 4.2 u can get it from MSDN. there was a
version 5 i believe that came with MSOffice but don't think
it's supported anymore.

Share this post


Link to post
Share on other sites
helix    301
We use some homebrew xml parser that someone wrote in java and I ported to c++. It kinda sucks but it's very low impact and simple which is a huge plus for our needs.

Share this post


Link to post
Share on other sites
SirLuthor    364
I guess that would make me the only one here who finds XML to be extremely ugly and ill-readable. I cannot honestly see this fixation with turning everything into XML, it's awful nasty stuff, and I hope never to have the misfortune of having to type or read any of it. A dying breed, those who don't like XML....

Anyway, as the others have said, if you wish to make things ugly, there are innumerable XML libraries out there, a good google search should bring even more to light, if you don't like the options already mentioned.

Share this post


Link to post
Share on other sites
helix    301
If you don't like XML, what do you use instead?

I would agree about it being ugly, but it's very powerful and robust and widely used and supported so that more than makes up for it in my opinion.

Share this post


Link to post
Share on other sites
SirLuthor    364
I wrote my own configuration file parser (for configuration files, naturally) with namespaces, variable types, etc, all sorts of junk I figured I would need. For basically any other file that needs to be read in, I'll go with a pure binary file, simply because it's the easiest and fastest in and out.

Share this post


Link to post
Share on other sites
mfawcett    373
Quote:
Original post by SirLuthor
I guess that would make me the only one here who finds XML to be extremely ugly and ill-readable. I cannot honestly see this fixation with turning everything into XML, it's awful nasty stuff, and I hope never to have the misfortune of having to type or read any of it. A dying breed, those who don't like XML....

Anyway, as the others have said, if you wish to make things ugly, there are innumerable XML libraries out there, a good google search should bring even more to light, if you don't like the options already mentioned.


I agree it's pretty unreadable, but it's incredibly nice for interoperability between unrelated programs, which is what is was made for.

For instance, web services is one place where it's used quite frequently. I can create a web service that takes in some source and destination longitude/latitude and return you a route from point A to point B (e.g. MapQuest). Now anybody in the world can create a thin or thick client to interact with that web service. You could have a thin client call the web service, get the XML result, and display it in the web page as a jpg. You could have a thick client use GDI, and yet another thick client render it in real time using DirectX or OpenGL. Without any modification, you could even send the XML to a DataGrid control in a dialog.

So let's move on over to games. Say our User Interface is described by XML files. Now anybody in the world can make their own UI editor that exports to XML and our game will happily accept their designs. If we had used a custom binary format, nobody could write a UI editor without first figuring out that format, and even if we released it, they'd have to write their own exporter that wrote to that format, whereas there are quite a few XML libraries already in use.

I am usually of the opinion that XML should be generated, not manually entered. Therefore, you should never have to type it, or read it.

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