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 6 of 6
  1. #1
    me'
    me' is offline
    Senior Coder
    Join Date
    Nov 2002
    Location
    Warwickshire, England
    Posts
    1,229
    Thanks
    0
    Thanked 0 Times in 0 Posts

    XSLT functions claim my XML isn't well formed?

    Well, I got my XSLT functions to work (php.ini had an incorrect extensions directory stored), but now they claim my XML isn't well formed! Well, to be exact:
    XML parser error 4: not well-formed (invalid token)
    Okay, some code:
    Code:
    php
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
       "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
      <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
      <title>RSS Feed Parser</title>
    </head>
    <body>
    <?php
      $xh = xslt_create();
      $result = xslt_process($xh, 'http://localhost/trial/rss-feed.xml', 'http://localhost/trial/rss-parser.xsl');
      if (!$result) {echo "<p><strong>error:</strong> " . xslt_error($xh) . "</p>";} else echo "\" $result \"";
      
      xslt_free($xh);
    ?>
    </body>
    </html>
    
    xslt
    <?xml version="1.0" encoding="ISO-8859-1"?>
    <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    
    <xsl:template match="rss/channel">
      <h1>RSS Feed Parser</h1>
      <xsl:for-each select="item">
        <h2><xsl:value-of select="title" /></h2>
        <p><xsl:value-of select="description" /></p>
      </xsl:for-each>
    </xsl:template>
    
    </xsl:stylesheet>
    
    rss
    <?xml version="1.0" encoding="ISO-8859-1"?>
    <rss version="2.0">
    <channel>
    <item>
      <title>Test</title>
      <description>Some random stuff should go here. Not sure what.</description>
      <link>http://www.xmouse.com/showpost.php?id=221203085328</link>
    </item>
    
    <item>
      <title>Test2</title>
      <description>The second test that I'll be writing. This one comes courteous of some random bloke that I pulled off the street. Here he is, ladies and gentlemen: *Grunt* Yes, well, wasn't that interesting? I can't be bothered to write anything else, this'll do for a simple test.</description>
      <link>http://www.xmouse.com/showpost.php?id=221203085223</link>
    </item>
    
    <title>My random trial RSS feedy thing</title>
    <link>#</link>
    <language>en</language>
    
    </channel>
    </rss>
    All looks well formed to me...
    David House - Perfect is achieved, not when there is nothing left to add, but when there is nothing left to take away. (Antoine de St. Exupery).
    W3Schools | XHTML Validator | CSS Validator | Colours | Typography | HTML&CSS FAQ | Go get Mozilla Now | I blog!

  • #2
    Mega-ultimate member
    Join Date
    Jun 2002
    Location
    Winona, MN - The land of 10,000 lakes
    Posts
    1,855
    Thanks
    1
    Thanked 45 Times in 42 Posts
    Just a guess here, but I've noticed when I was doing RSS feeds that if I called a file through http, I got all the http headers returned. Although the file it self does not contain them, the server will prepend them on the response.

    To check this, try to open the file through http and then write the file (with a new name) somewhere. Usually the newly written file will contain the http response headers. That's probably what's causing the problem.

    You may need to filter them out before you start processing the xml.

    <edit>
    You may want to check out
    this post.
    </edit>

    Hope this helps.

  • #3
    Super Moderator
    Join Date
    May 2002
    Location
    Perth Australia
    Posts
    4,108
    Thanks
    11
    Thanked 101 Times in 99 Posts
    try the alternate way , I think the issues you are having are either as bcarl suggests above , OR an issue with PHP streams and how they fetch content + a bug/feature with sablatron itslef ??


    anyway , this works..
    PHP Code:
    <?php 
    $files 
    = array( 
        
    '/_xml' => implode'' file'http://localhost/rss-feed.xml' ) ), 
        
    '/_xsl' => implode'' file'http://localhost/rss-parser.xsl' ) ) 
    ); 

    $xh xslt_create(); 
    xslt_set_log$xh true ) ; 
    xslt_set_log$xh 'e:/phpdev/www/myfile.log' ) ; 
    if( 
    $whoot xslt_process$xh 'arg:/_xml' 'arg:/_xsl' NULL $files ) ){
        echo 
    $whoot ;
    }else { 
       echo 
    "<p><strong>error:</strong> " xslt_error($xh) . "</p>" ;

    xslt_free$xh ) ; 

    die() ;
    ?>
    resistance is...

    MVC is the current buzz in web application architectures. It comes from event-driven desktop application design and doesn't fit into web application design very well. But luckily nobody really knows what MVC means, so we can call our presentation layer separation mechanism MVC and move on. (Rasmus Lerdorf)

  • #4
    me'
    me' is offline
    Senior Coder
    Join Date
    Nov 2002
    Location
    Warwickshire, England
    Posts
    1,229
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Awesome! Thanks guys, this is a great help.
    David House - Perfect is achieved, not when there is nothing left to add, but when there is nothing left to take away. (Antoine de St. Exupery).
    W3Schools | XHTML Validator | CSS Validator | Colours | Typography | HTML&CSS FAQ | Go get Mozilla Now | I blog!

  • #5
    me'
    me' is offline
    Senior Coder
    Join Date
    Nov 2002
    Location
    Warwickshire, England
    Posts
    1,229
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Got ahead of myself there.
    XML parser error 3: no element found
    Where:
    Code:
    +------------+--------------+--------------+--------------+
    |            | relative url | absolute url | nonlocal url |
    +------------+--------------+--------------+--------------+
    | with $_GET | no error     | no error     | error        |
    +------------+--------------+--------------+--------------+
    | without    | no error     | no error     | error        |
    +------------+--------------+--------------+--------------+
    relative url is something like 'index.xml'
    absolute is something like 'http://localhost/trial/index.xml'
    nonlocal url is something like 'http://www.stopdesign.com/index.xml'
    with $_GET means I'm imploding with implode('', $_GET['url']) and passing the url I want to parse.
    Without means I type the location I want to parse into the code itself.

    Okay, I had a look at my errors log file, and:
    [29-Dec-2003 13:43:16] PHP Warning: php_hostconnect: connect failed in c:\program files\pdev\www\trial\rss-parser.php on line 24
    [29-Dec-2003 13:43:16] PHP Warning: file("http://www.stopdesign.com/index.xml") - Bad file descriptor in c:\program files\pdev\www\trial\rss-parser.php on line 24
    [29-Dec-2003 13:43:16] PHP Warning: Bad arguments to implode() in c:\program files\pdev\www\trial\rss-parser.php on line 24
    [29-Dec-2003 13:43:16] PHP Warning: Sablotron error on line 1: XML parser error 3: no element found in c:\program files\pdev\www\trial\rss-parser.php on line 32
    It can't connect. Could this be something to do with the fact that I've got a firewall going?
    Last edited by me'; 12-29-2003 at 02:46 PM.
    David House - Perfect is achieved, not when there is nothing left to add, but when there is nothing left to take away. (Antoine de St. Exupery).
    W3Schools | XHTML Validator | CSS Validator | Colours | Typography | HTML&CSS FAQ | Go get Mozilla Now | I blog!

  • #6
    Super Moderator
    Join Date
    May 2002
    Location
    Perth Australia
    Posts
    4,108
    Thanks
    11
    Thanked 101 Times in 99 Posts
    firstly check that allow_url_fopen = 1 (or 'On') in the php.ini

    either a proxy server or a firewall could be an issue..

    check by seeing if this works...

    PHP Code:
    <?php
    echo implode'' file'http://www.google.com' ) );
    ?>

    else you may need to reconfigure your firewall , or to get around proxies possibly use a http client like Snoopy
    resistance is...

    MVC is the current buzz in web application architectures. It comes from event-driven desktop application design and doesn't fit into web application design very well. But luckily nobody really knows what MVC means, so we can call our presentation layer separation mechanism MVC and move on. (Rasmus Lerdorf)


  •  

    Posting Permissions

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