Update RSS file from another XML file

大憨熊 提交于 2019-12-13 05:39:53

问题


I am not sure how to do this?

I want to be able to update an xml file (which I can do) and then have the rss feed atomically updated from this xml file. Hope this makes sense.

I can update and show the data from my XML file. I do this with XSL and some PHP.

I can create and show the data from an RSS file.

I dont know how to link the two so when I update the XML file it updates the details in the RSS file.

Hope this makes sense.

This is the xml file - catalogue.xml

<?xml version="1.0" encoding="utf-8"?>
<?xml-stylesheet type="text/xsl" href="catalogue.xsl"?>

<catalogue>
  <record>
    <catId>001</catId>
    <title>Fungus</title>
    <location>NPD</location>
    <photographer>jj</photographer>
    <equipment>Canon EOS 40D</equipment>
    <caption>Small fungus</caption>
    <notes>fungus</notes>
    <date>10/8/2012</date>
    <imageUrl>images/IMG_1684.jpg</imageUrl>
  </record>
 </catalogue>

This is the RSS file - rss.xml

<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0">

<channel>
  <title>Photo Catalogue Updates</title>
  <link></link>
  <description></description>
  <item>
    <title>Fungus</title>
    <link>images/IMG_3036.jpg</link>
    <description>A new image has been uploaded</description>
  </item>
</channel>
</rss>

Basically I just need to inform the user via RSS that a new image has been added.

Thanks

UPDATE - Shortened CODE as requested

This is the form:

  <form action="updateaction_rss.php" method="post" enctype="multipart/form-data">
 <table>
    <tr>  
     <td colspan="2"class="labelcell"><label for="title">Title:</label></td>
     <td colspan="2"class="fieldcell"><input type="text" id="title" name="title"  tabindex="2"/></td>
   </tr>
   <td colspan="4"><input type="submit" name="upload" class="box" value="Submit" tabindex="10" /></td>
  </table>
</fieldset>
  </form>

This is the code to update the rss file:

<?php

$record = array(

    'title' => $_POST['title'],
 );



$rss_doc = new DOMDocument('1.0');
$rss_doc->formatOutput = true;
$rss_doc->preserveWhiteSpace = false;
$rss_doc->load( "rss.xml" );


$rss_a = $rss_doc->getElementsByTagName("rss")->item(0);

$rss_b = $rss_doc->createElement("channel");
$rss_a->appendChild( $rss_b );


$rss_title = $rss_doc->createElement("title");
$rss_title->appendChild(
    $rss_doc->createTextNode( $record["title"] )
);
$rss_b->appendChild( $rss_title );


$rss_doc->save("rss.xml");


header("Location: {$_SERVER['HTTP_REFERER']}"); 

?>

Thanks for any advice.


回答1:


OK - Figured it out - My Bad - I had not given the rss.xml file the correct read/write privileges. Sorry and I guess its a good learning experience!



来源:https://stackoverflow.com/questions/19613601/update-rss-file-from-another-xml-file

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!