NationStates Jolt Archive


XML Feed

Los Paranoias
15-07-2004, 14:49
Could someone, preferably one of the staff, explain how it would be possible to include data from the XML feed into a website?

From my (albeit limited) knowledge of XML and XSL, I understand it is necessary to include a link to an external stylesheet within the XML... but the XML feed from Nationstates cannot be edited. So, how is it possible to format and display the information that the feed gives you?

I've heard talk of using complex PHP strings to parse the XML into another XML page, but surely there is a simpler way I am just overlooking?

Thanks in advance.
Enerica
15-07-2004, 15:09
Well I'm not staff but I do make a GDP calculator and I use Javascript

Like so:




//First create the object

var xmlDoc = new ActiveXObject("Microsoft.XMLDOM")

//then load it

xmlDoc.async = "false";
xmlDoc.load("http://www.nationstates.net/cgi-bin/nationdata.cgi/nation=enerica")

//then get the variables

var fullname = xmlDoc.getElementsByTagName('FULLNAME').item(0).text



etc then use it

php haven't got a clue but I bet it involves loops. Javascript is the way to go!
Enerica
15-07-2004, 15:11
Oh then to put that into a website you just print the variable onto the screen



document.write("Name: "+ fullname + "<br />")


etc
Enerica
15-07-2004, 15:13
And obviously to format it just include html tags in the

document.write("<b>Name:</b><i>"+fullname+"</i><br />")

Then when the page loads it should place that information on the page, with this in the source code



<b>Name:</b><i>United Conservative States of Enerica</i><br />
Nianacio
16-07-2004, 00:44
Enerica's example uses ActiveX, so I think it'll only be useable in IE on Windows. I know it doesn't work in Opera. :(
Enerica
16-07-2004, 09:24
Enerica's example uses ActiveX, so I think it'll only be useable in IE on Windows. I know it doesn't work in Opera. :(
Doesn't work on Netscape either, but I have ceased to have any sympathy for people who use that browser :D

It uses a MS parser.
Sunset
16-07-2004, 09:40
php.net has some examples of xml parsers that do a fine job of stuffing the whole XML feed into a single array - just pull and play from there.

</. rant> Support open standards and don't use browser dependant code.</end /. rant>
Enerica
16-07-2004, 12:39
<rant>Javascript is and excellent coding language and it's peoples own fault if they use a substandard browser like Netscape</rant>

:D
Myrth
16-07-2004, 13:07
<rant>Javascript is and excellent coding language and it's peoples own fault if they use a substandard browser like Netscape</rant>

:D

IE is the standard of substandard :p
Amicus curiae
16-07-2004, 13:23
There is no activeX in Mozilla Firefox by default, which makes it much more secure.
Enerica
16-07-2004, 13:40
IE is the standard of substandard :p
The only saving grace Netscape has is a pop-up blocker which doesn't work.

And Opera is just annoying. Which is why I choose to be vindictive towards both :D
Petsburg
16-07-2004, 13:51
The only saving grace Netscape has is a pop-up blocker which doesn't work.

And Opera is just annoying. Which is why I choose to be vindictive towards both :D

And what about mozzila? :P
Enerica
16-07-2004, 13:54
And what about mozzila? :P
Meh

The whole world should be forced to use the browser that is best for me! :D
Doujin
16-07-2004, 14:12
Enerica, your lack of consideration for every other browser is probably why your calculator sucks :)
Enerica
16-07-2004, 15:57
Enerica, your lack of consideration for every other browser is probably why your calculator sucks :)

You must die for that Doujin :D

I happen to have gone off my calculator, which is why I am remaking it as an xml version, meaning you only have to put in your nation name :D

I will now look smug in my hate for other browsers.
Goobergunchia
16-07-2004, 22:20
*smacks Enerica with various W3C standards*
Nianacio
16-07-2004, 23:49
<rant>Javascript is and excellent coding language and it's peoples own fault if they use a substandard browser like Netscape</rant>Javascript isn't the issue; ActiveX is.
The only saving grace Netscape has is a pop-up blocker which doesn't work.Opera has one that does work. ;)
And Opera is just annoying.What's wrong with it? It works a lot better than IE for me. :/
Defaultia
17-07-2004, 01:03
Well, the Firefox browser's popup blocker does work.

