Click to See Complete Forum and Search --> : XML to PHP


Solaar
03-13-2006, 01:11 PM
Hi All

I have simple XML code which I have used XSLT to output, both files are pasted below and the result can be seen at http://itsuite.it.brighton.ac.uk/pjgh1/birds.xml.
This was for experimental purposes, I now want to display the XML data on a PHP page but am incertain as to how, I have trawled the web and can't get my head round some of the solutions found as i loathe trying to unravel someone elses complicated, poorly explained code and tend to start daydreaming after about 3 seconds. Can anyone suggest a straightforward solution?

Many Thanks

Solaar

BIRDS.XML
<?xml version="1.0" encoding="ISO-8859-1"?>
<!-- Edited with XML Spy v2006 (http://www.altova.com) -->
<?xml-stylesheet type="text/xsl" href="birds.xsl" ?>
<British_Birds>
<species>
<name>Golden oriole</name>
<latin>Oriolus oriolus</latin>
<status>Summer</status>
<breeding>9-42</breeding>
<passage>85</passage>
<Image ID="123" URI="golden_oriole.jpg"/>
<url address="www.rspb.org.uk/birds/guide/g/goldenoriole/index.asp" />
</species>
<species>
<name>Sparrowhawk</name>
<latin>Accipiter nisus</latin>
<status>Resident</status>
<breeding>34,500</breeding>
<passage>0</passage>
<Image ID="123" URI="sparrowhawk.jpg"/>
<url address="www.rspb.org.uk/birds/guide/s/sparrowhawk/index.asp" />
</species>
<species>
<name>Siskin</name>
<latin>Carduelis spinus</latin>
<status>Resident/Winter</status>
<breeding>310,000</breeding>
<passage>0</passage>
<Image ID="123" URI="siskin.jpg"/>
<url address="www.rspb.org.uk/birds/guide/s/siskin/index.asp" />
</species>
<species>
<name>Hoopoe</name>
<latin>Upupa epops</latin>
<status>Passage</status>
<breeding>Occasional</breeding>
<passage>100</passage>
<Image ID="123" URI="hoopoe.jpg"/>
<url address="www.rspb.org.uk/birds/guide/h/hoopoe/index.asp" />
</species>
</British_Birds>
BIRDS.XSL
<?xml version="1.0" encoding="ISO-8859-1" ?>
<!-- Edited with XML Spy v2006 (http://www.altova.com) -->

<html xsl:version="1.0" xmlns FPRIVATE "TYPE=PICT;ALT=" sl="http://www.w3.org/1999/XSL/Transform" xmlns="http://www.w3.org/1999/xhtml">

<body style="font-family:Arial,helvetica,sans-serif;font-size:12pt; background-color:#EEEEEE">

<h1>British Birds</h1>

<table border="1" width="75%" bordercolor="#111111">
<tr><th></th><th>Species</th><th>Latin</th><th>Status</th>
<th>Breeding</th><th>Passage</th><th>more info</th></tr>
<xsl:for-each select="British_Birds/species">
<tr>
<td width="5%">
<img src="{Image/@URI}" height = "65" width = "50"/>
</td>
<td width="25%">
<span style="font-style:enbolden">
<xsl:value-of select="name" />
</span>
</td>
<td width="10%">

<span style="font-style:italic">

<xsl:value-of select="latin" />

</span>
</td>
<td width="25%">
<xsl:value-of select="status" />
</td>

<td width="10%">
<xsl:value-of select="breeding " />
breeding pairs
</td>
<td width="10%">
<xsl:value-of select="passage" />
birds
</td>
<td width="10%">
<a href="{url/@address}">more...</a>

</td>
</tr>

</xsl:for-each>
</table>
</body>
</html>

NogDog
03-13-2006, 04:49 PM
What is it that you want your PHP script to do (that isn't already being done via XSLT)?

Solaar
03-13-2006, 04:57 PM
I just want to use PHP to present the data. Eventually I will be wanting to load the XML into a MySql and then use PHP/SQL to query the database and display search results etc.

NogDog
03-13-2006, 05:03 PM
If you're using PHP5, then take a look at simplexml_load_file() (http://www.php.net/simplexml_load_file). If using PHP4, it's a bit more complex.

NogDog
03-13-2006, 05:06 PM
Or...just do this, and let your xslt do the work:

<?php
header("Content-type: text/xml");
readfile("birds.xml");
?>

Solaar
03-14-2006, 07:23 AM
Thanks, will give those a bash.

Solaar
03-14-2006, 07:32 AM
Thanks NogDog that worked, don't suppose you know how to enter the same XML data into MySql without using something like Navicat?