Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 1 of 1
  1. #1
    Moderator
    Join Date
    May 2002
    Location
    Hayward, CA
    Posts
    1,459
    Thanks
    1
    Thanked 23 Times in 21 Posts

    mod_perl: Running XML through PHP preprocessor

    Lately I've been revisiting an old thorn in my side for HTTP usage. Namely, how can I pass to PHP, SSI, Perl, or Python (or any other language as needed) an XML document for processing via XML processing instructions?

    At first, I tinkered with the idea of creating custom Apache filename extensions (.pxml, for instance, for PHP-processed XML). A little work with .htaccess showed that wouldn't necessarily fit the bill.

    So I'm exploring another idea, based on something I remember Firepages telling me.

    Suppose I have a URI:

    http://localhost/php/foo.xml

    Where the actual file resides at
    http://localhost/foo.xml

    The "php" directory could be an alias for indicating I should send the document through the PHP interpreter. After it goes through the interpreter, the server would then return the correct mime-type.

    Is this doable, perhaps with a couple sub-requests, perhaps an HTTP HEAD request involved?

    UPDATE: Figured out how to do the PHP thing, at least for phpdev4.2.3. In httpd.conf, add the following:

    Code:
    # run PHP interpreter through a directory request
    Alias /processPHP/ "C:/phpdev/contentTypes/process.php/"
    <Directory "C:/phpdev/contentTypes/">
        Options Indexes FollowSymLinks MultiViews
        AllowOverride None
        Order allow,deny
        Allow from localhost 127.0.0.1
    </Directory>
    php.ini gets its "short_open_tags" value set to "Off", so I don't have to worry about <?xml version="1.0" ?> triggering PHP...

    Then I create a new directory, C:/phpdev/contentTypes/, and I add the following files:

    .htaccess
    Code:
    AddType application/xhtml+xml .xhtml
    AddType image/svg+xml .svg
    process.php
    Code:
    <?php
    $fileInfo = apache_lookup_uri($_SERVER["PATH_INFO"]);
    header("Content-type: ".$fileInfo["content_type"]);
    include_once(substr($_SERVER["DOCUMENT_ROOT"],0,-1).$_SERVER["PATH_INFO"]);
    ?>
    Now I need to figure out equivalents for Perl and Python...
    Last edited by Alex Vincent; 07-13-2003 at 11:46 PM.
    "The first step to confirming there is a bug in someone else's work is confirming there are no bugs in your own."
    June 30, 2001
    author, Verbosio prototype XML Editor
    author, JavaScript Developer's Dictionary
    https://alexvincent.us/blog


 

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •