0

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.

pelagos
  • 1,025
  • 3
  • 17
  • 27
  • You may want to check out the [DOMDocument](http://www.php.net/manual/en/class.domdocument.php) class. – Horse SMith Oct 27 '13 at 01:07
  • Thanks - I know it has something to do with that. I am using the DMODocument class at present to update the catalogue.xml file via a form (upload image and add info). I am just not sure how I link them to update the rss.xml file at the same time. – pelagos Oct 27 '13 at 02:09
  • You can go through it's nodes and "convert"/change them (`getElementsByTagName`), or you can use them to build a new XML file. Check the documentation/API to DOMDocument I linked to and you can always try to use search on google, or [here](http://stackoverflow.com/questions/6001923/php-domdocument-question-how-to-replace-text-of-a-node)'s a similar case. – Horse SMith Oct 27 '13 at 02:17
  • Thanks Horse - I have update my original post with the php code I am using. The top half (original code to update catalogue.xml) is fine. The bottom half (trying to update rss.xml as well) is not working. The code runs but nothing in rss.xml gets updated. Thanks – pelagos Oct 27 '13 at 04:35
  • Hi pelagos - sorry if I've missed something subtle, but you're opening `rss.xml` as `$rss_doc`, but then saving `$doc` as `rss.xml`. Shouldn't you be doing `$rss_doc->save("rss.xml")`? – Clart Tent Oct 27 '13 at 08:33
  • Yeah that was a typo - I have corrected and it is still not working. The original catalogue.xml gets updated but rss.xml does not. Thanks – pelagos Oct 27 '13 at 08:38
  • Please fix that typo in the code here as well and also please properly indent (format) your code when you add it here. Also re-create a new example that demonstrates your issue but with as little code and data as possible. Just enough to demonstrate your issue. Do not just provide an excerpt from your code, instead re-write it from scratch to create an example for testing purposes. – hakre Oct 27 '13 at 09:12
  • Thanks - I have updated the code above as requested. I am not sure how to shorten it to demonstrate the issue? Thanks for any help - obviously relatively new to all this... – pelagos Oct 27 '13 at 10:44

1 Answers1

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!

pelagos
  • 1,025
  • 3
  • 17
  • 27