And IE doesn't have a popup blocker unless you install Google Toolbar. And Google runs on Linux.

Micro$oft products are crap, and they're losing marketshare.

*puts a Posted with Linux sticker on this post*
The Most Glorious Hack
17-07-2004, 05:55
Popup blockers? Feh. I hates them.
Enerica
17-07-2004, 10:36
Popup blockers? Feh. I hates them.
Yay for pop ups.

The reason the Javascript doesn't work for the others is like has been said, it uses an IE only XMLDOM. I use all three browsers, I just use IE more.
Enerica
17-07-2004, 10:38
*smacks Enerica with various W3C standards*
This is what I think of your standards




<font color = red>Hello World</font>



:D
Defaultia
17-07-2004, 14:02
This is what I think of your standards




<font color = red>Hello World</font>



:D

And this is what I think of your M$-HTML:



<font color="red">Standards compliance matters</font><br />



Unfortunately, I couldn't think of anything which wouldn't work in Micro$oft Internet Explorer.

*whacks Enerica around with tons of W3C standards, then hacks his/her computer and installs Linux on it*
Nianacio
17-07-2004, 19:29
Unfortunately, I couldn't think of anything which wouldn't work in Micro$oft Internet Explorer.You can crash IE by using certain pieces of standards-compliant code, but I don't know what they are.
Enerica
18-07-2004, 13:43
installs Linux on it*

I have a screensaver on my laptop that does that :D

Netscape and IE both react to tables in the same way, however Opera is annoyingly different and has to do what you say!

*creates an non-standard dtd*
E-Xtremia
28-07-2004, 03:56
Well I'm not staff but I do make a GDP calculator and I use Javascript

Like so:




//First create the object

var xmlDoc = new ActiveXObject("Microsoft.XMLDOM")

//then load it

xmlDoc.async = "false";
xmlDoc.load("http://www.nationstates.net/cgi-bin/nationdata.cgi/nation=enerica")

//then get the variables

var fullname = xmlDoc.getElementsByTagName('FULLNAME').item(0).text



etc then use it

php haven't got a clue but I bet it involves loops. Javascript is the way to go!


It works as you have typed it... as long as I do not try to use a 2-or-more-word name... I have tried _'s, %20's, and just spaces... but I cannot make it read... any suggestions?

Also, how do I make the URL for the flag appear in an IMG tag? it wont allow me to do it
Enerica
28-07-2004, 07:59
In javascript (and I assume same idea for php), assign it as a string to a variable

then

document.write("<img src = '"+flagvar+"' >")

Or I think its printf for php
Enerica
28-07-2004, 08:02
As for a two or more word name, not sure it seems to work when I've done it.

Try putting the name in a variable and then using the same idea as above to post the name into the string (i.e. the string that is the name of the file to open)

i.e.


//First create the object

var xmlDoc = new ActiveXObject("Microsoft.XMLDOM")

//then load it

var name = "Salusa Secondus"
xmlDoc.async = "false";
xmlDoc.load("http://www.nationstates.net/cgi-bin/nationdata.cgi/nation="+name)

//then get the variables

var fullname = xmlDoc.getElementsByTagName('FULLNAME').item(0).text
New Genoa
29-07-2004, 03:10
And this is what I think of your M$-HTML:



<font color="red">Standards compliance matters</font><br />



Unfortunately, I couldn't think of anything which wouldn't work in Micro$oft Internet Explorer.

*whacks Enerica around with tons of W3C standards, then hacks his/her computer and installs Linux on it*

GAH!!



<span style="color:red;">Standards compliance matters and the font tag is deprecated.</span><br />
Enerica
29-07-2004, 09:20
Argh!! Stylesheet obsessive

