Jump to content

XML - Convert my code from CF to PHP (small code)


MoFish

Recommended Posts

hello. I have been using CF lately to develop my web-page; however, I have recently bought new hosting which no longer supports CF and uses PHP instead. i'm looking to convert the following code into PHP. could anyone assist me in doing so, it would be much appreciated. - the below code works perfect in CF, so i'm looking for the equivalent in php  ;D

thanks alot, mofish.

[code]
<cfset MyXmlFile = Expandpath("MyXML.xml")>
<cffile action="READ" variable="xmlInput"  file="#MyXmlFile#">
<cfset MyXmlFile = Expandpath("Main.xsl")>
<cffile action="READ" variable="xslInput" file="#MyXmlFile#">
<cfset xmlOutput = XMLTransform(xmlInput, xslInput)>
<cfcontent type="text/html" reset="yes">
[/code]
I haven't seen CF code before but it looks like it's taking and XML file and applying XSL stylesheet to it.

Try

[code]
<?php
   
    $xml = simplexml_load_file('MyXML.xml');
    $xsl = simpleXML_load_file('Main.xsl');
    $proc = new XsltProcessor();
    $proc->importStylesheet($xsl);
    $newxml = $proc->transformToDoc($xml);
    print $newxml->saveXML();
?>
[/code]
[code]Warning: I/O warning : failed to load external entity "mainpage.xml" in /home/mo/public_html/mo/are2007/index.php on line 6

Warning: I/O warning : failed to load external entity "are2007XML.xsl" in /home/mo/public_html/mo/are2007/index.php on line 7

Fatal error: Class 'XsltProcessor' not found in /home/mo/public_html/mo/are2007/index.php on line 8[/code]

oh dear, that didn't appear to go too great :D
its now enabled, got my hosting to sort that out this morning. still a few errors however, but they should be errors in which I can be fixed... hopefully  8)

[code]
Warning: I/O warning : failed to load external entity "mainpage.xml" in /home/mo/public_html/mo/are2007/index.php on line 6

Warning: I/O warning : failed to load external entity "are2007XML.xsl" in /home/mo/public_html/mo/are2007/index.php on line 7

Warning: XSLTProcessor::importStylesheet() expects parameter 1 to be object, boolean given in /home/mo/public_html/mo/are2007/index.php on line 9

Warning: XSLTProcessor::transformToDoc() expects parameter 1 to be object, boolean given in /home/mo/public_html/mo/are2007/index.php on line 10

Fatal error: Call to a member function saveXML() on a non-object in /home/mo/public_html/mo/are2007/index.php on line 11
[/code]

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.