XML - Help!

O

old.Yomar

Guest
How do I display XML on our website? GOA says I need to learn the entire lingo to be able to do that, but sure a simple example must be enough to 'get the hang of it'. Can anybody tell me how he/she would display the data hidden in the XML below in simple HTML?

XML location: http://www.camelot-europe.com/herald/servers.xml

<server name="Excalibur" type="English" updated="05-04-2002 16:00:02">
<population>70</population>
<status>Up</status>
<relic name="Scabbard of Excalibur" type="Melee" realm="Albion">
<owner>Albion</owner>
</relic>
<keep name="Caer Boldiam" realm="Albion">
<owner>Albion</owner>
</keep>
</server>

What HTML would I need to turn this into:
Excalibur
English
05-04-2002 16:00:02
70
Up
Scabbard of Excalibur
Melee
Albion
Albion
Caer Boldiam
Albion
Albion

I think I can figure out the rest myself. All I need is an example that shows not only how to process the main parameters, but also the subparameters within (main parameter being for example server, it's subparameter "type" being "English"). Forgive the use of the words parameters/subparameters, I'm sure programmers call it differently.
 
O

old.Rohirrim

Guest
im having the same prob as u m8...Ask around, if i find an answer ill post on here
 
O

old.Yomar

Guest
I've come as far as this using some routines I found on the Internet:

<html>
<body>

<script type="text/vbscript">
set xmlDoc=CreateObject("Microsoft.XMLDOM")
xmlDoc.async="false"
xmlDoc.load("http://www.camelot-europe.com/herald/nb_connected.xml")
document.write("<h1>Traversing the XML nodes</h1>")
for each x in xmlDoc.documentElement.childNodes
document.write("" & x.nodename & "")
document.write(": ")
document.write(x.text)
document.write("

")
next
</script>

</body>
</html>

I actually understand what's happening here. All I wonder about is how to display the server name and the server type now. Any easy adaptation that can do that?
 
M

-Mortal-

Guest
Have a look here http://www.theunforgiven.barrysworld.net/servers.php this is my first try at coding based on the US merlin server (used it because Euro XML wasnt up at the time) basically you have to use php to get the XML to come out in a sensible format.

There is a few bugs in it (such as it only shows 5 relics just now) but it is very early in development and done quickly. Hope to fix it and change details over to Prydwen this weekend.

If you want me to email the file so you can play about with it and alter it to suit your requirements drop me an email, its just a small zip file php page.

mortal@btinternet.com
 
O

old.Yomar

Guest
I know it's prolly best to use style sheets and/or XMS, but I find it a real hassle to work with different formats and files, especially since I'm only planning to put up all this info on one page. Plus I guess that the parameters themselves (not their contents) will be very static.

Anybody who knows VBasic who can help me to get the server name and type using the above VBasic routine?
 
O

old.rlesedai

Guest
Dunno if this will help (its the code that i use on my site). It is VBscript and uses ASP. Its simple, but it does work for me and my guild (which is the main point).
I must admit that i am please with the XML feature of Mythic (and hopefully GoA) and hope that all came companies produce something similar.

Anyhow, here is the code (it uses the sample details from the Mythic server, but you should be able to use them).

oh, as a last point, your web server will need to be able to execute XML (i have to change my providers as my current one does not support the XML object). If in doubt, contact your hosts.



<%

'This XML Component comes with windows 2000.
Set objXMLa = Server.CreateObject("Microsoft.XMLDOM")
'Tells the xml call to wait until all the data is grabbed before returing any
objXMLa.async = False
'sets the xml call to use http instead of a filesystem request
objXMLa.setProperty "ServerHTTPRequest", true

objXMLa.Load("http://www.camelotherald.com/guilds/Pendragon/281.xml")

If objXMLa.parseError.errorCode <> 0 Then
Response.Write objXMLa.parseError.reason&"
"
Response.Write objXMLa.parseError
End If

'sets the particular properties from the xml file.
Set atdds = objXMLa.getElementsByTagName("guild")
Set atbs = objXMLa.getElementsByTagName("character")
Set objdds = objXMLa.getElementsByTagName("race")
Set objdds2 = objXMLa.getElementsByTagName("class")
Set objdds3 = objXMLa.getElementsByTagName("level")
Set objdds4 = objXMLa.getElementsByTagName("guildrank")
Set objdds5 = objXMLa.getElementsByTagName("totalrp")
Set objdds6 = objXMLa.getElementsByTagName("lastweekrp")
Set objdds7 = objXMLa.getElementsByTagName("anon")



For i = 0 to (objdds.length - 1)
name = atbs.item(i).getAttribute("name")
laston = atbs.item(i).getAttribute("laston")

gname = atdds.item(i).getAttribute("name")
gchars = atdds.item(i).getAttribute("activechars")
gmembs = atdds.item(i).getAttribute("activemebers")
grps = atdds.item(i).getAttribute("guildrp")



%>

<tr>

<td><font><%=name%>[/B]</font></td>
<td><font><%=objdds.item(i).text%>[/B]</font></td>
<td><font><%=objdds2.item(i).text%>[/B]</font></td>
<td><font><%=objdds3.item(i).text%>[/B]</font></td>
<td><font><%=objdds4.item(i).text%>[/B]</font><td>
<td><font><%=objdds5.item(i).text%>[/B]</font></td>
<td><font><%=objdds6.item(i).text%>[/B]</font></td>
<td><font><%=objdds7.item(i).text%>[/B]</font></td>


</tr>
<%
Next


%>
 
O

old.Yomar

Guest
Thanks! I just got my routine working (never used this lingo before)... I'm sure it's much worse than yours, but it does the job:

<html>
<body>

<script type="text/vbscript">

set xmlDoc=CreateObject("Microsoft.XMLDOM")
xmlDoc.async="false"
xmlDoc.load("http://www.camelot-europe.com/herald/nb_connected.xml")
for each x in xmlDoc.documentElement.childNodes
document.write("" & x.getAttribute("name"))
document.write(" (")
document.write(x.getAttribute("type"))
document.write(")" & "
")
document.write("
")
document.write("Population: " & x.childnodes(0).text & "
")
document.write("Status: " & x.childnodes(1).text & "
")
document.write("

")
next

</script>

</body>
</html>
 
O

old.Yomar

Guest
After much trial and error, I finally completed the script. Not bad for a guy who never heard of VBScript until today :)

By changing the FIRST number in EVERY instance starting with xmlDoc.documentElement.childNodes(0), you can get information on your own server. Refer to the XML file to see where your server is listed (the first server listed is Excalibur, with 0). Next server is 1, next 2, etcetera.

The script uses two XML files: one for extracting server data, the other for extracting data on relics & keeps. It extracts server data from another XML file, since this one is actualized more often (it doesn't contain any data on relics & keeps though, so I had to use the other XML file for that).

Here it is... you can copy this straight to HTML. Prolly only works in Internet Explorer.

<script type="text/vbscript">

set xmlDoc=CreateObject("Microsoft.XMLDOM")
xmlDoc.async="false"
xmlDoc.load("http://www.camelot-europe.com/herald/nb_connected.xml")

document.write("<h2>Server status</h2>")

document.write("" & xmlDoc.documentElement.childNodes(0).getAttribute("name"))
document.write(" (")
document.write(xmlDoc.documentElement.childNodes(0).getAttribute("type"))
document.write(")" & "
")
document.write("
")
document.write("Population: " & xmlDoc.documentElement.childNodes(0).childnodes(0).text & "
")
document.write("Status: " & xmlDoc.documentElement.childNodes(0).childnodes(1).text & "
")

</script>











<script type="text/vbscript">
set xmlDoc=CreateObject("Microsoft.XMLDOM")
xmlDoc.async="false"
xmlDoc.load("http://www.camelot-europe.com/herald/servers.xml")

document.write("<h2>Relics</h2>")

y=1

while (y<7)
document.write("" & xmlDoc.documentElement.childNodes(0).childnodes(y+1).getAttribute("name") & "")
document.write(" (" & xmlDoc.documentElement.childNodes(0).childnodes(y+1).getAttribute("type") & ", " & xmlDoc.documentElement.childNodes(0).childnodes(y+1).getAttribute("realm") & "):")
document.write(" owned by " & xmlDoc.documentElement.childNodes(0).childnodes(y+1).text & "
")
y=y+1
wend

document.write("<h2>Keeps</h2>")

y=1
while (y<21)
document.write("" & xmlDoc.documentElement.childNodes(0).childnodes(y+7).getAttribute("name") & "")
document.write(" (" & xmlDoc.documentElement.childNodes(0).childnodes(y+7).getAttribute("realm") & "):")
document.write(" owned by " & xmlDoc.documentElement.childNodes(0).childnodes(y+7).text & "
")
y=y+1
wend

</script>
 
O

Olgark

Guest
Wow thanks guys been trying for most of the day in getting this to work. Never heard of anything you have spoke of and I have been strugling with the sites that GOA :rolleyes: told us would help.


Is it me or has someone :puke: all over this site. ITS GREEN.
 
O

old.Ozird Rinfut

Guest
This is the server population script:

Paste in a txt file, rename the extension to PHP

Code:
<?php
// DAoC Server Status v1.0, msw, 12/2001
// Simple script to print out a very basic server status page using the xml
// from Camelot Herald. Check out [url]http://www.camelotherald.com/xml.php[/url]
//
// I use this code in a 'block' on my php-Nuke website ([url]http://home.greycouncil.org/[/url])
// and it works fine. Should work as a simple webpage for others that have
// php/xml support.
//
// Hope this helps ya out, I won't support ya, don't ask me questions!
// I myself spent about a hour or so reading the tutorials the Mythic guys
// listed on their website. If you can't figure this out or have problems visit there.
// 
// Tutorial for XML/PHP [url]http://www.webmasterbase.com/article/560[/url]
//
// To see the plain version hit [url]http://home.greycouncil.org/test-xml/daoc-servers.php[/url]
//
// To see the php-Nuke BLOCK version hit [url]http://home.greycouncil.org/[/url]
//
// This ain't by any means the best way to do this I am sure but it works.
//
// Run this like you would any other php script on your website.... that is
// all...See ya in game (well, when they fix/add a few things!)

$insideitem = false;
$tag = "";
$da_server = "";
$da_population = "";
$da_type ="";
$da_status = "";
$da_totalpop=0;

function startElement($parser, $tagName, $attrs) {    
global $insideitem,$tag, $da_server, $da_type;
	if ($insideitem) {
		$tag = $tagName;
	} elseif ($tagName == "SERVER") 
	{

	$insideitem = true;    
	while (list ($key, $val) = each ($attrs)) {
		switch($key) {
		case "NAME": $da_server=$val;break;
		case "TYPE": $da_type=$val;break;
		} // end case
	} // end while
	}

}


function characterData($parser, $data) {    
global $insideitem, $tag, $da_server, $da_population, $da_type, $da_status,$da_totalpop;
	if ($insideitem) {

	   switch ($tag) {            
		case "POPULATION":	$da_population .= $data; $da_totalpop += $data; break;            
		case "STATUS":		$da_status .= $data; break;
		}    


	}

}


function endElement($parser, $tagName) {    
global $insideitem, $tag, $da_server, $da_population, $da_type, $da_status;
	if ($tagName == "SERVER") {
		print "<TR><TD>[b]$da_server[/b]";
		if ($da_type) { print "([i]$da_type[/i])"; }
		print "</TD>";
		print "<TD>$da_status</TD>";
		print "<TD>$da_population</TD></TR>\n";

		$da_server = "";        
		$da_population = "";        
		$da_status = "";
		$da_type = "";
		$insideitem = false;    
	}
}



// gotta have this for the php-NUKE block stuff to work
global $da_totalpop;

// Create an XML parser
$xml_parser = xml_parser_create();

// Set the functions to handle opening and closing tags
xml_set_element_handler($xml_parser, "startElement", "endElement");

// Set the function to handle blocks of character data
xml_set_character_data_handler($xml_parser, "characterData");


// print "<hr>\n";
print "<TABLE BORDER=0 WIDTH=0%>\n<TR>\n";
print  "<TD>[B]Server[/B]</TD><TD>[B]Status[/B]</TD><TD>[B]Users[/B]</TD>\n";
print "</TR>\n";

// Open the XML file for reading
$fp = fopen("http://www.camelot-europe.com/herald/servers.xml","r")  or die("Error reading RSS data.");

// Read the XML file 4KB at a time
while ($data = fread($fp, 4096))    
// Parse each 4KB chunk with the XML parser created above
xml_parse($xml_parser, $data, feof($fp)) 
		or die(sprintf("XML error: %s at line %d",
			xml_error_string(xml_get_error_code($xml_parser)),
				xml_get_current_line_number($xml_parser)));
// Close the XML filef
fclose($fp);

print "<TR><TD>Total Users</TD><TD></TD><TD>$da_totalpop</TD></TR>\n";
print "</TABLE>\n";


// Free up memory used by the XML parser
xml_parser_free($xml_parser);



// end of file

?>

Preview here: http://nidstang.mine.nu/daoc-servers.php
 
S

Seyrcim

Guest
This was my first try at using XML so it's not a beauti ;) Since it's from our guild page it has some stuff left out, so if you just try this out it will probably look strange without some changes =)

Code:
<?
$file = "http://www.camelot-europe.com/herald/nb_connected.xml";
$element = "";
$gather = false;
$total = 0;

function startElement1($parser, $name, $attrs) {
    global $element, $gather;
    if ($attrs["TYPE"] == "English" || $gather)
    {
        $gather = true;
        switch($name)
        {
            case "SERVER" :     print "<td>" . $attrs["NAME"] .  "</td>"; $element = $name; break;
            case "POPULATION" : $element = $name; break;
            case "STATUS" :     $element = $name; break;
        }
    }
}

function endElement1($parser, $name)
{
    global $gather;
    if ($name == "SERVER" && $gather)
    {
        print "</tr>\n<tr>";
        $gather = false;
    }
}

function characterData1($parser, $data)
{
    global  $element, $total, $gather;

    if (trim($data) != "" && $gather)
    {
        switch($element)
        {
            case "POPULATION" : print "<td>$data</td>"; $total += $data; break;
            case "STATUS" :     print "<td>$data</td>\n"; break;
        }
    }
}

$xml_parser = xml_parser_create();
xml_set_element_handler($xml_parser, "startElement1", "endElement1");
xml_set_character_data_handler($xml_parser, "characterData1");


if (!($fp = fopen($file, "r")))
{
    die("could not open XML input");
}

while ($data = fread($fp, 4096))
{
    if (!xml_parse($xml_parser, $data, feof($fp)))
    {
        die(sprintf("XML error: %s at line %d",
                    xml_error_string(xml_get_error_code($xml_parser)),
                    xml_get_current_line_number($xml_parser)));
    }
}
print "<td>[b]Total:[/b]</td><td colspan=2 align=left>[b]$total[/b]</td>";
xml_parser_free($xml_parser);
?>

Also, it only show the status for the english servers (as you can see) if you want to see what it looks like, as well as the realm-stats have a look at http://delfinen.telge.kth.se/NoM/main.php?page=realm (only for excalibur)

[EDIT] Heh, using the php-tag was a really bad idea ;)
 
Z

zilch

Guest
My troubles

http://www.btinternet.com/~pulsar85/ourside/servers-daoc.htm This is my try

This is the code...i cant get it to work when i publish it.....but it works fine when saved on my computer

<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<script language="JavaScript">
<!--
function MM_reloadPage(init) { //reloads the window if Nav4 resized
if (init==true) with (navigator) {if ((appName=="Netscape")&&(parseInt(appVersion)==4)) {
document.MM_pgW=innerWidth; document.MM_pgH=innerHeight; onresize=MM_reloadPage; }}
else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH) location.reload();
}
MM_reloadPage(true);
// -->
</script>

<link rel="stylesheet" href="style.css" type="text/css">
<body bgcolor="#000000" text="#FFFFFF">
<div id="Layer1" style="position:absolute; left:4px; top:3px; width:200px; height:292px; z-index:1">
server.jpg
</div>
<div id="Layer2" style="position:absolute; left:35px; top:170px; width:165px; height:70px; z-index:2">
<p class="OurSide2">
<script type="text/vbscript" class="OurSide2">

set xmlDoc=CreateObject("Microsoft.XMLDOM")
xmlDoc.async="false"
xmlDoc.load("http://www.camelot-europe.com/herald/nb_connected.xml")

document.write("" & xmlDoc.documentElement.childNodes(5).getAttribute("name"))
document.write(" (")
document.write(xmlDoc.documentElement.childNodes(5).getAttribute("type"))
document.write(")" & "
")
document.write("
")
document.write("Population: " & xmlDoc.documentElement.childNodes(5).childnodes(0).text & "
")
document.write("Status: " & xmlDoc.documentElement.childNodes(5).childnodes(1).text & "
")

</script>
</p>
</div>
<div id="Layer2" style="position:absolute; left:35px; top:90px; width:165px; height:70px; z-index:2">
<p class="OurSide2">
<script type="text/vbscript">

set xmlDoc=CreateObject("Microsoft.XMLDOM")
xmlDoc.async="false"
xmlDoc.load("http://www.camelot-europe.com/herald/nb_connected.xml")

document.write("" & xmlDoc.documentElement.childNodes(0).getAttribute("name"))
document.write(" (")
document.write(xmlDoc.documentElement.childNodes(0).getAttribute("type"))
document.write(")" & "
")
document.write("
")
document.write("Population: " & xmlDoc.documentElement.childNodes(0).childnodes(0).text & "
")
document.write("Status: " & xmlDoc.documentElement.childNodes(0).childnodes(1).text & "
")

</script>
</p>
</div>
<div id="Layer3" style="position:absolute; left:7px; top:95px; width:23px; height:16px; z-index:3">
drsr_en.gif
</div>
<div id="Layer3" style="position:absolute; left:7px; top:175px; width:23px; height:16px; z-index:3">
drsr_en.gif
</div>
<div id="Layer4" style="position:absolute; left:15px; top:28px; width:182px; height:40px; z-index:4">
<p class="OurSide2" align="center"><font size="6">Servers</font></p>
</div>
</body>
</html>


Do i need something on my server (i dont have a clue)
 
O

old.rlesedai

Guest
You need the XML object on the server (contact your ISP to ask if they do).
My previous host did not, therefore i had to change providers.

It will work on your PC is you have Windows 2000/XP installed as it came with the os. Uncertain if it was included in any other.

(Well, there you have it, my complete knowledge so far on this subject - and bound to be slighty off target :) )
 
Z

zilch

Guest
Server wont let me use xml

does that mean i can still use it on my own computer (cause i can)? while testing it it will collect the info from the xml file if my html file is on my computer.
 
O

old.rlesedai

Guest
Yup, you can use the script on your PC if you have the XML component on your PC. However, when you place all these on your webserver (with your ISP), you are now using their systems. Therefore, if they have not setup the server to run XML, then your script will NOT work.

There are a load of free service hosts out there that provide XML support. I suggest a quick search on the net for a list.
 
Z

zilch

Guest
Thx

And that means i can stil use my isp's webspace but place the link to the webspace which enables me to use XML ...... Cheers m8 :)
 
O

old.Zeikerd

Guest
I also build a php version.
This is how it works:
It parses all the xml at first and creates objects in php from it.
Then it lets the objects create the html output.
It's a bit of a jumble and not extremely fast, but it can output everything you want if you edit it a small bit.
Sample output for Exaclibur server
Source code

PS. OO in php is crappy ;)
 
O

old.VooVoo

Guest
I've not attempted to ever try doing a server stats yet, and all this looks rather confusing to me =( (granted over time it'll all prolly look simple)

How do i got about writing this?

I looked at hte example scripts on the Main web-site but i still cannot work out where its getting the source to display the results.

I'm pretty much totally new to php and xml and i'm not that much experinenced in html.

any help would be appricated, heh step-by-step is always good, if any of you have ICQ or AIM would be a big help, i'm on all day (sunday 9th june) if you have any free time.

Thanks
 

Users who are viewing this thread

Top Bottom