cvs: peardoc /en/package/xml xml-feed-parser.xml /en/package/xml/xml-feed-parser extensions.xml intro.xml

From: Date: Sat, 07 Jan 2006 20:20:22 +0000
Subject: cvs: peardoc /en/package/xml xml-feed-parser.xml /en/package/xml/xml-feed-parser extensions.xml intro.xml
Groups: php.pear.doc 
Request: Send a blank email to pear-doc+get-7420@lists.php.net to get a copy of this message
jystewart Sat Jan 7 20:20:22 2006 UTC Added files: /peardoc/en/package/xml xml-feed-parser.xml /peardoc/en/package/xml/xml-feed-parser extensions.xml intro.xml Log: Initial upload of documentation for XML_Feed_Parser http://cvs.php.net/viewcvs.cgi/peardoc/en/package/xml/xml-feed-parser.xml?view=markup&rev=1.1 Index: peardoc/en/package/xml/xml-feed-parser.xml +++ peardoc/en/package/xml/xml-feed-parser.xml <!-- $Revision: 1.1 $ --> <sect1 id="package.xml.xml-feed-parser"> <title>XML_Feed_Parser</title> <para> XML_Feed_Parser is a parser for (the various) RSS and Atom format XML feeds. It provides a somewhat unified API while still allowing access to the full details of each feed type. </para> &package.xml.xml-feed-parser.intro; </sect1> <!-- Keep this comment at the end of the file Local variables: mode: sgml sgml-omittag:t sgml-shorttag:t sgml-minimize-attributes:nil sgml-always-quote-attributes:t sgml-indent-step:1 sgml-indent-data:t sgml-parent-document:nil sgml-default-dtd-file:"../../../manual.ced" sgml-exposed-tags:nil sgml-local-catalogs:nil sgml-local-ecat-files:nil End: vim600: syn=webservices fen fdm=syntax fdl=2 si vim: et tw=78 syn=sgml vi: ts=1 sw=1 --> http://cvs.php.net/viewcvs.cgi/peardoc/en/package/xml/xml-feed-parser/extensions.xml?view=markup&rev=1.1 Index: peardoc/en/package/xml/xml-feed-parser/extensions.xml +++ peardoc/en/package/xml/xml-feed-parser/extensions.xml <?xml version="1.0" encoding="iso-8859-1" ?> <!-- $Revision: 1.1 $ --> <refentry id="package.xml.xml-feed-parser.extensions"> <refnamediv> <refname>XML_Feed_Parser and Extensions</refname> <refpurpose>Handling extensions with XML_Feed_Parser</refpurpose> </refnamediv> <refsect1 id="package.xml.xml-feed-parser.intro.desc"> &title.desc; <para>Using XML namespaces, the various syndication formats are very easy to extend and the number of extensions in use is enormous.</para> <para>XML_Feed_Parser focusses on core functionality shared between the various syndication formats. Some of the most common extensions are handled natively&#8212;particularly when they provide one format with features to bring it into line with others, such as the content extension for RSS2&#8212;but the majority provide specialist content and providing support for them would quickly result in a bloated package.</para> <para>It is possible that a proper extensions mechanism may be introduced in a future version, but as an alternative the DOM models in use within the classes are publicly accessible, allowing the package to be wrapped with special handlers.</para> <para>For example, to make use of the 'pheed' extension (namespace http://www.pheed.com/pheed/) we might use: <programlisting role="php"> $feed = new XML_Feed_Parser($xml_source); $entry = $feed->getEntryByOffset(0); $eModel = $entry->model; $thumbnails = $eModel->getElementsByTagNameNS( 'http://www.pheed.com/pheed/', 'thumbnail'); if ($thumbnails->length) { $thumbnail_url = $thumbnails->item(0)->nodeValue; } </programlisting> </para> </refsect1> </refentry> http://cvs.php.net/viewcvs.cgi/peardoc/en/package/xml/xml-feed-parser/intro.xml?view=markup&rev=1.1 Index: peardoc/en/package/xml/xml-feed-parser/intro.xml +++ peardoc/en/package/xml/xml-feed-parser/intro.xml <?xml version="1.0" encoding="iso-8859-1" ?> <!-- $Revision: 1.1 $ --> <refentry id="package.xml.xml-feed-parser.intro"> <refnamediv> <refname>Introduction and Quick Start</refname> <refpurpose>Overview of XML_Feed_Parser</refpurpose> </refnamediv> <refsect1 id="package.xml.xml-feed-parser.intro.desc"> &title.desc; <para>XML_Feed_Parser provides a generic interface to a number of the most popular XML-based syndication formats (Atom, RSS1, RSS2, etc). In order to focus on its core competencies, it does not provide any HTTP or feed creation features, but instead parses a wide range of formats quickly and simply.</para> <para> Presuming the XML for a feed is stored in the variable $xml_source, the simplest way to create an instance of the parser is: <programlisting role="php">try { $feed = new XML_Feed_Parser($xml_source); } catch (XML_Feed_Parser_Exception $e) { die('Feed invalid: ' . $e->getMessage()); }</programlisting> </para> <para>The constructor accepts a number of parameters, as follows: <programlisting role="php"> /* The file you wish to parse */ $source = 'my_source.xml'; /* Where Relax NG is available, we can force validation of the feed */ $validate = true; /* Whether or not to suppress non-fatal warnings */ $suppress_warnings = false; /* If the feed is not valid XML and the tidy extension is installed we can * attempt to use it to fix the feed */ $use_tidy = true; $feed = new XML_Feed_Parser($source, $validate, $suppress_warnings, $use_tidy);</programlisting> </para> <para>Once you have an instance of the parser you can extract feed-level data by querying it directly. eg. <programlisting role="php">$title = $feed->title;</programlisting> </para> <para>You can also access elements by iterating over the feed, or directly by offset or id. <programlisting role="php"> foreach ($feed as $entry) { print $entry->title . "\n"; } $first_entry = $feed->getEntryByOffset(0); $particular_entry = $feed->getEntryById('http://jystewart.net/entry/1'); </programlisting> </para> <para> </para> </refsect1> </refentry>

« previous php.pear.doc (#7420) next »