NationStates Jolt Archive


XML automated data feed

Clonetopia
14-04-2004, 17:56
I am aware that the XML automated data feed (http://www.nationstates.net/cgi-bin/nationdata.cgi/nation=clonetopia) can be used to include details of a nation in a website, but I am not sure how. Can anyone help me with this?
Pyro Kittens
16-04-2004, 06:28
interesting clone, where did you get this info from?
Celdonia
16-04-2004, 15:23
I'm afraid it's not that straightforward. Depending on how you want to use it you need to be able to parse (interperate) the data from the XML feed, and then maniplulate it.

The most straightforward way of doing it is by reading it with something like PHP a (free) scripting language used by web developers and then displaying it on an webpage. It's not practical though to read the XML everytime someone loads your webpage (it'll take too long because you'll be hitting the NS server ever time and it puts an unneccessary load on the already overloaded NS server).

The best approach is to put the data into a database (mySQL is free and does the job nicely) and use that to display the information when the page is loaded.

To get all this working you need a webhost that gives you access to PHP and mySQL, or whatever other tools you choose to use.

If that doesn't mean a lot to you then I'm afraid you probably need to know more than I've got time to tell you.

On the Celdonia website I keep stats for the Anticapitalist Alliance (http://www.redfrenzy.com/aca_db.php), The Coalition of Anticapitalist Economies (http://www.redfrenzy.com/cace_db.php), and the International Fair Trade Agreement (http://www.redfrenzy.com/treaty_db.php). I've been asked a few times for the code to do this but unfortunately in it's present form it's a bit messy (it evolved organically) and I end up having to explain how to use it and where to change it for the relevant region, and I just don't have the time. I am however working on some generic code, and intructions for use, that will allow anyone to plug it into their website. Typically though I'm short on time so its in limbo until I get another chance to look at it.

There are lots of other people here who use the XML feeds though, so maybe someone can be more helpful.
Ballotonia
18-04-2004, 08:00
Try the following in your own HTML page.

<HTML><BODY>
<!-- Use the data from one nation, set URL as XML ID -->
<!-- Use your own nation instead of mine ;) -->
<XML ID="NationStates" SRC="http://www.nationstates.net/cgi-bin/nationdata.cgi/nation=ballotonia"></XML>

<!-- Set the DATASRC for this table, using ID -->
<TABLE DATASRC="#NationStates" BORDER="1"><TR>

[!-- Normal entries are used directly as DATAFLD -->
<TD><SPAN DATAFLD="NAME"></SPAN></TD>
</TR><TR>
<TD><SPAN DATAFLD="REGION"></SPAN></TD>
</TR><TR>

<!-- Exception one: handling the subfields, use another table -->
<TD><TABLE DATAFLD="FREEDOM" DATASRC="#NationStates"><TR>
<TD><SPAN DATAFLD="CIVILRIGHTS"></SPAN></TD>
</TR><TR>
<TD><SPAN DATAFLD="ECONOMY"></SPAN></TD>
</TR><TR>
<TD><SPAN DATAFLD="POLITICALFREEDOM"></SPAN></TD>
</TR></TABLE></TD>
</TR><TR>

<!-- Exception two: flag image URL -->
<TD><IMG DATASRC="#NationStates" DATAFLD="FLAG"></TD>

</TR></TABLE>
</BODY></HTML>


Ballotonia
Unfree People
18-04-2004, 10:16
Wow... how come no one's ever given such a simple explanation of such a hard to grasp concept before? I've had it explained to me a dozen times how to use the datafeed... but nothing explains it as neatly as your html, Ballo... thank you lol
Ballotonia
18-04-2004, 10:42
Wow... how come no one's ever given such a simple explanation of such a hard to grasp concept before? I've had it explained to me a dozen times how to use the datafeed... but nothing explains it as neatly as your html, Ballo... thank you lol

Well, those who don't speak basic HTML will not likely be able to use the XML feed no matter what. Also keep in mind this is just to display stuff for a limited few items. It's not suitable to create a whole regional census, which will require the more complex stuff which I'm not about to attempt to explain. Not in the least because I'm not an expert myself ;)

BTW, the stuff above is based on a similar example I got from someone else. While it works, I don't use it myself as I use Tcl scripts.

Ballotonia
Unfree People
19-04-2004, 03:48
Heh, it works perfectly for me and I know enough html to make it do exactly what I want it to do. I've never wanted regional censi, just to be able to play around with the data feed in a way I could understand :D
Topnotch Toast
19-04-2004, 06:32
BTW, it only works on IE5+.

-Toast