XML Outputting - PHP vs JS vs Anything Else?

后端 未结 3 1801
难免孤独
难免孤独 2020-12-21 23:53

I am working on developing a Travel website which uses XML API\'s to get the data.

However i am relatively new to XML and outputting it. I have been experimenting wi

3条回答
  •  心在旅途
    2020-12-22 00:06

    XSLT works like a charm and is supported by PHP. It takes this XSLT script to output your XML file:

    
    
    
        
            
                Test
            
            
                

    User:

    Line ID:

    -

    To run the script against your file use just 3 lines of PHP code:

    importStylesheet(DOMDocument::load("test.xsl")); //load script
    echo $proc->transformToXML(DOMDocument::load("test.xml")); //load your file
    ?>
    

    You can even try this transformation in your browser without any PHP adding this

    as second line in your XML file and opening the XML file in Firefox or IE having the XSL file in the same folder.
    Changing the 3rd PHP line in this
    $proc->transformToUri(DOMDocument::load("test.xml"),"test.html");
    will save the output as static file.

    Some good advice is suggested here:
    https://stackoverflow.com/questions/339930/any-good-xslt-tutorial-book-blog-site-online

提交回复
热议问题