A guide how to implement XML on your page?

U

Uncle Sick(tm)

Guest
Anyone knows a good link or could write a short, comprehendible guide?

Uncle Sick would be grateful;)
 
A

Alrindel

Guest
There's a section on Mythic's site that covers the basics quite well: http://www.camelotherald.com/xml.php

To summarize (perhaps unhelpfully) how you "implement XML" on your web site depends on what information you want to display and how, and on what technology is available to you (does your web site let you use Shell? Perl? PHP? ASP? Miva? Some other scripting language?) If you have access to a server-side scripting language, you will probably write a script to download the appropriate XML files, interpret them, and generate HTML dynamically based on their contents - there are many code samples around for the different languages available to use as a starting point, including the PHP that I wrote for my guild's web site here:

http://silent-death.net/xml/guild.php
http://silent-death.net/xml/guild.php.txt

http://silent-death.net/xml/server.php
http://silent-death.net/xml/server.php.txt

If you don't have access to a server-side scripting language then it is still possible to do some client-side XML interpretation (in Internet Explorer for Windows, at any rate) using VBScript. This has a few nuisances, not least being that IE will refuse to use XML from a different web site than the page that contains the script unless you go into the security preferences and explicitly authorize it. There is an example of this here: http://www.akebono.cistron.nl/sortname.html

Hope this helps you get started.
 
G

Gef

Guest
Use PHP and an XSL template, its the most basic of basic that basic can get..

PHP File
<html>
<link rel="stylesheet" href="../guild/Styles.css" type="text/css">
<body bgcolor="#40008C">
<?

//Open XML File into the DOM
$xmlDom = domxml_open_file("http://www.camelot-europe.com/herald/nb_connected.xml");

//Load XSL Template
$xslDom = domxml_xslt_stylesheet_file("nb_connected.xsl");

//Process the two
$result = $xslDom->process($xmlDom);

//Print the results
print($result->dump_mem(true));

?>
</body>
</html>

XSL Template
<?xml version="1.0" ?>

<xsl:stylesheet version="1.0"
xmlns="http://www.w3.org/1999/xhtml"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
>

<xsl:eek:utput method="html" version="4.0" encoding="iso-8859-1"/>

<xsl:template match="/">

<xsl:for-each select="/server_status/server">
<table>
<tr>
<td style="color:#AAAAAA;">Name:</td>
<td><xsl:value-of select="@name"/> (<xsl:value-of select="@type"/>)</td>
</tr>
<tr>
<td style="color:#AAAAAA;">Population:</td>
<td><xsl:value-of select="population"/></td>
</tr>
<tr>
<td style="color:#AAAAAA;">Status:</td>
<td>
<xsl:choose>
<xsl:when test="status = 'Up'"><font color="green">Up and ready for action!</font></xsl:when>
<xsl:eek:therwise><font color="red">He's dead jim.</font></xsl:eek:therwise>
</xsl:choose>
</td>
</tr>
</table>
</xsl:for-each>

</xsl:template>

</xsl:stylesheet>

I could comment the XSL but its pretty self explanatory, <xsl:for-each select="/server_status/server"> is a loop that runs through each server and prints the results. Attributes in XML nodes are always printed using a preceeding '@' symbol. i.e <xsl:value-of select="@name"/> would print the server name.

Finished things can be seen:

http://www.g3f.co.uk/status/
http://www.g3f.co.uk/trade/
http://www.g3f.co.uk/guild/

I made these for a friend to embed in his own guild page, using iFrames or something cause his webspace doesnt support PHP .. dohh!
 
U

Uncle Sick(tm)

Guest
Thanks alot the both of you - also received a script from a friendly Templar (crossrealm-teaming!!)..... so I'll get working on it now.
 
U

Uncle Sick(tm)

Guest
That's what I get when I upload Gef's php template... I am about to repeatedly bang my head against the wall....
Pasted it into Dreamweaver and saved it as a .php file.

*sighs*

Enlighten me, friends.

Alright - saved Gef's XSL example as an .xml file and uploaded it:

*bangs head against desk*
I am not having trouble uploading xml pages nor php page but I can't seem to implement the xml on a php page.

Lycos supposedly supports php but when I upload the files, they come out as they should in the preview but not in my browser.
And I can't find the hook....
 
G

Gef

Guest
You look like you got it almost right, the XSL template file should be called nb_connected.xsl and should be in the same folder as your main PHP file. Its defined on the line that says:

$xslDom = domxml_xslt_stylesheet_file("nb_connected.xsl");

XML and XSL are two totally seperate things ..

