本文整理汇总了Python中elementtree.ElementTree.SubElement方法的典型用法代码示例。如果您正苦于以下问题:Python ElementTree.SubElement方法的具体用法?Python ElementTree.SubElement怎么用?Python ElementTree.SubElement使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类elementtree.ElementTree
的用法示例。
在下文中一共展示了ElementTree.SubElement方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: attach_page_style
# 需要导入模块: from elementtree import ElementTree [as 别名]
# 或者: from elementtree.ElementTree import SubElement [as 别名]
def attach_page_style(self, el):
"""Attach the default page style.
Create an automatic-style that refers to the current style
of this element and that refers to the default page style.
"""
current_style = el.get('text:style-name')
style_name = 'P1003'
el1 = SubElement(
self.automatic_styles, 'style:style', attrib={
'style:name': style_name,
'style:master-page-name': "rststyle-pagedefault",
'style:family': "paragraph",
}, nsdict=SNSD)
if current_style:
el1.set('style:parent-style-name', current_style)
el.set('text:style-name', style_name)
示例2: visit_enumerated_list
# 需要导入模块: from elementtree import ElementTree [as 别名]
# 或者: from elementtree.ElementTree import SubElement [as 别名]
def visit_enumerated_list(self, node):
el1 = self.current_element
if self.blockstyle == self.rststyle('blockquote'):
el2 = SubElement(el1, 'text:list', attrib={
'text:style-name': self.rststyle('blockquote-enumlist'),
})
self.list_style_stack.append(self.rststyle('blockquote-enumitem'))
elif self.blockstyle == self.rststyle('highlights'):
el2 = SubElement(el1, 'text:list', attrib={
'text:style-name': self.rststyle('highlights-enumlist'),
})
self.list_style_stack.append(self.rststyle('highlights-enumitem'))
elif self.blockstyle == self.rststyle('epigraph'):
el2 = SubElement(el1, 'text:list', attrib={
'text:style-name': self.rststyle('epigraph-enumlist'),
})
self.list_style_stack.append(self.rststyle('epigraph-enumitem'))
else:
liststylename = 'enumlist-%s' % (node.get('enumtype', 'arabic'), )
el2 = SubElement(el1, 'text:list', attrib={
'text:style-name': self.rststyle(liststylename),
})
self.list_style_stack.append(self.rststyle('enumitem'))
self.set_current_element(el2)
示例3: visit_inline
# 需要导入模块: from elementtree import ElementTree [as 别名]
# 或者: from elementtree.ElementTree import SubElement [as 别名]
def visit_inline(self, node):
styles = node.attributes.get('classes', ())
if styles:
el = self.current_element
for inline_style in styles:
el = SubElement(el, 'text:span',
attrib={'text:style-name':
self.rststyle(inline_style)})
count = len(styles)
else:
# No style was specified so use a default style (old code
# crashed if no style was given)
el = SubElement(self.current_element, 'text:span')
count = 1
self.set_current_element(el)
self.inline_style_count_stack.append(count)
示例4: visit_colspec
# 需要导入模块: from elementtree import ElementTree [as 别名]
# 或者: from elementtree.ElementTree import SubElement [as 别名]
def visit_colspec(self, node):
self.column_count += 1
colspec_name = self.rststyle(
'%s%%d.%%s' % TABLESTYLEPREFIX,
(self.table_count, chr(self.column_count), )
)
colwidth = node['colwidth'] / 12.0
el1 = SubElement(self.automatic_styles, 'style:style', attrib={
'style:name': colspec_name,
'style:family': 'table-column',
}, nsdict=SNSD)
el1_1 = SubElement(el1, 'style:table-column-properties', attrib={
'style:column-width': '%.4fin' % colwidth
},
nsdict=SNSD)
el2 = self.append_child('table:table-column', attrib={
'table:style-name': colspec_name,
})
self.table_width += colwidth
示例5: attach_page_style
# 需要导入模块: from elementtree import ElementTree [as 别名]
# 或者: from elementtree.ElementTree import SubElement [as 别名]
def attach_page_style(self, el):
"""Attach the default page style.
Create an automatic-style that refers to the current style
of this element and that refers to the default page style.
"""
current_style = el.get('text:style-name')
style_name = 'P1003'
el1 = SubElement(
self.automatic_styles, 'style:style', attrib={
'style:name': style_name,
'style:master-page-name': "rststyle-pagedefault",
'style:family': "paragraph",
}, nsdict=SNSD)
if current_style:
el1.set('style:parent-style-name', current_style)
el.set('text:style-name', style_name)
示例6: generate_admonition
# 需要导入模块: from elementtree import ElementTree [as 别名]
# 或者: from elementtree.ElementTree import SubElement [as 别名]
def generate_admonition(self, node, label, title=None):
if hasattr(self.language, 'labels'):
translated_label = self.language.labels[label]
else:
translated_label = label
el1 = SubElement(self.current_element, 'text:p', attrib={
'text:style-name': self.rststyle(
'admon-%s-hdr', (label, )),
})
if title:
el1.text = title
else:
el1.text = '%s!' % (translated_label.capitalize(), )
s1 = self.rststyle('admon-%s-body', (label, ))
self.paragraph_style_stack.append(s1)
#
# Roles (e.g. subscript, superscript, strong, ...
#
示例7: addGraphonesToLexicon
# 需要导入模块: from elementtree import ElementTree [as 别名]
# 或者: from elementtree.ElementTree import SubElement [as 别名]
def addGraphonesToLexicon(xml, graphones):
lexicon = xml.getroot()
for letters, phonemes in graphones:
lemma = SubElement(lexicon, 'lemma')
lemma.text = '\n '
orth = SubElement(lemma, 'orth')
orth.text = '_' + ''.join(letters) + '_'
orth.tail = '\n '
phon = SubElement(lemma, 'phon')
phon.text = ' '.join(phonemes)
phon.tail = '\n '
synt = SubElement(lemma, 'synt')
SubElement(synt, 'tok').text = lmToken(letters, phonemes)
synt.tail = '\n'
# synt.tail = '\n '
# eval = SubElement(lemma, 'eval')
# SubElement(eval, 'tok').text = '[UNKNOWN]'
# eval.tail = '\n'
lemma.tail = '\n'
示例8: changeSyntaticToPhonetic
# 需要导入模块: from elementtree import ElementTree [as 别名]
# 或者: from elementtree.ElementTree import SubElement [as 别名]
def changeSyntaticToPhonetic(xml):
lexicon = xml.getroot()
for lemma in lexicon.getiterator('lemma'):
if lemma.get('special'): continue
phon = lemma.find('phon')
if phon is not None:
phon = phon.text.split()
phon.append('#1')
synt = lemma.find('synt')
if synt is None:
synt = SubElement(lemma, 'synt')
else:
synt.clear()
synt.tail = '\n '
if phon:
for ph in phon:
SubElement(synt, 'tok').text = ph
# ===========================================================================
示例9: SubElement
# 需要导入模块: from elementtree import ElementTree [as 别名]
# 或者: from elementtree.ElementTree import SubElement [as 别名]
def SubElement(parent, tag, attrib=None, nsmap=None, nsdict=CNSD):
if attrib is None:
attrib = {}
tag, attrib = fix_ns(tag, attrib, nsdict)
if WhichElementTree == 'lxml':
el = etree.SubElement(parent, tag, attrib, nsmap=nsmap)
else:
el = _ElementInterfaceWrapper(tag, attrib)
parent.append(el)
el.setparent(parent)
return el
示例10: create_manifest
# 需要导入模块: from elementtree import ElementTree [as 别名]
# 或者: from elementtree.ElementTree import SubElement [as 别名]
def create_manifest(self):
if WhichElementTree == 'lxml':
root = Element('manifest:manifest',
nsmap=MANIFEST_NAMESPACE_DICT,
nsdict=MANIFEST_NAMESPACE_DICT,
)
else:
root = Element('manifest:manifest',
attrib=MANIFEST_NAMESPACE_ATTRIB,
nsdict=MANIFEST_NAMESPACE_DICT,
)
doc = etree.ElementTree(root)
SubElement(root, 'manifest:file-entry', attrib={
'manifest:media-type': self.MIME_TYPE,
'manifest:full-path': '/',
}, nsdict=MANNSD)
SubElement(root, 'manifest:file-entry', attrib={
'manifest:media-type': 'text/xml',
'manifest:full-path': 'content.xml',
}, nsdict=MANNSD)
SubElement(root, 'manifest:file-entry', attrib={
'manifest:media-type': 'text/xml',
'manifest:full-path': 'styles.xml',
}, nsdict=MANNSD)
SubElement(root, 'manifest:file-entry', attrib={
'manifest:media-type': 'text/xml',
'manifest:full-path': 'settings.xml',
}, nsdict=MANNSD)
SubElement(root, 'manifest:file-entry', attrib={
'manifest:media-type': 'text/xml',
'manifest:full-path': 'meta.xml',
}, nsdict=MANNSD)
s1 = ToString(doc)
doc = minidom.parseString(s1)
s1 = doc.toprettyxml(' ')
return s1
示例11: generate_content_element
# 需要导入模块: from elementtree import ElementTree [as 别名]
# 或者: from elementtree.ElementTree import SubElement [as 别名]
def generate_content_element(self, root):
return SubElement(root, 'office:text')
示例12: create_custom_headfoot
# 需要导入模块: from elementtree import ElementTree [as 别名]
# 或者: from elementtree.ElementTree import SubElement [as 别名]
def create_custom_headfoot(self, parent, text, style_name, automatic_styles):
parent = SubElement(parent, 'text:p', attrib={
'text:style-name': self.rststyle(style_name),
})
current_element = None
field_iter = self.split_field_specifiers_iter(text)
for item in field_iter:
if item[0] == ODFTranslator.code_field:
if item[1] not in ('p', 'P',
't1', 't2', 't3', 't4',
'd1', 'd2', 'd3', 'd4', 'd5',
's', 't', 'a'):
msg = 'bad field spec: %%%s%%' % (item[1], )
raise RuntimeError(msg)
el1 = self.make_field_element(parent,
item[1], style_name, automatic_styles)
if el1 is None:
msg = 'bad field spec: %%%s%%' % (item[1], )
raise RuntimeError(msg)
else:
current_element = el1
else:
if current_element is None:
parent.text = item[1]
else:
current_element.tail = item[1]
示例13: append_child
# 需要导入模块: from elementtree import ElementTree [as 别名]
# 或者: from elementtree.ElementTree import SubElement [as 别名]
def append_child(self, tag, attrib=None, parent=None):
if parent is None:
parent = self.current_element
if attrib is None:
el = SubElement(parent, tag)
else:
el = SubElement(parent, tag, attrib)
return el
示例14: append_pending_ids
# 需要导入模块: from elementtree import ElementTree [as 别名]
# 或者: from elementtree.ElementTree import SubElement [as 别名]
def append_pending_ids(self, el):
if self.settings.create_links:
for id in self.pending_ids:
SubElement(el, 'text:reference-mark', attrib={
'text:name': id})
self.pending_ids = [ ]
示例15: generate_labeled_block
# 需要导入模块: from elementtree import ElementTree [as 别名]
# 或者: from elementtree.ElementTree import SubElement [as 别名]
def generate_labeled_block(self, node, label):
label = '%s:' % (self.language.labels[label], )
el = self.append_p('textbody')
el1 = SubElement(el, 'text:span',
attrib={'text:style-name': self.rststyle('strong')})
el1.text = label
el = self.append_p('blockindent')
return el