*whacks with a separate css file with only a:link etc in it*


<color =red>Hello<br />

:P
New Genoa
29-07-2004, 19:06
GAH! The <color> tag doesn't even exist! :sniper:
Enerica
29-07-2004, 19:41
burn!


:D
Commerce Heights
01-08-2004, 23:32
<span style="color:red">No need to put a semicolon at the end of the style, New Genoa</span>
*smacks Enerica with NSEconomy's standards-compliance* http://terranordalis.thirdgeek.com/images/smiles/icon_razz.gif
New Genoa
01-08-2004, 23:37
It's a habit, just in case I need to add more. But NSEconomy still uses tables. HA!
E-Xtremia
05-08-2004, 06:02
As for a two or more word name, not sure it seems to work when I've done it.

Try putting the name in a variable and then using the same idea as above to post the name into the string (i.e. the string that is the name of the file to open)

i.e.


//First create the object

var xmlDoc = new ActiveXObject("Microsoft.XMLDOM")

//then load it

var name = "Salusa Secondus"
xmlDoc.async = "false";
xmlDoc.load("http://www.nationstates.net/cgi-bin/nationdata.cgi/nation="+name)

//then get the variables

var fullname = xmlDoc.getElementsByTagName('FULLNAME').item(0).text

Well... that fixed it... I thank you...

but for some reason... all but one of the nations in the region work (one of my alts, "Deleted Nation")! :headbang:
Rapid Dr3am
05-08-2004, 14:10
<?php
/***************************************************************************
* nationstate.php
* -------------------
* begin : Friday, 23, May, 2003
* copyright : (C) Robin Morrison (People's Republic of Winnipeg)
*
*
***************************************************************************/

/***************************************************************************
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
***************************************************************************/
//check to see if a nation has been specified

$nation = 'rapid_dr3am'; //You can feel free to change this to the default nation of your choice.

// Open and read the XML Output

$fileName = "http://www.nationstates.net/cgi-bin/nationdata.cgi/nation=".$nation;

$size = "800";
$fp = fopen($fileName,'r');
$text = fread($fp,$size);
fclose($fp);

//Create the Array of feed sections. Just use the ones you need.
//To see all the avalible sections visit http://www.nationstates.net/cgi-bin/nationdata.cgi/nation=xxx
$section = array( 1 => "FULLNAME",
2 => "MOTTO",
3 => "CATEGORY",
4 => "UNSTATUS",
5 => "CIVILRIGHTS",
6 => "ECONOMY",
7 => "POLITICALFREEDOM",
8 => "REGION",
9 => "POPULATION",
10 => "TAX",
11 => "ANIMAL",
12 => "CURRENCY",
13 => "FLAG",
14 => "MAJORINDUSTRY",
15 => "GOVTPRIORITY",
16 => "LASTLOGIN",
17 => "LASTACTIVITY",
);

//Now run a foreach that goes through the array we just created.
foreach ($section as $var) {
$open = "<".$var.">";
$close = "</".$var.">";
$start = strpos($text,$open);
$end = strpos($text,$close);
$length = $end - $start;

$val = substr($text,$start,$length);
//Make sure that these if() statements reflect the options you used in the $section array
if ($var == 'FULLNAME') { $name = str_replace($open, '', $val); }
if ($var == 'MOTTO') { $motto = str_replace($open, '', $val); }
if ($var == 'CATEGORY') { $category = str_replace($open, '', $val); }
if ($var == 'UNSTATUS') { $unstatus = str_replace($open, '', $val); }
if ($var == 'CIVILRIGHTS') { $civilrights = str_replace($open, '', $val); }
if ($var == 'ECONOMY') { $economy = str_replace($open, '', $val); }
if ($var == 'POLITICALFREEDOM') { $political = str_replace($open, '', $val); }
if ($var == 'REGION') { $region = str_replace($open, '', $val); }
if ($var == 'POPULATION') {
$pop = str_replace($open, '', $val);
//This Just changes the Population Output to Billions if it is more than 1000
if ($pop >= 1000) {
$pop = round($pop/1000, 2);
$postfix = "Billion";
} else {
$postfix = "Million";
}
}
if ($var == 'TAX') { $tax = str_replace($open, '', $val); }
if ($var == 'ANIMAL') { $animal = str_replace($open, '', $val); }
if ($var == 'CURRENCY') { $currency = str_replace($open, '', $val); }
if ($var == 'FLAG') { $flag = str_replace($open, '', $val); }
if ($var == 'MAJORINDUSTRY') { $industry = str_replace($open, '', $val); }
if ($var == 'GOVTPRIORITY') { $priority = str_replace($open, '', $val); }
if ($var == 'LASTLOGIN') { $lastlogin = str_replace($open, '', $val); }
if ($var == 'LASTACTIVITY') { $lastactivity = str_replace($open, '', $val); }
}