Your server does support PHP otherwise you wouldnt get the PHP error message :)
 
G

Gef

Guest
One thing I just realised, the version of PHP on your webspace has to have XML support compiled into it. I know my server runs 4.2.2 and I added the XML stuff as a compile time option. Dont know how up to date your webspace is but you may have to check.

Just make a file called test.php or something and put:

<html>
<body>
<?

phpinfo();

?>
</body>
</html>

Then run it, this is what I get:

http://www.g3f.co.uk/php.php

It has to have:

'--with-dom-xslt' '--with-dom-exslt'

in the box that says 'Configure Command' if it doesnt then your a bit buggered and I would find a new ISP ;)
 
C

Cadire

Guest
Heh, thanks for the reply anyway!

While I have your attention though :cool:

I'm playing around with using the said XML file, but seem to have a problem (I'm using javascript as my webby has no php etc).

I set the xml id like so:
Code:
<xml id="data" src="http://www.camelot-europe.com/herald/servers/Prydwen/guilds/150.xml"></xml>

and then parse the elements like so (this is name element):
Code:
<span style="background: white; 
            width:150; border-width:1" dataSrc="#data" 
            dataFld="name"></span>

This works ok-ish, except that if you look at the xml file, there is a space between guild name and character name, and I can't seem to select the one I want. I just get the first instance of name.

Is there any way to get rid of the whitespace... bearing in mind that I'm a real beginner at this?

Cheers :)
 
C

Cadire

Guest
OK, I think I have this now.

I just to a .attributes to get the name, then getAttribute('name').
 
G

Gef

Guest
Cadire if your going to take the data binding route you should know its only supported in IE5.5+ and has a lot of security issues involved with doing things client side. Its also pretty limited.

Sickofit, it has basic XML enabled, called 'expat' but its pretty naff XML, just a parser, thats all. It doesnt support XSL so you wont be able to take the easy route. Not the same as XMLDOM, ISP's these days, dont know what their doing I tells ya.

You can parse it all by hand using pure script, with Expat you can hook functions to certain tags, process, then when it hits a handled tag it calls the function. Its pretty complex and my PHP isnt that good but i'm getting better ;)

There are a lot of PHP scripts out there that other people have produced, but they are overcomplicated and will be difficult to customise. I saw one the other day, purpledragons or something, huge ammount of code to do something relatively simple. But if you cant get XSL working on your server its an option.
 
I

inqy

Guest
Thanks to the stuff on here (actually mainly to Alrindel's guild.php file which I've completely bastardized and used to work out wtf is happening) I've managed a little guild page, which I'll be adding to.

What do you think...there are a couple of bugs. (eg if you sort by one thing, it will forget if it was looking at inactive members and show active, ahh well) :)

http://www.guildxpd.co.uk/guild.php
 
C

Cadire

Guest
Cadire if your going to take the data binding route you should know its only supported in IE5.5+ and has a lot of security issues involved with doing things client side. Its also pretty limited.

I've bought webhosting with a provider that supplies php/mysql and all those goodies. At $6.95 a month it's cheap enough to just play around with this stuff server side.
 
G

Gef

Guest
Go for it Cadiere but like I say its pretty icky to use and very clunky.

Blain, that script has nothing to do with XML, whoever wrote that doesnt actually understand what XML is. He has written his own parser for starters, I read that before and couldnt understand why. He literally loads the XML file in as if it were a text file and then searches it and pulls out keywords to get the data.

50% of that code could be done in one or two lines. If you want to learn how XML works dont follow that as a guideline.
 
A

Alrindel

Guest
Originally posted by Gef
He has written his own parser for starters, I read that before and couldnt understand why.
So it will run without modification on the most basic implementation of PHP, even an obsolete one, without needing any special mods, libraries or a database engine.
50% of that code could be done in one or two lines. If you want to learn how XML works dont follow that as a guideline.
I have not posted any more on this thread because you have pretty much taken it over with your posts which are so aggressively evangelical about using an XSL stylesheet that you seem to believe it's the only way to use XML data and any other solution is stupid. I learned a long time ago that there's no arguing with people who think that way, but I will share this opinion with you: a good programmer will write code to do what you need that runs on the system you have available, while a poor programmer will suggest the only technique he knows, and if it won't work the first time he'll say, "your a bit buggered and I would find a new ISP".

As always, if anyone needs help using GOA's XML documents on their web pages, feel free to send me a private message.

Toodle-pip!
 
G

Gef

Guest
Originally posted by Alrindel

So it will run without modification on the most basic implementation of PHP, even an obsolete one, without needing any special mods, libraries or a database engine.

