Sophie

Sophie

distrib > Fedora > 18 > i386 > by-pkgid > 7e03e96dde1cbbdbc7cc96424cd9e059 > files > 316

python-feedparser-doc-5.1.3-3.fc18.noarch.rpm



<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">


<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    
    <title>Namespace Handling &mdash; feedparser 5.1.3 documentation</title>
    
    <link rel="stylesheet" href="_static/default.css" type="text/css" />
    <link rel="stylesheet" href="_static/pygments.css" type="text/css" />
    <link rel="stylesheet" href="_static/feedparser.css" type="text/css" />
    
    <script type="text/javascript">
      var DOCUMENTATION_OPTIONS = {
        URL_ROOT:    '',
        VERSION:     '5.1.3',
        COLLAPSE_INDEX: false,
        FILE_SUFFIX: '.html',
        HAS_SOURCE:  true
      };
    </script>
    <script type="text/javascript" src="_static/jquery.js"></script>
    <script type="text/javascript" src="_static/underscore.js"></script>
    <script type="text/javascript" src="_static/doctools.js"></script>
    <link rel="top" title="feedparser 5.1.3 documentation" href="index.html" />
    <link rel="up" title="Advanced Features" href="advanced.html" />
    <link rel="next" title="Relative Link Resolution" href="resolving-relative-links.html" />
    <link rel="prev" title="Content Normalization" href="content-normalization.html" /> 
  </head>
  <body>
    <div class="related">
      <h3>Navigation</h3>
      <ul>
        <li class="right" style="margin-right: 10px">
          <a href="genindex.html" title="General Index"
             accesskey="I">index</a></li>
        <li class="right" >
          <a href="resolving-relative-links.html" title="Relative Link Resolution"
             accesskey="N">next</a> |</li>
        <li class="right" >
          <a href="content-normalization.html" title="Content Normalization"
             accesskey="P">previous</a> |</li>
        <li><a href="index.html">feedparser 5.1.3 documentation</a> &raquo;</li>
          <li><a href="advanced.html" accesskey="U">Advanced Features</a> &raquo;</li> 
      </ul>
    </div>  

    <div class="document">
      <div class="documentwrapper">
        <div class="bodywrapper">
          <div class="body">
            
  <div class="section" id="namespace-handling">