//Check to see if a Message has been set ($msg)
if (isset($msg)) {
echo "<font color=\"red\" size=\"3\">".$msg."</font><br><br>";
}
?>
<table border="0">
<tr>
<td valign="top" align="right"><font color="FFFFFF">FLAG:</font></td>
<td align="center"><img src="<? print($flag); ?>" style="border: 0 solid black;"></td>
</tr><tr>
<td align="right"><font color="FFFFFF">Full Name:</font></td>
<td><? print($name); ?></td>
</tr><tr>
<td align="right"><font color="FFFFFF">Motto:</font></td>
<td><? print($motto); ?></td>
</tr><tr>
<td align="right"><font color="FFFFFF">Category:</font></td>
<td><? print($category); ?></td>
</tr><tr>
<td align="right"><font color="FFFFFF">UN Status:</font></td>
<td><? print($unstatus); ?></td>
</tr><tr>
<td align="right"><font color="FFFFFF">Civilrights:</font></td>
<td><? print($civilrights); ?></td>
</tr><tr>
<td align="right"><font color="FFFFFF">Economy:</font></td>
<td><? print($economy); ?></td>
</tr><tr>
<td align="right"><font color="FFFFFF">Political Freedoms:</font></td>
<td><? print($political); ?></td>
</tr><tr>
<td align="right"><font color="FFFFFF">Region:</font></td>
<td><? print($region); ?></td>
</tr><tr>
<td align="right"><font color="FFFFFF">Population:</font></td>
<td><? print($pop."&nbsp;".$postfix); ?></td>
</tr><tr>
<td align="right"><font color="FFFFFF">Tax:</font></td>
<td><? print($tax); ?>%</td>
</tr><tr>
<td align="right"><font color="FFFFFF">Animal:</font></td>
<td><? print($animal); ?></td>
</tr><tr>
<td align="right"><font color="FFFFFF">Currency:</font></td>
<td><? print($currency); ?></td>
</tr><tr>
<td align="right"><font color="FFFFFF">Major Industry:</font></td>
<td><? print($industry); ?></td>
</tr><tr>
<td align="right"><font color="FFFFFF">Government Priority:</font></td>
<td><? print($priority); ?></td>
</tr><tr>
<td align="right"><font color="FFFFFF">Last Login:</font></td>
<td><? print($lastlogin); ?></td>
</tr><tr>
<td align="right"><font color="FFFFFF">Last Active:</font></td>
<td><? print($lastactivity); ?></td>
</tr>
</table>
</span>
</td>
</tr>
</table>

<br />


Demo: http://www.rapiddr3am.net/nationstate.php
E-Xtremia
06-08-2004, 06:29
Demo: http://www.rapiddr3am.net/nationstate.php


I thank you... but I was trying to avoid PHP if at all possible... it is overly confusing...

Which file would be smaller though? an entire region using PHP, or entire region using Java?

You can see the page I am working on by clicking on the link below:

http://www.tge.vze.com and then click "Census" in the left flash bar...
Rapid Dr3am
09-08-2004, 00:49
Well I would use PHP, Not because I'm a PHP programmer but because JavaScript is the most evil thing to ever come into web design in all my years.

