本文整理匯總了Python中elementtree.ElementTree.SubElement.attrib["scheme"]方法的典型用法代碼示例。如果您正苦於以下問題:Python SubElement.attrib["scheme"]方法的具體用法?Python SubElement.attrib["scheme"]怎麽用?Python SubElement.attrib["scheme"]使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類elementtree.ElementTree.SubElement
的用法示例。
在下文中一共展示了SubElement.attrib["scheme"]方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: CreateSourceElement
# 需要導入模塊: from elementtree.ElementTree import SubElement [as 別名]
# 或者: from elementtree.ElementTree.SubElement import attrib["scheme"] [as 別名]
def CreateSourceElement(ee, feed):
"""Create an atom:source element in the provided entry element,
based on the provided feed metadata.
"""
if not feed: return
root = SubElement(ee, "source")
TextElement(root, "title", feed.get("title_detail"))
if feed.has_key("links"):
for link in feed.links:
LinkElement(root, "link", link)
TextElement(root, "subtitle", feed.get("subtitle_detail"))
TextElement(root, "rights", feed.get("rights_detail"))
SubElement(root, "generator").text = "feedarchive"
SubElement(root, "updated").text = rfc3339(time.time())
SubElementIf(root, "id", feed.get("id"))
if feed.has_key("image"):
SubElement(root, "icon").text = feed.image.href
if feed.has_key("tags"):
for tag in feed.tags:
te = SubElement(root, "category")
if tag.get("term"): te.attrib["term"] = tag.term
if tag.get("scheme"): te.attrib["scheme"] = tag.scheme
if tag.get("label"): te.attrib["label"] = tag.label
PersonElement(root, "author", feed.get("author_detail"))
示例2: GetFeedElement
# 需要導入模塊: from elementtree.ElementTree import SubElement [as 別名]
# 或者: from elementtree.ElementTree.SubElement import attrib["scheme"] [as 別名]
def GetFeedElement(feed):
"""Create an atom:feed element for the provided feed.
The provided feed must be in the format described at http://feedparser.org.
"""
root = Element("feed")
root.attrib["xmlns"] = "http://www.w3.org/2005/Atom"
TextElement(root, "title", feed.feed.get("title_detail"))
if feed.feed.has_key("links"):
for link in feed.feed.links:
LinkElement(root, "link", link)
TextElement(root, "subtitle", feed.feed.get("subtitle_detail"))
TextElement(root, "rights", feed.feed.get("rights_detail"))
SubElement(root, "generator").text = "feedarchive"
SubElement(root, "updated").text = rfc3339(time.time())
SubElementIf(root, "id", feed.feed.get("id"))
if feed.feed.has_key("image"):
SubElement(root, "icon").text = feed.feed.image.href
if feed.feed.has_key("tags"):
for tag in feed.feed.tags:
te = SubElement(root, "category")
if tag.get("term"): te.attrib["term"] = tag.term
if tag.get("scheme"): te.attrib["scheme"] = tag.scheme
if tag.get("label"): te.attrib["label"] = tag.label
PersonElement(root, "author", feed.feed.get("author_detail"))
for entry in feed.entries:
ee = SubElement(root, "entry")
TextElement(ee, "title", entry.get("title_detail"))
if entry.has_key("links"):
for link in entry.links:
LinkElement(ee, "link", link)
TextElement(ee, "summary", entry.get("summary_detail"))
TextElement(ee, "content", entry.get("content_detail"))
DateTimeElement(ee, "published", entry, "published")
DateTimeElement(ee, "updated", entry, "updated")
SubElementIf(ee, "id", entry.get("id"))
PersonElement(ee, "author", entry.get("author_detail"))
PersonElement(ee, "publisher", entry.get("publisher_detail"))
if entry.has_key("contributors"):
for contributor in entry.contributors:
PersonElement(ee, "contributor", contributor)
CreateSourceElement(ee, entry.get("source"))
return root