javascript - XML Outputting - PHP vs JS vs Anything Else? -
i working on developing travel website uses xml api's data.
however relatively new xml , outputting it. have been experimenting using php output test xml file, furthest iv got output few records.
as questions states need know technology best project. below iv included points take consideration.
- the website going large sized, heavy traffic site (expedia/lastminute size)
- my skillset php (intermediate/high skilled) & javascript (intermediate/high skilled)
below example of xml api outputting:
<?xml version="1.0"?> <response method="###" success="y"> <errors> </errors> <request> <auth password="test" username="test" /> <method action="###" sitename="###" /> </request> <results> <line id="6" logourl="###" name="line 1" smalllogourl="###"> <ships> <ship id="16" name="ship 1" /> <ship id="453" name="ship 2" /> <ship id="468" name="ship 3" /> <ship id="356" name="ship 4" /> </ships> </line> <line id="63" logourl="###" name="line 2" smalllogourl="###"> <ships> <ship id="492" name="ship 1" /> <ship id="454" name="ship 2" /> <ship id="455" name="ship 3" /> <ship id="421" name="ship 4" /> <ship id="401" name="ship 5" /> <ship id="404" name="ship 6" /> <ship id="405" name="ship 7" /> <ship id="406" name="ship 8" /> <ship id="407" name="ship 9" /> <ship id="408" name="ship 10" /> </ships> </line> <line id="41" logourl="###"> <ships> <ship id="229" name="ship 1" /> <ship id="230" name="ship 2" /> <ship id="231" name="ship 3" /> <ship id="445" name="ship 4" /> <ship id="570" name="ship 5" /> <ship id="571" name="ship 6" /> </ships> </line> </results> </response>
if possible when suggesting technlogy best project, if provide getting started guides or information appreciated.
thank taking time read this.
xslt works charm , supported php. takes xslt script output xml file:
<?xml version="1.0" encoding="utf-8"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/xsl/transform"> <xsl:template match="/"> <html> <head> <title>test</title> </head> <body> <h1>user: <xsl:value-of select="//request/auth/@username"/></h1> <xsl:apply-templates select="//results/line"/> </body> </html> </xsl:template> <xsl:template match="line"> <div> <h3>line id: <xsl:value-of select="@id"/></h3> <xsl:apply-templates select="./ships/ship"/> </div> </xsl:template> <xsl:template match="ship"> <div> <xsl:value-of select="@id"/> <xsl:text> - </xsl:text> <xsl:value-of select="@name"/> </div> </xsl:template> </xsl:stylesheet>
to run script against file use 3 lines of php code:
<?php $proc=new xsltprocessor; $proc->importstylesheet(domdocument::load("test.xsl")); //load script echo $proc->transformtoxml(domdocument::load("test.xml")); //load file ?>
you can try transformation in browser without php adding this
<?xml-stylesheet type="text/xsl" href="test.xsl"?>
second line in xml file , opening xml file in firefox or ie having xsl file in same folder.
changing 3rd php line in this
$proc->transformtouri(domdocument::load("test.xml"),"test.html");
save output static file.
some advice suggested here:
https://stackoverflow.com/questions/339930/any-good-xslt-tutorial-book-blog-site-online
Comments
Post a Comment