Basically with php I say, read the file and parse the contents out as html.

With javascript I say hey browser, gona let me do this? And the browser might say no.

So if I have js disabled and you are using it I can't dee it but I don't know any browsers that disable html pretty pointless.

Also JS is slow, and buggy.
Gothic Kitty
09-08-2004, 11:50
I have a php forum. Can I use that script on my forum? If yes, where would I place it?
Cork South Central
09-08-2004, 13:37
Demo: http://www.rapiddr3am.net/nationstate.php

does anyone have an (or know how to) updated version of this php for the newer XML file?
Heftig
09-08-2004, 14:02
What do you mean "newer xml file"?

Is there more than one XML feed? Are there different versions?
Do they contain different data?

Questions over questions... Does anyone know?
Rapid Dr3am
09-08-2004, 15:25
I didn't know this had all been added.

- <GOVT>
<ADMINISTRATION>0%</ADMINISTRATION>
<WELFARE>0%</WELFARE>
<HEALTHCARE>0%</HEALTHCARE>
<EDUCATION>3%</EDUCATION>
<SPIRITUALITY>20%</SPIRITUALITY>
<DEFENCE>18%</DEFENCE>
<LAWANDORDER>43%</LAWANDORDER>
<COMMERCE>16%</COMMERCE>
<PUBLICTRANSPORT>1%</PUBLICTRANSPORT>
<ENVIRONMENT>0%</ENVIRONMENT>
<SOCIALEQUALITY>0%</SOCIALEQUALITY>
</GOVT>
Goobergunchia
09-08-2004, 21:13
It was added following the Jolt move.
Cork South Central
10-08-2004, 10:21
It was added following the Jolt move.
was it announced on the News section that there was an updated XML file?? (probs was, I just missed it!)
Rapid Dr3am
10-08-2004, 20:01
Well someone should ask Winnipeg, if he wants to update his code. :)
SalusaSecondus
10-08-2004, 22:06
was it announced on the News section that there was an updated XML file?? (probs was, I just missed it!)

Nah, there were a few upgrades that we forgot to announce. I don't think that we announced BBCode in the Factbook entries either.
Winnipeg
11-08-2004, 19:21
Demo: http://merit.jink.org/winnipeg/ns_xml.php

<?php
// Basic NationStates.net XML Feed Reader
// Coded by Robin Morrison (People's Republic of Winnipeg)
// Updated Aug 11th 2004
// Free for use by anyone as long as this header remains in the code

//check to see if a nation has been specified
if (isset($_REQUEST['nation'])) {
$nation = $_REQUEST['nation'];
} else {
$nation = 'Winnipeg'; //You can feel free to change this to the default nation of your choice.
$msg = 'No Nation was Selected. Using Default Nation. ('.$nation.')';
}

// Open and read the XML Output

$fileName = "http://www.nationstates.net/cgi-bin/nationdata.cgi/nation=".$nation;

$size = "1200";
$fp = fopen($fileName,'r');
$text = fread($fp,$size);
fclose($fp);

//Create the Array of feed sections. Just use the ones you need.
//To see all the avalible sections visit http://www.nationstates.net/cgi-bin/nationdata.cgi/nation=winnipeg

$section = array( 0 => "NAME",
1 => "TYPE",
2 => "MOTTO",
3 => "CATEGORY",
4 => "UNSTATUS",
5 => "CIVILRIGHTS",
6 => "ECONOMY",
7 => "POLITICALFREEDOM",
8 => "REGION",
9 => "POPULATION",
10 => "TAX",
11 => "ANIMAL",
12 => "CURRENCY",
13 => "FLAG",
14 => "MAJORINDUSTRY",
15 => "GOVTPRIORITY",
16 => "LASTLOGIN",
17 => "LASTACTIVITY",
18 => "ADMINISTRATION",
19 => "WELFARE",
20 => "HEALTHCARE",
21 => "EDUCATION",
22 => "SPIRITUALITY",
23 => "DEFENCE",
24 => "LAWANDORDER",
25 => "COMMERCE",
26 => "PUBLICTRANSPORT",
27 => "ENVIRONMENT",
28 => "SOCIALEQUALITY",
);

