File: Zend_Feed-ModifyingFeed.xml

package info (click to toggle)
zendframework 1.12.9%2Bdfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: jessie-kfreebsd
  • size: 133,584 kB
  • sloc: xml: 1,311,829; php: 570,173; sh: 170; makefile: 125; sql: 121
file content (71 lines) | stat: -rw-r--r-- 2,851 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
<?xml version="1.0" encoding="UTF-8"?>
<!-- Reviewed: no -->
<sect1 id="zend.feed.modifying-feed">
    <title>Modifying Feed and Entry structures</title>

    <para>
        <classname>Zend_Feed</classname>'s natural syntax extends to constructing and modifying
        feeds and entries as well as reading them. You can easily turn your new or modified objects
        back into well-formed <acronym>XML</acronym> for saving to a file or sending to a server.
    </para>

    <example id="zend.feed.modifying-feed.example.modifying">
        <title>Modifying an Existing Feed Entry</title>

        <programlisting language="php"><![CDATA[
$feed = new Zend_Feed_Atom('http://atom.example.com/feed/1');
$entry = $feed->current();

$entry->title = 'This is a new title';
$entry->author->email = 'my_email@example.com';

echo $entry->saveXML();
]]></programlisting>

        <para>
            This will output a full (includes <command>&lt;?xml ... &gt;</command> prologue)
            <acronym>XML</acronym> representation of the new entry, including any necessary
            <acronym>XML</acronym> namespaces.
        </para>

        <para>
            Note that the above will work even if the existing entry does not already have an author
            tag. You can use as many levels of <command>-&gt;</command> access as you like before
            getting to an assignment; all of the intervening levels will be created for you
            automatically if necessary.
        </para>
    </example>

    <para>
        If you want to use a namespace other than <command>atom:</command>, <command>rss:</command>,
        or <command>osrss:</command> in your entry, you need to register the namespace with
        <classname>Zend_Feed</classname> using
        <methodname>Zend_Feed::registerNamespace()</methodname>. When you are modifying an existing
        element, it will always maintain its original namespace. When adding a new element, it will
        go into the default namespace if you do not explicitly specify another namespace.
    </para>

    <example id="zend.feed.modifying-feed.example.creating">
        <title>Creating an Atom Entry with Elements of Custom Namespaces</title>

        <programlisting language="php"><![CDATA[
$entry = new Zend_Feed_Entry_Atom();
// id is always assigned by the server in Atom
$entry->title = 'my custom entry';
$entry->author->name = 'Example Author';
$entry->author->email = 'me@example.com';

// Now do the custom part.
Zend_Feed::registerNamespace('myns', 'http://www.example.com/myns/1.0');

$entry->{'myns:myelement_one'} = 'my first custom value';
$entry->{'myns:container_elt'}->part1 = 'first nested custom part';
$entry->{'myns:container_elt'}->part2 = 'second nested custom part';

echo $entry->saveXML();
]]></programlisting>
    </example>
</sect1>
<!--
vim:se ts=4 sw=4 et:
-->