本文整理汇总了Python中xml.dom.minidom.Element.setAttribute方法的典型用法代码示例。如果您正苦于以下问题:Python Element.setAttribute方法的具体用法?Python Element.setAttribute怎么用?Python Element.setAttribute使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类xml.dom.minidom.Element
的用法示例。
在下文中一共展示了Element.setAttribute方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_insertPrevNextText
# 需要导入模块: from xml.dom.minidom import Element [as 别名]
# 或者: from xml.dom.minidom.Element import setAttribute [as 别名]
def test_insertPrevNextText(self):
"""
L{insertPrevNextLinks} appends a text node with the title of the
previous slide to each node with a I{previous} class and the title of
the next slide to each node with a I{next} class.
"""
next = Element('span')
next.setAttribute('class', 'next')
container = Element('div')
container.appendChild(next)
slideWithNext = HTMLSlide(container, 'first', 0)
previous = Element('span')
previous.setAttribute('class', 'previous')
container = Element('div')
container.appendChild(previous)
slideWithPrevious = HTMLSlide(container, 'second', 1)
insertPrevNextLinks(
[slideWithNext, slideWithPrevious], None, None)
self.assertEqual(
next.toxml(), '<span class="next">second</span>')
self.assertEqual(
previous.toxml(), '<span class="previous">first</span>')
示例2: test_insertImages
# 需要导入模块: from xml.dom.minidom import Element [as 别名]
# 或者: from xml.dom.minidom.Element import setAttribute [as 别名]
def test_insertImages(self):
"""
L{formulaeToImages} replaces any elements with the I{latexformula}
class with I{img} elements which refer to external images generated
based on the latex in the original elements.
"""
parent = Element('div')
base = FilePath(self.mktemp())
base.makedirs()
macros = Element('span')
macros.setAttribute('class', 'latexmacros')
text = Text()
text.data = 'foo'
macros.appendChild(text)
parent.appendChild(macros)
formula = Element('span')
formula.setAttribute('class', 'latexformula')
text = Text()
text.data = 'bar'
formula.appendChild(text)
parent.appendChild(formula)
# Avoid actually executing the commands to generate images from the
# latex. It might be nice to have some assertions about what commands
# are executed, or perhaps even execute them and make sure an image
# file is created, but that is a task for another day.
commands = []
formulaeToImages(parent, base.path, _system=commands.append)
self.assertEqual(
parent.toxml(),
'<div><span><br/><img src="latexformula0.png"/><br/></span></div>')
示例3: _add_lang_to_html
# 需要导入模块: from xml.dom.minidom import Element [as 别名]
# 或者: from xml.dom.minidom.Element import setAttribute [as 别名]
def _add_lang_to_html(htmltext, lang):
'''
Take a piece of HTML and add an xml:lang attribute to it.
'''
if lang == 'und':
return htmltext
parser = html5lib.HTMLParser(
tree=html5lib.treebuilders.getTreeBuilder("dom")
)
html = parser.parseFragment(htmltext)
html.normalize()
if len(html.childNodes) == 0:
return '<div xml:lang="%s"></div>' % lang
elif len(html.childNodes) == 1:
node = html.firstChild
if node.nodeType == Node.TEXT_NODE:
div = Element('div')
div.ownerDocument = html
div.setAttribute('xml:lang', lang)
div.childNodes = [node]
html.childNodes = [div]
else:
node.setAttribute('xml:lang', lang)
else:
#add a single encompassing div
div = Element('div')
div.ownerDocument = html
div.setAttribute('xml:lang', lang)
div.childNodes = html.childNodes
html.childNodes = [div]
return html.toxml()
示例4: get_file_entry
# 需要导入模块: from xml.dom.minidom import Element [as 别名]
# 或者: from xml.dom.minidom.Element import setAttribute [as 别名]
def get_file_entry(resource,clip_len,properties):
resource_base_name = str(os.path.basename(resource))
fn = resource_base_name.split(".")[0]
o_file = Element("file")
o_file.setAttribute("id", fn)
if not used_files.has_key(resource_base_name):
used_files[resource_base_name]=resource
# here add info of file
# o_file.appendChild(create_simple_element("name", clip_resource_basename))
o_file.appendChild(create_simple_element("name", resource_base_name))
o_pathurl=create_simple_element("pathurl", resource)
o_file.appendChild(o_pathurl)
o_rate=Element("rate")
o_rate.appendChild(create_simple_element("timebase", "25"))
o_file.appendChild(o_rate)
o_file.appendChild(create_simple_element("duration", str(clip_len)))
o_file_media = Element("media")
video_index=get_property(properties, "video_index")
if int(video_index)>=0:
o_file_media_video = Element("video")
o_file_media_video.appendChild(create_simple_element("duration", str(clip_len)))
o_file_media.appendChild(o_file_media_video)
num_audio_channels=producer_get_audio_channels_from_properties(properties)
if int(num_audio_channels)>0:
o_file_media_audio = Element("audio")
[sample_rate, depth] = get_audio_params_from_properties(properties)
o_samplecharacteristics = Element("samplecharacteristics")
o_samplecharacteristics.appendChild(create_simple_element("samplerate", str(sample_rate)))
o_samplecharacteristics.appendChild(create_simple_element("depth", str(depth)))
o_file_media_audio.appendChild(o_samplecharacteristics)
o_file_media_audio_channelcount = create_simple_element("channelcount", num_audio_channels)
o_file_media_audio.appendChild(o_file_media_audio_channelcount)
o_file_media.appendChild(o_file_media_audio)
o_file.appendChild(o_file_media)
return o_file
示例5: set_scripts
# 需要导入模块: from xml.dom.minidom import Element [as 别名]
# 或者: from xml.dom.minidom.Element import setAttribute [as 别名]
def set_scripts(self):
self.scripts = [x.script for x in self.traitscripts.scripts(self.name)]
while self.scripts_element.hasChildNodes():
del self.scripts_element.childNodes[0]
for script in self.scripts:
element = Element('script')
element.setAttribute('name', script)
self.scripts_element.appendChild(element)
示例6: node2xml
# 需要导入模块: from xml.dom.minidom import Element [as 别名]
# 或者: from xml.dom.minidom.Element import setAttribute [as 别名]
def node2xml(node):
"""Takes in a node object and returns an XML object for that node"""
ele = Element("node")
for k, v in node.attrs.items():
ele.setAttribute(k, v)
for k, v in node.tags.items():
ele.appendChild(tag2xml(k, v))
return ele
示例7: _getElementForMappingEntry
# 需要导入模块: from xml.dom.minidom import Element [as 别名]
# 或者: from xml.dom.minidom.Element import setAttribute [as 别名]
def _getElementForMappingEntry(entry, mappingStyle):
e = Element(mappingStyle)
for k, v in entry.items():
# ignore empty, None or compiled regexp items into output
if not v or (k == "path-match-expr"):
continue
e.setAttribute(k, str(v))
return e
示例8: fetch
# 需要导入模块: from xml.dom.minidom import Element [as 别名]
# 或者: from xml.dom.minidom.Element import setAttribute [as 别名]
def fetch(self, output_directory='none'):
element = Element('Water_meter001')
element.setAttribute('Meter_Reading','%f' % self._data)
self.output_directory.write("\r\n")
self.output_directory.write(element.toxml())
#element.toxml()
pass
示例9: to_dom
# 需要导入模块: from xml.dom.minidom import Element [as 别名]
# 或者: from xml.dom.minidom.Element import setAttribute [as 别名]
def to_dom(self):
root_node = Element("root", namespaceURI=NAMESPACE)
root_node.setAttribute("str", self.str)
root_node.setAttribute("lemma", self.lemma)
root_node.setAttribute("lemma_root", self.lemma_root)
root_node.setAttribute("syntactic_category", self.syntactic_category)
if self.secondary_syntactic_category:
root_node.setAttribute("secondary_syntactic_category", self.secondary_syntactic_category)
return root_node
示例10: fetch
# 需要导入模块: from xml.dom.minidom import Element [as 别名]
# 或者: from xml.dom.minidom.Element import setAttribute [as 别名]
def fetch(self, output_directory):
'''
The output_directory parameter is ignored.
'''
formatted_datetime = self._captured_datetime.strftime(self._format)
element = Element('DateTime')
element.setAttribute('CurrentDateTime', formatted_datetime)
return element
示例11: way2xml
# 需要导入模块: from xml.dom.minidom import Element [as 别名]
# 或者: from xml.dom.minidom.Element import setAttribute [as 别名]
def way2xml(way):
ele = Element('way')
for k,v in way.attrs.items():
ele.setAttribute(k,v)
for ref in way.nodes:
nd = Element('nd')
nd.setAtrribute('ref', ref)
ele.appendChild(nd)
for k,v in way.tags.items():
ele.appendChild(tags2xml(k,v))
return ele
示例12: relation2xml
# 需要导入模块: from xml.dom.minidom import Element [as 别名]
# 或者: from xml.dom.minidom.Element import setAttribute [as 别名]
def relation2xml(relation):
ele = Element("relation")
for k, v in relation.attrs.items():
ele.setAttribute(k, v)
for member in relation.members:
ele = Element("member")
for k, v in member.items():
ele.setAttribute(k, v)
for k, v in relation.tags.items():
ele.appendChild(tag2xml(k, v))
return ele
示例13: way2xml
# 需要导入模块: from xml.dom.minidom import Element [as 别名]
# 或者: from xml.dom.minidom.Element import setAttribute [as 别名]
def way2xml(way):
ele = Element("way")
for k, v in way.attrs.items():
ele.setAttribute(k, v)
for ref in way.nodes:
nd = Element("nd")
nd.setAttribute("ref", ref)
ele.appendChild(nd)
for k, v in way.tags.items():
ele.appendChild(tag2xml(k, v))
return ele
示例14: test_anchorRef
# 需要导入模块: from xml.dom.minidom import Element [as 别名]
# 或者: from xml.dom.minidom.Element import setAttribute [as 别名]
def test_anchorRef(self):
"""
L{LatexSpitter.visitNode} emits a footnote when it encounters an I{a}
element with an I{href} attribute with a network scheme.
"""
listing = Element('a')
listing.setAttribute('href', 'http://example.com/foo')
self.spitter.visitNode(listing)
self.assertEqual(
''.join(self.output),
"\\footnote{http://example.com/foo}")
示例15: __init__
# 需要导入模块: from xml.dom.minidom import Element [as 别名]
# 或者: from xml.dom.minidom.Element import setAttribute [as 别名]
def __init__(self, conn, suite):
Element.__init__(self, 'traits')
self.conn = conn
self.suite = suite
self.setAttribute('suite', self.suite)
self._traits_ = StatementCursor(self.conn, 'Traits')
self._traits_.set_table(ujoin(self.suite, 'traits'))
self.traitnames = [row.trait for row in self._traits_.select(order='trait')]
for t in self.traitnames:
t_element = Element('trait')
t_element.setAttribute('name', t)
self.appendChild(t_element)