//Create the Array for the names to use in the $nations Array
//I use a second array because I don't like using all Caps in my arrays

$section2 = array( 0 => "name",
1 => "title",
2 => "motto",
3 => "category",
4 => "unstatus",
5 => "civilRights",
6 => "economy",
7 => "polFreedom",
8 => "region",
9 => "population",
10 => "tax",
11 => "animal",
12 => "currency",
13 => "flag",
14 => "majIndustry",
15 => "govPriority",
16 => "lastlogin",
17 => "lastact",
18 => "admin",
19 => "welfare",
20 => "health",
21 => "edu",
22 => "spirit",
23 => "defence",
24 => "law",
25 => "commerce",
26 => "transport",
27 => "enviro",
28 => "social",
);

//Now we just need to have the script parse out the necessary values.
//For this I decided to use for() as I can use $z on both Arrays.

$numSec = 28;

$nation = array();

for ($z=0;$z<($numSec+1);$z++) {
$open = "<".$section[$z].">";
$close = "</".$section[$z].">";
$start = strpos($text,$open);
$end = strpos($text,$close);
$length = $end - $start;
$val = substr($text,$start,$length);
$val = str_replace($open, '', $val);
if ($section[$z] == 'POPULATION') {
if ($val >= 1000) {
$val = round($val/1000, 3);
$nation['postfix'] = "Billion";
} else {
$nation['postfix'] = "Million";
}
$nation[$section2[$z]] = $val;
} else if ($z >= 18 && $z <= 28) {
// This is the 10 new Budget Categories. While not Necessary I personally remove the % from the Values
$nation[$section2[$z]] = str_replace('%', '', $val);
} else if ($section[$z] == 'REGION') {
$nation[$section2[$z]] = $val;
$nation['regionurl'] = str_replace(' ', '_', $nation[$section2[$z]]); //for the Region URL
} else {
$nation[$section2[$z]] = $val;
}
}

//Check to see if a Message has been set ($msg)
if (isset($msg)) {
echo "<font color=\"red\" size=\"3\">".$msg."</font><br /><br />";
}
?>
<html>
<head>
<title><? echo $nation['title'].' of '.$nation['name']; ?></title>
<style>
.title { font: 12pt arial; color: red; border-bottom: 1px solid red }
.category { font: 11pt arial; color: black }
.value { font: 11pt arial; color: white; background-color: black }
.flag { border: 1px solid black }
</style>
</head>
<body>

