Forum Moderators: coopster
Could anyone tell me whether it's possible to call an xml file as an include?
i.e. include("myfile.xml");
The xml file itself contains the xsl declaration. I can't add all elements to the xsl stylesheet as the page I wish to add the xml file to has a number of db driven elements around it.
Obviously this can be done by parsing the xml file, but I'd rather not do that if possible as the contents updated frequently and old data doesn't require archiving.
Thanks
If you want to send it as application XML, you will need to send the proper header() [php.net] call.
Parse error: syntax error, unexpected T_STRING in c:\filepath\soccerscores_test.xml on line 1
My XML file looks like:
<?xml version="1.0" encoding="ISO-8859-1"?>
<!DOCTYPE soccer SYSTEM "soccer4.dtd">
<?xml-stylesheet type="text/xsl" href="soccerscores.xsl"?>
<soccer>
<cp id="15" nm="ENGLAND: Premier League" dt="2005-12-10">
<gm id="78077" tm="13:45" c1="Liverpool" c2="Middlesbrough" cid1="242" cid2="234">
<sr ss="FT" r1="2" r2="0" minute="FT"/>
<ev pl="Fernando Morientes" tp="goal" mt="71" cb="1"/>
<ev pl="Fernando Morientes" tp="goal" mt="77" cb="1"/>
<ev pl="Chris Riggott" tp="rc" mt="84" cb="2"/>
<ev pl="Mohamed Sissoko" tp="yc" mt="66" cb="1"/>
<ev pl="Matthew Bates" tp="yc" mt="66" cb="2"/>
<ev pl="Chris Riggott" tp="yc" mt="79" cb="2"/>
</gm>
</cp>
</soccer>
Regards
$parser = xslt_create();
$html = xslt_process$parser, "soccerscores_test.xml", "soccerscores.xsl");
xslt_free($parser);
echo $html;
The code above works on a test server I have but not on the server which is going to host the script, where I receive the following error message:
Fatal error: Call to undefined function xslt_create()
I imagine that has something to do with my WAMP installation, dlls not being in the system32 folder and extensions being commented out.
So you would have to read the file in to a variable:
$xml = file_get_contents('xml_file.xml');
echo $xml;
That should work as it won't try to evaluate as XML.