从另一个 XML 文件更新 RSS 文件 [英] Update RSS file from another XML file

查看:58
本文介绍了从另一个 XML 文件更新 RSS 文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不知道该怎么做?

我希望能够更新一个 xml 文件(我可以这样做),然后从这个 xml 文件自动更新 rss 提要.希望这是有道理的.

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.

我可以更新和显示我的 XML 文件中的数据.我用 XSL 和一些 PHP 来做到这一点.

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

我可以创建和显示来自 RSS 文件的数据.

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

我不知道如何链接两者,因此当我更新 XML 文件时,它会更新 RSS 文件中的详细信息.

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

希望这是有道理的.

这是 xml 文件 - catalogue.xml

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>

这是 RSS 文件 - rss.xml

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>

基本上我只需要通过 RSS 通知用户已添加新图片.

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

谢谢

更新 - 根据要求缩短代码

UPDATE - Shortened CODE as requested

这是表格:

  <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>

这是更新 rss 文件的代码:

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']}"); 

?>

感谢您的建议.

推荐答案

好的 - 想通了 - 我的不好 - 我没有给 rss.xml 文件正确的读/写权限.抱歉,我想这是一次很好的学习体验!

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!

这篇关于从另一个 XML 文件更新 RSS 文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