<table border="0">
<tr>
<td colspan="2" class="title">Main Information</td>
</tr><tr>
<td class="category" align="right">Nation Name:</td>
<td class="value" align="center"><? echo $nation['title'].' of '.$nation['name']; ?></td>
</tr><tr>
<td class="category" align="right">National Flag:</td>
<td align="center"><span title="<? echo $nation['flag']; ?>"><img src="<? echo $nation['flag']; ?>" width="107" height="71" class="flag" /></span></td>
</tr><tr>
<td class="category" align="right">National Motto:</td>
<td class="value" align="center">"<? echo $nation['motto']; ?>"</td>
</tr><tr>
<td class="category" align="right">UN Membership:</td>
<td class="value" align="center"><? echo $nation['unstatus']; ?></td>
</tr><tr>
<td class="category" align="right">UN Category:</td>
<td class="value" align="center"><? echo $nation['category']; ?></td>
</tr><tr>
<td class="category" align="right">Civil Rights:</td>
<td class="value" align="center"><? echo $nation['civilRights']; ?></td>
</tr><tr>
<td class="category" align="right">Political Freedoms:</td>
<td class="value" align="center"><? echo $nation['polFreedom']; ?></td>
</tr><tr>
<td class="category" align="right">Economy Rating:</td>
<td class="value" align="center"><? echo $nation['economy']; ?></td>
</tr><tr>
<td class="category" align="right">Major Industry</td>
<td class="value" align="center"><? echo $nation['majIndustry']; ?></td>
</tr><tr>
<td class="category" align="right">Region:</td>
<td class="value" align="center"><a href="http://www.nationstates.net/cgi-bin/index.cgi/06747/page=display_region/region=<? echo $nation['regionurl']; ?>" class="value"><? echo $nation['region']; ?></a></td>
</tr><tr>
<td class="category" align="right">National Population:</td>
<td class="value" align="center"><? echo $nation['population'].' '.$nation['postfix']; ?></td>
</tr><tr>
<td class="category" align="right">National Currency:</td>
<td class="value" align="center"><? echo $nation['currency']; ?></td>
</tr><tr>
<td class="category" align="right">National Animal:</td>
<td class="value" align="center"><? echo $nation['animal']; ?></td>
</tr><tr>
<td colspan="2" class="title">Budget Related Information</td>
</tr><tr>
<td class="category" align="right">Income Tax Level:</td>
<td class="value" align="center"><? echo $nation['tax']; ?>%</td>
</tr><tr>
<td class="category" align="right">Government Priority:</td>
<td class="value" align="center"><? echo $nation['govPriority']; ?></td>
</tr><tr>
<td class="category" align="right">Administrative Budget:</td>
<td class="value" align="center"><? echo $nation['admin']; ?>%</td>
</tr><tr>
<td class="category" align="right">Welfare Budget:</td>
<td class="value" align="center"><? echo $nation['welfare']; ?>%</td>
</tr><tr>
<td class="category" align="right">Public Healthcare Budget:</td>
<td class="value" align="center"><? echo $nation['health']; ?>%</td>
</tr><tr>
<td class="category" align="right">Public Education Budget:</td>
<td class="value" align="center"><? echo $nation['edu']; ?>%</td>
</tr><tr>
<td class="category" align="right">Spirituality Budget:</td>
<td class="value" align="center"><? echo $nation['spirit']; ?>%</td>
</tr><tr>
<td class="category" align="right">Defence Department Budget:</td>
<td class="value" align="center"><? echo $nation['defence']; ?>%</td>
</tr><tr>
<td class="category" align="right">Law and Order Budget:</td>
<td class="value" align="center"><? echo $nation['law']; ?>%</td>
</tr><tr>
<td class="category" align="right">Commerce Budget:</td>
<td class="value" align="center"><? echo $nation['commerce']; ?>%</td>
</tr><tr>
<td class="category" align="right">Public Transportation Budget:</td>
<td class="value" align="center"><? echo $nation['transport']; ?>%</td>
</tr><tr>
<td class="category" align="right">Environmental Budget:</td>
<td class="value" align="center"><? echo $nation['enviro']; ?>%</td>
</tr><tr>
<td class="category" align="right">Social Equality Budget:</td>
<td class="value" align="center"><? echo $nation['social']; ?>%</td>
</tr><tr>
<td colspan="2" class="title">Non-RP Related</td>
</tr><tr>
<td class="category" align="right">Last Login</td>
<td class="value" align="center"><? echo gmdate("H:i:s \G\M\T M/d/Y", $nation['lastlogin']).' ('.$nation['lastlogin'].')'; ?></td>
</tr><tr>
<td class="category" align="right">Last Activity</td>
<td class="value" align="center"><? echo $nation['lastact']; ?></td>
</tr>
</table>

</body>
</html>

And for the Record, Javascript is EVIL! :p
Enerica
12-08-2004, 14:00
I will have to kill you now :D

