how do I use my php file to attach an active url to my output (XML) file

180 views Asked by At

I have a fairly simple php file that attempts to create an XML document. I am trying to get the URLs pulled from the mysql database to show up in the XML document that i create.

I cannot seem to figure out why my url's are ignored without xlink information. That is the mysql database is accessed successfully but only the title and description information is created in the xml document.

And when I add the xlink information the document simply gives no output at all. The code is below.

<?php header('Content-Type: text/xml'); ?>
<?php echo '<?xml version="1.0" encoding="utf-8"?>'; ?>
<rss version="2.0">
    <channel xmlns:xlink="http://www.w3.org/1999/xlink>
        <title>METHUZALA.COM</title>
        <link xlink:type="simple" xlink:href="http://www.methuzala.com">http://www.methuzala.com</link>
        <description>UPDATE: Articles Found and Added</description>
        <language> en-us </language>

        <?php 
            require('php/includes/path.php');
            $conn= mysqli_connect(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME );
            $query="SELECT title, short_title, article_url, short_description from  news_article";
            $data = mysqli_query($conn,$query);
            while ($row = mysqli_fetch_array($data))  {
                echo '<item">';
                echo '<title>'.  $row['title']. '</title>';
                echo '<wurl xlink:type="simple" xlink:href="'.$row['article_url'].'" xlink:show="new">TESTING'.'</wurl>';
                echo '<description>'. $row['short_description']. '</description>';
                echo '</item>';
            } //while-end of file
            mysqli_close($conn);
            echo '</item>';
        ?>
    </channel>
</rss>    
2

There are 2 answers

5
Rod On

I welcome any input that might be helpful. I removed the xlink information and this code produces a result that is radically different depending on the browser.

In Chrome: It gives the correct rss XML file output, but no newsfeed output.

In Safari: It gives the correct newsfeed output but it is not formatted. it is one large paragraph.

In Firefox: It gives the correct first lines of the channel(Title of the newsfeed, description of the newsfeed, but no links or elements show in the xml output. Elements are all blank.

<?php header('Content-Type: text/xml'); 
echo '<?xml version="1.0" encoding="utf-8"?>'; ?>
<rss version="2.0">
    <channel>
        <title>METHUZALA.COM</title>
        <link>http://www.methuzala.com</link>
        <description>UPDATE: Articles Found and Added</description>
        <language> en-us </language>

        <?php 
            require('php/includes/path.php');
            $conn= mysqli_connect(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME );
            $query="SELECT title, article_url, short_description from  news_article";
            $data = mysqli_query($conn,$query);
            while ($row = mysqli_fetch_array($data))  {
                $title=$row['title'];
                $wurl=$row['article_url'];
                $description=$row['short_description'];
        ?>
        <element> 
            <title><?php echo $title; ?></title>
            <link><?php echo $wurl; ?></link>
            <description><?php echo $description; ?></description>
        </element>
        <?php
        }
        mysqli_close($conn);
        ?>
    </channel>
</rss>

firefox output safari output

1
Nigel Ren On

When you are opening the <item> tag, you have an extra quote...

echo '<item">';

Should be

echo '<item>';

This would through out the quoting of data cause all sorts to be combined.