本文整理汇总了Python中elementtree.SimpleXMLWriter.XMLWriter.element方法的典型用法代码示例。如果您正苦于以下问题:Python XMLWriter.element方法的具体用法?Python XMLWriter.element怎么用?Python XMLWriter.element使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类elementtree.SimpleXMLWriter.XMLWriter
的用法示例。
在下文中一共展示了XMLWriter.element方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: project_save1
# 需要导入模块: from elementtree.SimpleXMLWriter import XMLWriter [as 别名]
# 或者: from elementtree.SimpleXMLWriter.XMLWriter import element [as 别名]
def project_save1(tree):
f = open('resar.xml', 'w')
w = XMLWriter(f)
html = w.start("data")
w.element("empresa", '"' + tree.GetItemText(tree.GetRootItem(), 0) + '"')
w.start('items')
def printChildren(tree, treeItem):
subItem = tree.GetFirstChild(treeItem)[0]
name = tree.GetItemText(treeItem, 1)
index = tree.GetItemText(treeItem, 0)
try:
parent = tree.GetItemText(tree.GetItemParent(treeItem), 1)
except Exception:
parent = 'root'
if not subItem.IsOk():
w.element("item", nombre=name, indice=index, parent=parent)
else:
w.element("item", nombre=name, indice=index, parent='root')
while subItem.IsOk():
printChildren(tree, subItem)
subItem = tree.GetNextSibling(subItem)
printChildren(tree, tree.GetRootItem())
w.end('items')
w.close(html)
f.close()
示例2: installerLog
# 需要导入模块: from elementtree.SimpleXMLWriter import XMLWriter [as 别名]
# 或者: from elementtree.SimpleXMLWriter.XMLWriter import element [as 别名]
def installerLog(package_details):
'''
This module writes the required fields of a package to a temporary
XML file which is then appended to the list of installedLog.xml.
Right now - only name and version written to the installedLog.xml.
'''
#package_details contain all the info about the package
w = XMLWriter('tempholder.xml')
xml = w.start("xml")
w.start("Package")
w.element("name", package_details[0])
w.element("version", package_details[1])
#w.element("architecture", package_details[2])
#w.element("short-description",package_details[3])
#w.element("installed",package_details[4])
#w.element("long-description",package_details[4])
#-----^basic logging data above^------
#w.element("section",package_details[5])
#w.element("installed-size",package_details[6])
#w.element("maintainer",package_details[7])
#w.element("original-maintainer",package_details[8])
#w.element("replaces",package_details[9])
#w.element("provides",package_details[10])
#w.element("pre-depends",package_details[11])
#w.element("depends",package_details[5])
#w.element("recomends",package_details[13])
#w.element("suggests",package_details[14])
#w.element("conflicts",package_details[15])
#w.element("filename",package_details[16])
#w.element("size",package_details[17])
#w.element("md5sum",package_details[18])
#w.element("homepage",package_details[19])
w.end()
w.close(xml)
示例3: create_project
# 需要导入模块: from elementtree.SimpleXMLWriter import XMLWriter [as 别名]
# 或者: from elementtree.SimpleXMLWriter.XMLWriter import element [as 别名]
def create_project(name, path, template=None):
os.mkdir(path)
os.mkdir(os.path.join(path, 'bin'))
os.mkdir(os.path.join(path, 'contabilidad'))
os.mkdir(os.path.join(path, 'documentos'))
f = open(os.path.join(path, 'bin','empresa.xml'), 'w')
w = XMLWriter(f)
html = w.start("data")
w.element("empresa", '"' + name + '"')
w.start('items')
w.element('item', nombre=name, indice='', parent='root')
w.end('items')
w.close(html)
f.close()
示例4: tagcloudxml
# 需要导入模块: from elementtree.SimpleXMLWriter import XMLWriter [as 别名]
# 或者: from elementtree.SimpleXMLWriter.XMLWriter import element [as 别名]
def tagcloudxml(request):
xml = cStringIO.StringIO()
w = XMLWriter(xml)
tags = w.start("tags")
for tag in tagcloud():
w.element("a",
text=tag['tag'],
attrs={'href': "http://www.bhamtechevents.org/browse_events/%s".format(tag['tag']),
'title': "%s topics".format(tag["count"]), 'rel': "tag",
'style': "font-size: %s".format(tag["size"])}
)
w.end()
w.close(tags)
w.flush()
return HttpResponse(xml.read())
示例5: write_keymap
# 需要导入模块: from elementtree.SimpleXMLWriter import XMLWriter [as 别名]
# 或者: from elementtree.SimpleXMLWriter.XMLWriter import element [as 别名]
def write_keymap(keymap, filename):
contexts = list(set([ c for c,a,k in keymap ]))
actions = list(set([ a for c,a,k in keymap ]))
w = XMLWriter(filename, "utf-8")
doc = w.start("keymap")
for context in contexts:
w.start(context)
w.start("keyboard")
for c,a,k in keymap:
if c==context:
w.element("key", a, id=k)
w.end()
w.end()
w.end()
w.close(doc)
示例6: _record_key
# 需要导入模块: from elementtree.SimpleXMLWriter import XMLWriter [as 别名]
# 或者: from elementtree.SimpleXMLWriter.XMLWriter import element [as 别名]
def _record_key():
dialog = KeyListener()
dialog.doModal()
key = dialog.key
del dialog
w = XMLWriter(twitter_file, "utf-8")
doc = w.start("keymap")
w.start("global")
w.start("keyboard")
w.element("key", "addon.opensettings(script.service.twitter)", id=str(key))
w.end()
w.end()
w.start("fullscreenvideo")
w.start("keyboard")
w.element("key", "addon.opensettings(script.service.twitter)", id=str(key))
w.end()
w.end()
w.end()
w.close(doc)
示例7: intWriter
# 需要导入模块: from elementtree.SimpleXMLWriter import XMLWriter [as 别名]
# 或者: from elementtree.SimpleXMLWriter.XMLWriter import element [as 别名]
def intWriter(path, camMat, distCoe, calibError={}):
try:
print 'Generating Intrinsic Parameters to:', path, '...'
with open(path, 'w') as int_xml:
w = XMLWriter(int_xml)
w.declaration()
# Camera Intrinsic (Root)
root = w.start('StdIntrinsic')
# Camera Matrix
w.element('CamMat',
fx=str(camMat[0][0]), fy=str(camMat[1][1]),
cx=str(camMat[0][2]), cy=str(camMat[1][2]))
# Distortion Coefficients
if (len(distCoe[0]) == 8): # 8 coefficients Rational Model, k4 k5 k6 enabled
w.element('DistCoe', k1=str(distCoe[0][0]), k2=str(distCoe[0][1]),
p1=str(distCoe[0][2]), p2=str(distCoe[0][3]),
k3=str(distCoe[0][4]), k4=str(distCoe[0][5]),
k5=str(distCoe[0][6]), k6=str(distCoe[0][7]))
elif (len(distCoe[0]) == 12): # 12 coefficients Prism Model, c1, c2, c3, c4 enabled, new in OpenCV 3.0.0
w.element('DistCoe', k1=str(distCoe[0][0]), k2=str(distCoe[0][1]),
p1=str(distCoe[0][2]), p2=str(distCoe[0][3]),
k3=str(distCoe[0][4]), k4=str(distCoe[0][5]),
k5=str(distCoe[0][6]), k6=str(distCoe[0][7]),
c1=str(distCoe[0][8]), c2=str(distCoe[0][9]),
c3=str(distCoe[0][10]),c4=str(distCoe[0][11]))
else:
w.element('DistCoe', k1=str(distCoe[0][0]), k2=str(distCoe[0][1]),
p1=str(distCoe[0][2]), p2=str(distCoe[0][3]),
k3=str(distCoe[0][4]))
# Error values
if len(calibError) > 0:
w.element('Error', rms=str(calibError['rms']), total=str(calibError['tot_err']), arth=str(calibError['arth_err']))
w.close(root)
print 'Intrinsic calibration has been generated successfully.'
except Exception as e:
print 'ERROR: occurred in writing intrinsic XML file.'
raise e # keep it bubbling up, to catch in main()
示例8: to_xml
# 需要导入模块: from elementtree.SimpleXMLWriter import XMLWriter [as 别名]
# 或者: from elementtree.SimpleXMLWriter.XMLWriter import element [as 别名]
def to_xml(self):
from StringIO import StringIO
myxml = StringIO()
w = XMLWriter(myxml)
w.start(self._kind.lower(), name=self._label )
if self._m_title: w.element("title", self._m_title )
if self._m_subtitle: w.element("subtitle", self._m_subtitle )
if self._m_num: w.element("num", self._m_num )
if self._m_source: w.element("source", self._m_source )
self.to_xml_body(w)
w.end(self._kind.lower())
ret = myxml.getvalue()
myxml.close()
return ret
示例9: write_graph_xml
# 需要导入模块: from elementtree.SimpleXMLWriter import XMLWriter [as 别名]
# 或者: from elementtree.SimpleXMLWriter.XMLWriter import element [as 别名]
def write_graph_xml(graph, output_file='street_graph.xml'):
w = XMLWriter(output_file)
graph_e = w.start("graph")
# write nodes
w.start("nodes")
for n in graph:
w.element("node", id=str(n), lat=str(graph[n].lat), lon=str(graph[n].lng))
w.end()
# write arcs
w.start("arcs")
for n in graph:
w.start("node", id=str(n))
for arc in graph[n]:
w.element("arc", ref=str(arc), weight=str(graph[n][arc]))
#print arc, graph[n][arc]
w.end()
w.end()
w.close(graph_e)
示例10: main
# 需要导入模块: from elementtree.SimpleXMLWriter import XMLWriter [as 别名]
# 或者: from elementtree.SimpleXMLWriter.XMLWriter import element [as 别名]
def main():
fout_name = os.path.join(data_dir, "geo_coordinates.xml")
fout = open(fout_name, "w")
w = XMLWriter(fout)
w.start("root")
f_name = os.path.join(data_dir, "crime_geo_coordinates.txt")
with open(f_name) as f:
for line in f:
lat = str(line.split(",")[0])
lng = str(line.split(",")[1])
w.start('dataelement')
w.element('text', "")
w.start("geodata")
w.element("latitude", lat)
w.element("longitude", lng)
w.end("geodata")
w.end("dataelement")
w.end("root")
示例11: search
# 需要导入模块: from elementtree.SimpleXMLWriter import XMLWriter [as 别名]
# 或者: from elementtree.SimpleXMLWriter.XMLWriter import element [as 别名]
resp, content = client.request(url,method=http_method)
return content
def search():
URL = 'https://api.twitter.com/1.1/search/tweets.json?'
Count = '&count=100'
DCGeocode='&geocode=38.895,-77.036389,4.5mi'
URL = URL + Count + DCGeocode
return oauth_request(URL)
if __name__ == "__main__":
f = codecs.open('tweet_data.xml', mode = 'w')
w = XMLWriter(f)
dictionary = json.loads(search())
w.start('root')
for n in range(0,len(dictionary["statuses"])):
entry = dictionary["statuses"][n]
if(not(entry["geo"] == None)):
w.start('dataelement')
w.element('text', "Status: " + entry["text"].encode('ascii','ignore') + '\n')
w.start('geodata')
w.element('latitude',str(entry["geo"]["coordinates"][0]))
w.element('longitude',str(entry["geo"]["coordinates"][1]))
w.end('geodata')
w.end('dataelement')
w.end('root')
示例12: createMetadata
# 需要导入模块: from elementtree.SimpleXMLWriter import XMLWriter [as 别名]
# 或者: from elementtree.SimpleXMLWriter.XMLWriter import element [as 别名]
def createMetadata(item_ID):
# get number of files
images = os.listdir("/processing/"+item_ID+"/images")
leaf_count = len(images) - 1 #accounts for /thumbs directory in there
# get dimensions of cover and create cover image
cover_path = Template('/processing/$item_ID/images/$item_ID').substitute(item_ID=item_ID) + "00001.jpg"
im = Image.open(cover_path)
width, height = im.size #returns tuple
# generate cover thumbnail
max_cover_width = 200
max_cover_height = 200
im.thumbnail((max_cover_width, max_cover_height), Image.ANTIALIAS)
im.save(Template('/processing/$item_ID/$item_ID').substitute(item_ID=item_ID) + "_cover.jpg")
print "Cover created for",item_ID
# write to xml
fhand = Template("/processing/$item_ID/$item_ID$suffix.xml").substitute(item_ID=item_ID, suffix="_metadata")
w = XMLWriter(fhand, "utf-8")
metadata = w.start("add")
w.start("doc")
w.element("field", Template("meta:$item_ID").substitute(item_ID=item_ID), name="id")
w.element("field", Template("$item_ID").substitute(item_ID=item_ID), name="ItemID") #no underscore for solr index in "ItemID"
#creats overall ratio - height / width
w.element("field", str(height), name="pheight")
w.element("field", str(width), name="pwidth")
w.element("field", str(leaf_count), name="leafs")
w.element("field", Template("$item_ID").substitute(item_ID=item_ID), name="item_title") #how will we generate this? ItemID for now...
w.end() #closes <doc>
w.close(metadata)
示例13: main
# 需要导入模块: from elementtree.SimpleXMLWriter import XMLWriter [as 别名]
# 或者: from elementtree.SimpleXMLWriter.XMLWriter import element [as 别名]
#.........这里部分代码省略.........
elif key == Key.right:
params['status'] = Status.skip
elif key == Key.left:
params['status'] = Status.back
elif key == Key.backspace:
params['status'] = Status.remove
elif Key.char(key, '1') and cfg.dual_mode:
params['status'] = Status.still
lens = Theta.Left
elif Key.char(key, '2') and cfg.dual_mode:
params['status'] = Status.still
lens = Theta.Right
# catch exit status
if params['status'] == Status.stop:
print "\nprocess aborted!"
break
# write data
if params['status'] == Status.record \
and len(trainer_points[lens]) != max_clicks: # TODO: does this disable recording clicks on the last frame
if dataQuality == 0:
trainer_points[lens][in_vid.at()] = (params['pos'], in_csv.row()[2:5], in_csv.row()[8:10])
params['status'] = Status.skip
# or remove it
elif params['status'] == Status.remove \
and in_vid.at() in trainer_points[lens]:
del trainer_points[lens][in_vid.at()]
print "\nremoved dot"
# load next csv frame
if params['status'] == Status.skip:
if in_vid.next():
in_csv.next()
else:
write_xml = True
print "\nend of video: {}/{}".format(in_vid.at() -1, mark_out -1)
break
# or load previous csv frame
elif params['status'] == Status.back:
if in_vid.back():
in_csv.back()
# reset status
params['status'] = Status.wait
# clean up
cv2.destroyAllWindows()
## write xml
if write_xml:
out_xml = XMLWriter(args[3])
out_xml.declaration()
doc = out_xml.start("TrainingSet")
# source information
out_xml.start("video", mark_in=str(mark_in), mark_out=str(mark_out))
out_xml.data(os.path.basename(args[1]))
out_xml.end()
out_xml.element("csv", os.path.basename(args[2]))
# training point data
for lens in trainer_points:
if lens == Theta.Right:
out_xml.start("buttonside", points=str(len(trainer_points[lens])))
elif lens == Theta.Left:
out_xml.start("backside", points=str(len(trainer_points[lens])))
else: # non dualmode
out_xml.start("frames", points=str(len(trainer_points[lens])))
for i in trainer_points[lens]:
pos, row, markers = trainer_points[lens][i]
x, y = pos
out_xml.start("frame", num=str(i))
out_xml.element("plane",
x=str(x),
y=str(y))
out_xml.element("vicon",
x=str(row[0]), y=str(row[1]), z=str(row[2]))
out_xml.element("visibility",
visibleMax=str(markers[0]),
visible=str(markers[1]))
out_xml.end()
out_xml.end() # frames
# clean up
out_xml.close(doc)
print "Data was written."
else:
print "No data was written"
print "\nDone."
return 0
示例14: run1
# 需要导入模块: from elementtree.SimpleXMLWriter import XMLWriter [as 别名]
# 或者: from elementtree.SimpleXMLWriter.XMLWriter import element [as 别名]
def run1():
x = XMLWriter("test.xml")
musicLibrary = x.start("musciLibrary")
x.start("song")
x.element("id", "2")
x.element("title", "Jigga What/Faint")
x.element("artist", "Linkin Park/Jay Z")
x.element("year", "2004")
x.element("trackNumber", "3")
x.element("totalTracks", "6")
x.element("genre", "Rap/Nu Metal")
x.end("song")
x.close(musicLibrary)
示例15: __init__
# 需要导入模块: from elementtree.SimpleXMLWriter import XMLWriter [as 别名]
# 或者: from elementtree.SimpleXMLWriter.XMLWriter import element [as 别名]
class TaraxuDjangoWriter:
def __init__(self, filename, encoding="utf-8", x=XmlFormat):
self.xmlfile = open(filename, "w")
self.writer = XMLWriter(self.xmlfile, encoding)
self.x = x
self.doc = self.writer.start(self.x.HEAD)
def close(self):
self.writer.close(self.doc)
self.xmlfile.close()
def start_task(self, task):
# detect what type of task this is and remember it for encapsulated elements
self.ttype = type(task).__name__
# start task and remember it so that we can close
self.task = self.writer.start(
self.x.TASK[self.ttype], id=task.corpus.custom_id, sourcelanguage=task.corpus.language.name
)
def end_task(self, task):
self.writer.close(self.task)
def add_result(self, result):
label = self.x.ITEM[self.ttype]
# pythonic way to get to the particular type of the result
try:
result = result.rankingresult
except:
pass
else:
self.writer.start(
label,
id=result.item.source_sentence.custom_id.strip(),
duration=str(result.duration),
user=result.user.username,
)
ranks = _RankingRank.objects.filter(result=result)
self.writer.element(self.x.SOURCE, result.item.source_sentence.text)
for rank in ranks:
self.writer.element(
self.x.TRANSLATION,
rank.translation.text,
system=rank.translation.document.translateddocument.translation_system.name,
rank=str(rank.rank),
)
self.writer.end()
try:
result = result.selectandposteditresult
except:
pass
else:
self.writer.start(
label,
id=result.item.source_sentence.custom_id.strip(),
duration=str(result.duration),
user=result.user.username,
)
self.writer.element(self.x.SOURCE, result.item.source_sentence.text)
try:
translation = Translation.objects.get(
source_sentence=result.item.source_sentence,
document__translateddocument__translation_system=result.system,
)
self.writer.element(self.x.TRANSLATION, translation.text)
except:
pass
try:
self.writer.element(
self.x.POSTEDIT, result.sentence, system=result.system.name, fromscratch=str(result.fromScratch)
)
except:
self.writer.element(self.x.POSTEDIT, result.sentence, system="?", fromscratch=str(result.fromScratch))
self.writer.end()