本文整理汇总了Python中elementtree.ElementTree.SubElement.attrib['type']方法的典型用法代码示例。如果您正苦于以下问题:Python SubElement.attrib['type']方法的具体用法?Python SubElement.attrib['type']怎么用?Python SubElement.attrib['type']使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类elementtree.ElementTree.SubElement
的用法示例。
在下文中一共展示了SubElement.attrib['type']方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: showNotes
# 需要导入模块: from elementtree.ElementTree import SubElement [as 别名]
# 或者: from elementtree.ElementTree.SubElement import attrib['type'] [as 别名]
from elementtree import ElementTree
import httplib2
import time
BASE = "http:??localhost:3000/"
client = httplib2.Http(".cache")
def showNotes():
headers, xml = client.request(BASE + "notes.xml")
doc = ElementTree.fromstring(xml)
for note in doc.findall('note'):
print "%s: %s" % (note.find('date').text, note.find('body').text)
newNote = Element("note")
date = SubElement(newNote, "date")
date.attrib['type'] = "date"
date.text = time.strftime("%Y-%m-%d", time.localtime())
body = SubElement(newNote, "body")
body.text = "A test note"
headers, ignore = client.request(BASE + "notes.xml", "POST",
body = tostring(newNote),
headers={'content-type': 'application/xml'})
newURI = headers['location']
modifiedBody = Element("note")
body = SubElement(modifiedBody, "body")
body.text = "This note has been modified"
client.request(newURI, "PUT",
body=tostring(modifiedBody),