1 <?xml version="1.0" encoding="UTF-8"?>
3 <sect1 id="zend.feed.modifying-feed">
4 <title>Modifying Feed and Entry structures</title>
7 <classname>Zend_Feed</classname>'s natural syntax extends to constructing and modifying
8 feeds and entries as well as reading them. You can easily turn your new or modified objects
9 back into well-formed <acronym>XML</acronym> for saving to a file or sending to a server.
12 <example id="zend.feed.modifying-feed.example.modifying">
13 <title>Modifying an Existing Feed Entry</title>
15 <programlisting language="php"><![CDATA[
16 $feed = new Zend_Feed_Atom('http://atom.example.com/feed/1');
17 $entry = $feed->current();
19 $entry->title = 'This is a new title';
20 $entry->author->email = 'my_email@example.com';
22 echo $entry->saveXML();
26 This will output a full (includes <code><?xml ... ></code> prologue)
27 <acronym>XML</acronym> representation of the new entry, including any necessary
28 <acronym>XML</acronym> namespaces.
32 Note that the above will work even if the existing entry does not already have an author
33 tag. You can use as many levels of <code>-></code> access as you like before getting
34 to an assignment; all of the intervening levels will be created for you automatically if
40 If you want to use a namespace other than <code>atom:</code>, <code>rss:</code>, or
41 <code>osrss:</code> in your entry, you need to register the namespace with
42 <classname>Zend_Feed</classname> using
43 <methodname>Zend_Feed::registerNamespace()</methodname>. When you are modifying an existing
44 element, it will always maintain its original namespace. When adding a new element, it will
45 go into the default namespace if you do not explicitly specify another namespace.
48 <example id="zend.feed.modifying-feed.example.creating">
49 <title>Creating an Atom Entry with Elements of Custom Namespaces</title>
51 <programlisting language="php"><![CDATA[
52 $entry = new Zend_Feed_Entry_Atom();
53 // id is always assigned by the server in Atom
54 $entry->title = 'my custom entry';
55 $entry->author->name = 'Example Author';
56 $entry->author->email = 'me@example.com';
58 // Now do the custom part.
59 Zend_Feed::registerNamespace('myns', 'http://www.example.com/myns/1.0');
61 $entry->{'myns:myelement_one'} = 'my first custom value';
62 $entry->{'myns:container_elt'}->part1 = 'first nested custom part';
63 $entry->{'myns:container_elt'}->part2 = 'second nested custom part';
65 echo $entry->saveXML();