Hardly special mods, XML support has been available in PHP for several versions now. If ISP's dont keep their versions up to date thats pretty poor, and yeah I would choose a better ISP.

Originally posted by Alrindel

I have not posted any more on this thread because you have pretty much taken it over with your posts which are so aggressively evangelical about using an XSL stylesheet that you seem to believe it's the only way to use XML data and any other solution is stupid. I learned a long time ago that there's no arguing with people who think that way, but I will share this opinion with you: a good programmer will write code to do what you need that runs on the system you have available, while a poor programmer will suggest the only technique he knows, and if it won't work the first time he'll say, "your a bit buggered and I would find a new ISP".

Well each to their own, no need to flame. I know its not the only way of doing it, but writing a clunky parser? I just hate to see XML used like that. A good programmer would see the value of XML and learn to use it properly rather than bodging something together.
 
G

glenfiddich

Guest
**Message mainly in reply to Gef, but it answers most of the point raised in this thread**

50% of that code could be done in one or two lines. If you want to learn how XML works dont follow that as a guideline.

Erm, XML is just another text file format and there are many ways to sort it and organize its contents. I feel you're a bit too biased.
Sure, XSL works wonders, I develop in XSL sheets everyday at work.
But i decided to make my own parser, so there. And my approach is about as valid as any other out there.

You're unfair to say that my code shouldnt serve as a guideline as it indeed focuses on the notion of context.


Originally posted by Gef
I saw one the other day, purpledragons or something, huge ammount of code to do something relatively simple. But if you cant get XSL working on your server its an option.

Like you said, not everyone has XSL support built into their webserver; think that most guild websites (more like 90% actually) do not have access to their server config.

My scripts have to the benefit of being there for people to use it.
Fair enough they may not be optimized for performance but hey, they do just fine for the job they're assigned.

A good programmer would see the value of XML and learn to use it properly rather than bodging something together.
Define "good programmer". We all think differently, sorry if i dont match your criteria. And for crying out loud, this is a script for sorting a list of characters in a video game, so this sort of criticism is a bit over the top of you ask me.

For those interested, you may find my scripts at http://camelot.purpledragons.net/sourceforge/

Cheers,
 
U

Uncle Sick(tm)

Guest
*confused*
So it would be possible to get the whole xml thing working with my current provider anyway? Without xsl?
 
G

glenfiddich

Guest
yes

my method is merely a text file parser, so you dont need full XML support.

contact me if you need help
 
C

candour

Guest
Not too sure how old this thread is, but anyway..

Been helping a friend of mine with his XML parsing recently, and come across a rather irritating problem. The code works perfectly on parsing and does a sterling job, however the PHP XML parser borks (No offence Bork in Huginfel) on non-standard characters.

This wasn't a problem in the past cos there weren't any, but over the last month or so people have started creating characters with some REALLY IRRITATING names :) For instance, there are people with the following:

Less than symbols
Greater than symbols
ASCII 1, 2, 3, 7, 11, 12, 14, 20

Now... I can live with the foreign character sets. I can live with some of the odd symbols I see around. But wtf is it with greater than/less than symbols??? It makes XML barf all over the place for obvious reasons. Even using odd ASCII chars isn't too bad, I can str_replace them. But I've had to write code to str_replace specific character names now. I've not seen any guild names like it yet, but lots of char names.

But for anyone else with similar problems I'd like to name and shame:

<Imortal> Avalon Midgard
> S@INT < Avalon Albion

And call them bastards.

Anyone have a solution/workaround to this? I'm using PHP. I thought of running through the file char by char and verifying the ASCII value, but that doesn't work on gt/lt chars. The only thing I can think of is writing my own XML parser but that seems like a lot of effort for not much reward. Ideally GOA would just delete all guilds/chars with stupid names. Better still, delete their accounts, that'll teach em.
 
R

razorboy

Guest
Originally posted by candour
Anyone have a solution/workaround to this? I'm using PHP.

$string = htmlspecialchars($string);
 
G

glenfiddich

Guest
Anyone have a solution/workaround to this? I'm using PHP. I thought of running through the file char by char and verifying the ASCII value, but that doesn't work on gt/lt chars. The only thing I can think of is writing my own XML parser but that seems like a lot of effort for not much reward. Ideally GOA would just delete all guilds/chars with stupid names. Better still, delete their accounts, that'll teach em. [/B]

Remember the XML files for Europe have an UTF-8 encoding. If you are using PHP, look up utf8_decode()
 

Users who are viewing this thread

Top Bottom