I prefere Javascript, as it can do a vast amount more than people expect, and looks nicer than......shiver...php.
Winnipeg
12-08-2004, 18:09
Yeah but then it has to not only load from your server every time but also has to load from the NationStates Server (Granted that Script I released does the same thing but it wouldn't take much effort to include a MySQL Database for that).

Not to mention what someone else mentioned earlier in this thread: PHP Works for every user, but others might have a broken Javascript on their browser or they might have just turned off their Javascript, or could have an older out of date browser that does odd stuff with the javascript code.

Javascript is not something you want to rely on to get the job done.
Rapid Dr3am
13-08-2004, 15:45
JavaScript has it's occasional use, but it's too resource intensive on the client side.

I got the php version working perfectly now here:
- http://www.rapiddr3am.net/nationstate.php

Much better now. :)

/me goes of thinking about making it run on a cron job and a database.
E-Xtremia
14-08-2004, 21:10
Demo: http://merit.jink.org/winnipeg/ns_xml.php

And for the Record, Javascript is EVIL! :p

fair'nough... but what I want to do, I can only do with java (no one ever answers if it can even be done with PHP)

I have a region of about 100 nations... I want to parse the following data from each of them:

FULLNAME
POPULATION
CATEGORY
FLAG

these are the only 4 I need

I wanted to do it in an external sheet, which is where the problem lies... below, you will find a sample of data.js... the external sheet I have been using to parse my data (it is on one server, the document is on a different one)


var xmlDoc = new ActiveXObject("Microsoft.XMLDOM")

xmlDoc.async = "false";


var KVM = "--Kaiser Von Moss--"
xmlDoc.load("http://www.nationstates.net/cgi-bin/nationdata.cgi/nation="+KVM)
var KVMnm = xmlDoc.getElementsByTagName('FULLNAME').item(0).text
var KVMpp = xmlDoc.getElementsByTagName('POPULATION').item(0).text
var KVMcg = xmlDoc.getElementsByTagName('CATEGORY').item(0).text
var KVMfl = xmlDoc.getElementsByTagName('FLAG').item(0).text

var Aus = "Auskordarg"
xmlDoc.load("http://www.nationstates.net/cgi-bin/nationdata.cgi/nation="+Aus)
var Ausnm = xmlDoc.getElementsByTagName('FULLNAME').item(0).text
var Auspp = xmlDoc.getElementsByTagName('POPULATION').item(0).text
var Auscg = xmlDoc.getElementsByTagName('CATEGORY').item(0).text
var Ausfl = xmlDoc.getElementsByTagName('FLAG').item(0).text

var Art = "Artanitis"


Once I get into the actual page, I just do this:

<SCRIPT SRC="data.js">

</SCRIPT> to load the page in,

then use the following for each nation:


<TR HEIGHT="71PX">
<TD COLSPAN="1">
<!-- -Kaiser Von Moss- --><SCRIPT>document.write(KVMnm)</SCRIPT>
</TD>
<TD BGCOLOR="#FF0000">
*UN*
</TD>
<TD>
<DIV ALIGN="RIGHT"><TT><SCRIPT>document.write(KVMpp)</SCRIPT></TT></DIV>
</TD>
<TD>
<SCRIPT>document.write(KVMcg)</SCRIPT>
</TD>
<TD>
Die Macht bildet Rechte Partei
</TD>
<TD WIDTH="107PX">
<DIV ALIGN="CENTER" VALIGN="CENTER"><SCRIPT>document.write("<IMG SRC='"+KVMfl+"' WIDTH='107PX' HEIGHT='71PX'>")</SCRIPT></DIV>
</TD>
</TR>


and so forth for each nation

The reason I do this, is because I want the UN nations to be denoted by the red cell (I dont know how I would do that with ANYthing but HTML) and the political parties have to do with the region, not the XML feed at all
Cork South Central
08-09-2004, 15:25
that php script ROCKS!
Cork South Central
30-09-2004, 10:57
I have added that to my website http://www.munsternations.com

I have modified it to work integrated within PHPNuke. I will shortly put all the relevant files into a zip file and post it to my downloads section, ofcourse crediting the original author.


(Sorry, forgot to add that registration is required to see it in action. But registration is free so you have nothing to lose. I have added a screenshot to show how it integrates with phpNuke)