<span id="advanced-namespaces"></span><h1>Namespace Handling<a class="headerlink" href="#namespace-handling" title="Permalink to this headline">¶</a></h1>
<p><strong class="program">Universal Feed Parser</strong> attempts to expose all possible data in feeds,
including elements in extension namespaces.</p>
<p>Some common namespaced elements are mapped to core elements.  For further
information about these mappings, see <a class="reference internal" href="reference.html#reference"><em>Reference</em></a>.</p>
<p>Other namespaced elements are available as <tt class="docutils literal"><span class="pre">prefixelement</span></tt>.</p>
<p>The namespaces defined in the feed are available in the parsed results as
<tt class="docutils literal"><span class="pre">namespaces</span></tt>, a dictionary of {prefix: namespaceURI}.  If the feed defines a
default namespace, it is listed as <tt class="docutils literal"><span class="pre">namespaces['']</span></tt>.</p>
<div class="section" id="accessing-namespaced-elements">
<h2>Accessing namespaced elements<a class="headerlink" href="#accessing-namespaced-elements" title="Permalink to this headline">¶</a></h2>
<div class="highlight-python"><div class="highlight"><pre><span class="gp">&gt;&gt;&gt; </span><span class="kn">import</span> <span class="nn">feedparser</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">d</span> <span class="o">=</span> <span class="n">feedparser</span><span class="o">.</span><span class="n">parse</span><span class="p">(</span><span class="s">&#39;http://feedparser.org/docs/examples/prism.rdf&#39;</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">d</span><span class="o">.</span><span class="n">feed</span><span class="o">.</span><span class="n">prism_issn</span>
<span class="go">u&#39;0028-0836&#39;</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">d</span><span class="o">.</span><span class="n">namespaces</span>
<span class="go">{&#39;&#39;: u&#39;http://purl.org/rss/1.0/&#39;,</span>
<span class="go">&#39;prism&#39;: u&#39;http://prismstandard.org/namespaces/1.2/basic/&#39;,</span>
<span class="go">&#39;rdf&#39;: u&#39;http://www.w3.org/1999/02/22-rdf-syntax-ns#&#39;}</span>
</pre></div>
</div>
<p>The prefix used to construct the variable name is not guaranteed to be the same
as the prefix of the namespaced element in the original feed.  If
<strong class="program">Universal Feed Parser</strong> recognizes the namespace, it will use the
namespace&#8217;s preferred prefix to construct the variable name.  It will also list
the namespace in the <tt class="docutils literal"><span class="pre">namespaces</span></tt> dictionary using the namespace&#8217;s preferred
prefix.</p>
<p>In the previous example, the namespace
(<a class="reference external" href="http://prismstandard.org/namespaces/1.2/basic/">http://prismstandard.org/namespaces/1.2/basic/</a>) was defined with the
namespace&#8217;s preferred prefix (prism), so the prism:issn element was accessible
as the variable <tt class="docutils literal"><span class="pre">d.feed.prism_issn</span></tt>.  However, if the namespace is defined
with a non-standard prefix, <strong class="program">Universal Feed Parser</strong> will still
construct the variable name using the preferred prefix, <em>not</em> the actual prefix
that is used in the feed.</p>
<p>This will become clear with an example.</p>
</div>
<div class="section" id="accessing-namespaced-elements-with-non-standard-prefixes">
<h2>Accessing namespaced elements with non-standard prefixes<a class="headerlink" href="#accessing-namespaced-elements-with-non-standard-prefixes" title="Permalink to this headline">¶</a></h2>
<div class="highlight-python"><pre>&gt;&gt;&gt; import feedparser
&gt;&gt;&gt; d = feedparser.parse('http://feedparser.org/docs/examples/nonstandard_prefix.rdf')
&gt;&gt;&gt; d.feed.prism_issn
u'0028-0836'
&gt;&gt;&gt; d.feed.foo_issn
Traceback (most recent call last):
File "&lt;stdin&gt;", line 1, in ?
File "feedparser.py", line 158, in __getattr__
raise AttributeError, "object has no attribute '%s'" % key
AttributeError: object has no attribute 'foo_issn'
&gt;&gt;&gt; d.namespaces
{'': u'http://purl.org/rss/1.0/',
'prism': u'http://prismstandard.org/namespaces/1.2/basic/',
'rdf': u'http://www.w3.org/1999/02/22-rdf-syntax-ns#'}</pre>
</div>
<p>This is the complete list of namespaces that <strong class="program">Universal Feed Parser</strong>
recognizes and uses to construct the variable names for data in these
namespaces:</p>
<table border="1" class="docutils">
<colgroup>
<col width="22%" />
<col width="78%" />
</colgroup>
<thead valign="bottom">
<tr class="row-odd"><th class="head">Prefix</th>
<th class="head">Namespace</th>
</tr>
</thead>
<tbody valign="top">
<tr class="row-even"><td>admin</td>
<td><a class="reference external" href="http://webns.net/mvcb/">http://webns.net/mvcb/</a></td>
</tr>
<tr class="row-odd"><td>ag</td>
<td><a class="reference external" href="http://purl.org/rss/1.0/modules/aggregation/">http://purl.org/rss/1.0/modules/aggregation/</a></td>
</tr>
<tr class="row-even"><td>annotate</td>
<td><a class="reference external" href="http://purl.org/rss/1.0/modules/annotate/">http://purl.org/rss/1.0/modules/annotate/</a></td>
</tr>
<tr class="row-odd"><td>audio</td>
<td><a class="reference external" href="http://media.tangent.org/rss/1.0/">http://media.tangent.org/rss/1.0/</a></td>
</tr>
<tr class="row-even"><td>blogChannel</td>
<td><a class="reference external" href="http://backend.userland.com/blogChannelModule">http://backend.userland.com/blogChannelModule</a></td>
</tr>
<tr class="row-odd"><td>cc</td>
<td><a class="reference external" href="http://web.resource.org/cc/">http://web.resource.org/cc/</a></td>
</tr>
<tr class="row-even"><td>co</td>
<td><a class="reference external" href="http://purl.org/rss/1.0/modules/company">http://purl.org/rss/1.0/modules/company</a></td>
</tr>
<tr class="row-odd"><td>content</td>
<td><a class="reference external" href="http://purl.org/rss/1.0/modules/content/">http://purl.org/rss/1.0/modules/content/</a></td>
</tr>
<tr class="row-even"><td>cp</td>
<td><a class="reference external" href="http://my.theinfo.org/changed/1.0/rss/">http://my.theinfo.org/changed/1.0/rss/</a></td>
</tr>
<tr class="row-odd"><td>creativeCommons</td>
<td><a class="reference external" href="http://backend.userland.com/creativeCommonsRssModule">http://backend.userland.com/creativeCommonsRssModule</a></td>
</tr>
<tr class="row-even"><td>dc</td>
<td><a class="reference external" href="http://purl.org/dc/elements/1.1/">http://purl.org/dc/elements/1.1/</a></td>
</tr>
<tr class="row-odd"><td>dcterms</td>
<td><a class="reference external" href="http://purl.org/dc/terms/">http://purl.org/dc/terms/</a></td>
</tr>
<tr class="row-even"><td>email</td>
<td><a class="reference external" href="http://purl.org/rss/1.0/modules/email/">http://purl.org/rss/1.0/modules/email/</a></td>
</tr>
<tr class="row-odd"><td>ev</td>
<td><a class="reference external" href="http://purl.org/rss/1.0/modules/event/">http://purl.org/rss/1.0/modules/event/</a></td>
</tr>
<tr class="row-even"><td>feedburner</td>
<td><a class="reference external" href="http://rssnamespace.org/feedburner/ext/1.0">http://rssnamespace.org/feedburner/ext/1.0</a></td>
</tr>
<tr class="row-odd"><td>fm</td>
<td><a class="reference external" href="http://freshmeat.net/rss/fm/">http://freshmeat.net/rss/fm/</a></td>
</tr>
<tr class="row-even"><td>foaf</td>
<td><a class="reference external" href="http://xmlns.com/foaf/0.1/">http://xmlns.com/foaf/0.1/</a></td>
</tr>
<tr class="row-odd"><td>geo</td>
<td><a class="reference external" href="http://www.w3.org/2003/01/geo">http://www.w3.org/2003/01/geo</a>/wgs84_pos#</td>
</tr>
<tr class="row-even"><td>icbm</td>
<td><a class="reference external" href="http://postneo.com/icbm/">http://postneo.com/icbm/</a></td>
</tr>
<tr class="row-odd"><td>image</td>
<td><a class="reference external" href="http://purl.org/rss/1.0/modules/image/">http://purl.org/rss/1.0/modules/image/</a></td>
</tr>
<tr class="row-even"><td>itunes</td>
<td><a class="reference external" href="http://example.com/DTDs/PodCast-1.0.dtd">http://example.com/DTDs/PodCast-1.0.dtd</a></td>
</tr>
<tr class="row-odd"><td>itunes</td>
<td><a class="reference external" href="http://www.itunes.com/DTDs/PodCast-1.0.dtd">http://www.itunes.com/DTDs/PodCast-1.0.dtd</a></td>
</tr>
<tr class="row-even"><td>l</td>
<td><a class="reference external" href="http://purl.org/rss/1.0/modules/link/">http://purl.org/rss/1.0/modules/link/</a></td>
</tr>
<tr class="row-odd"><td>media</td>
<td><a class="reference external" href="http://search.yahoo.com/mrss">http://search.yahoo.com/mrss</a></td>
</tr>
<tr class="row-even"><td>pingback</td>
<td><a class="reference external" href="http://madskills.com/public/xml/rss/module/pingback/">http://madskills.com/public/xml/rss/module/pingback/</a></td>
</tr>
<tr class="row-odd"><td>prism</td>
<td><a class="reference external" href="http://prismstandard.org/namespaces/1.2/basic/">http://prismstandard.org/namespaces/1.2/basic/</a></td>
</tr>
<tr class="row-even"><td>rdf</td>
<td><a class="reference external" href="http://www.w3.org/1999/02/22-rdf-syntax">http://www.w3.org/1999/02/22-rdf-syntax</a>-ns#</td>
</tr>
<tr class="row-odd"><td>rdfs</td>
<td><a class="reference external" href="http://www.w3.org/2000/01/rdf">http://www.w3.org/2000/01/rdf</a>-schema#</td>
</tr>
<tr class="row-even"><td>ref</td>
<td><a class="reference external" href="http://purl.org/rss/1.0/modules/reference/">http://purl.org/rss/1.0/modules/reference/</a></td>
</tr>
<tr class="row-odd"><td>reqv</td>
<td><a class="reference external" href="http://purl.org/rss/1.0/modules/richequiv/">http://purl.org/rss/1.0/modules/richequiv/</a></td>
</tr>
<tr class="row-even"><td>search</td>
<td><a class="reference external" href="http://purl.org/rss/1.0/modules/search/">http://purl.org/rss/1.0/modules/search/</a></td>
</tr>
<tr class="row-odd"><td>slash</td>
<td><a class="reference external" href="http://purl.org/rss/1.0/modules/slash/">http://purl.org/rss/1.0/modules/slash/</a></td>
</tr>
<tr class="row-even"><td>soap</td>
<td><a class="reference external" href="http://schemas.xmlsoap.org/soap/envelope/">http://schemas.xmlsoap.org/soap/envelope/</a></td>
</tr>
<tr class="row-odd"><td>ss</td>
<td><a class="reference external" href="http://purl.org/rss/1.0/modules/servicestatus/">http://purl.org/rss/1.0/modules/servicestatus/</a></td>
</tr>
<tr class="row-even"><td>str</td>
<td><a class="reference external" href="http://hacks.benhammersley.com/rss/streaming/">http://hacks.benhammersley.com/rss/streaming/</a></td>
</tr>
<tr class="row-odd"><td>sub</td>
<td><a class="reference external" href="http://purl.org/rss/1.0/modules/subscription/">http://purl.org/rss/1.0/modules/subscription/</a></td>
</tr>
<tr class="row-even"><td>sy</td>
<td><a class="reference external" href="http://purl.org/rss/1.0/modules/syndication/">http://purl.org/rss/1.0/modules/syndication/</a></td>
</tr>
<tr class="row-odd"><td>szf</td>
<td><a class="reference external" href="http://schemas.pocketsoap.com/rss/myDescModule/">http://schemas.pocketsoap.com/rss/myDescModule/</a></td>
</tr>
<tr class="row-even"><td>taxo</td>
<td><a class="reference external" href="http://purl.org/rss/1.0/modules/taxonomy/">http://purl.org/rss/1.0/modules/taxonomy/</a></td>
</tr>
<tr class="row-odd"><td>thr</td>
<td><a class="reference external" href="http://purl.org/rss/1.0/modules/threading/">http://purl.org/rss/1.0/modules/threading/</a></td>
</tr>
<tr class="row-even"><td>ti</td>
<td><a class="reference external" href="http://purl.org/rss/1.0/modules/textinput/">http://purl.org/rss/1.0/modules/textinput/</a></td>
</tr>
<tr class="row-odd"><td>trackback</td>
<td><a class="reference external" href="http://madskills.com/public/xml/rss/module/trackback/">http://madskills.com/public/xml/rss/module/trackback/</a></td>
</tr>
<tr class="row-even"><td>wfw</td>
<td><a class="reference external" href="http://wellformedweb.org/CommentAPI/">http://wellformedweb.org/CommentAPI/</a></td>
</tr>
<tr class="row-odd"><td>wiki</td>
<td><a class="reference external" href="http://purl.org/rss/1.0/modules/wiki/">http://purl.org/rss/1.0/modules/wiki/</a></td>
</tr>
<tr class="row-even"><td>xhtml</td>
<td><a class="reference external" href="http://www.w3.org/1999/xhtml">http://www.w3.org/1999/xhtml</a></td>
</tr>
<tr class="row-odd"><td>xlink</td>
<td><a class="reference external" href="http://www.w3.org/1999/xlink">http://www.w3.org/1999/xlink</a></td>
</tr>
<tr class="row-even"><td>xml</td>
<td><a class="reference external" href="http://www.w3.org/XML/1998/namespace">http://www.w3.org/XML/1998/namespace</a></td>
</tr>
</tbody>
</table>
<div class="admonition note">
<p class="first admonition-title">Note</p>
<p class="last"><strong class="program">Universal Feed Parser</strong> treats namespaces as case-insensitive to
match the behavior of certain versions of <strong class="program">iTunes</strong>.</p>
</div>
<div class="admonition warning">
<p class="first admonition-title">Warning</p>
<p class="last">Data from namespaced elements is not <a class="reference internal" href="html-sanitization.html#advanced-sanitization"><em>sanitized</em></a>
(even if it contains <abbr title="HyperText Markup Language">HTML</abbr> markup).</p>
</div>
</div>
</div>


          </div>
        </div>
      </div>
      <div class="sphinxsidebar">
        <div class="sphinxsidebarwrapper">
  <h3><a href="index.html">Table Of Contents</a></h3>
  <ul>
<li><a class="reference internal" href="#">Namespace Handling</a><ul>
<li><a class="reference internal" href="#accessing-namespaced-elements">Accessing namespaced elements</a></li>
<li><a class="reference internal" href="#accessing-namespaced-elements-with-non-standard-prefixes">Accessing namespaced elements with non-standard prefixes</a></li>
</ul>
</li>
</ul>

  <h4>Previous topic</h4>
  <p class="topless"><a href="content-normalization.html"
                        title="previous chapter">Content Normalization</a></p>
  <h4>Next topic</h4>
  <p class="topless"><a href="resolving-relative-links.html"
                        title="next chapter">Relative Link Resolution</a></p>
  <h3>This Page</h3>
  <ul class="this-page-menu">
    <li><a href="_sources/namespace-handling.txt"
           rel="nofollow">Show Source</a></li>
  </ul>
<div id="searchbox" style="display: none">
  <h3>Quick search</h3>
    <form class="search" action="search.html" method="get">
      <input type="text" name="q" />
      <input type="submit" value="Go" />
      <input type="hidden" name="check_keywords" value="yes" />
      <input type="hidden" name="area" value="default" />
    </form>
    <p class="searchtip" style="font-size: 90%">
    Enter search terms or a module, class or function name.
    </p>
</div>
<script type="text/javascript">$('#searchbox').show(0);</script>
        </div>
      </div>
      <div class="clearer"></div>
    </div>
    <div class="related">
      <h3>Navigation</h3>
      <ul>
        <li class="right" style="margin-right: 10px">
          <a href="genindex.html" title="General Index"
             >index</a></li>
        <li class="right" >
          <a href="resolving-relative-links.html" title="Relative Link Resolution"
             >next</a> |</li>
        <li class="right" >
          <a href="content-normalization.html" title="Content Normalization"
             >previous</a> |</li>
        <li><a href="index.html">feedparser 5.1.3 documentation</a> &raquo;</li>
          <li><a href="advanced.html" >Advanced Features</a> &raquo;</li> 
      </ul>
    </div>
    <div class="footer">
        &copy; Copyright 2004-2008 Mark Pilgrim, 2010-2012 Kurt McKee.
      Created using <a href="http://sphinx.pocoo.org/">Sphinx</a> 1.1.3.
    </div>
  </body>
</html>