本文整理汇总了Python中xml.dom.minidom.Element.toxml方法的典型用法代码示例。如果您正苦于以下问题:Python Element.toxml方法的具体用法?Python Element.toxml怎么用?Python Element.toxml使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类xml.dom.minidom.Element
的用法示例。
在下文中一共展示了Element.toxml方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_insertPrevNextText
# 需要导入模块: from xml.dom.minidom import Element [as 别名]
# 或者: from xml.dom.minidom.Element import toxml [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 toxml [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: xml_encode
# 需要导入模块: from xml.dom.minidom import Element [as 别名]
# 或者: from xml.dom.minidom.Element import toxml [as 别名]
def xml_encode(self, text):
from xml.dom.minidom import Text, Element
t = Text()
t.data = text
e = Element('x')
e.appendChild(t)
return e.toxml()[3:-4]
示例4: fetch
# 需要导入模块: from xml.dom.minidom import Element [as 别名]
# 或者: from xml.dom.minidom.Element import toxml [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
示例5: _thread_run
# 需要导入模块: from xml.dom.minidom import Element [as 别名]
# 或者: from xml.dom.minidom.Element import toxml [as 别名]
def _thread_run(self):
logging.debug('started Thread')
self._counter = 0
while self._start:
#print ('started Thread')
#print self._sensor_channel
self._data = self._adc.readADCSingleEnded(0, gain, sps)/1000
#print self._data
if self._data > 2:
#print self._sensor_channel
self._counter = self._counter+1
#print self._counter
element = Element('PeopleCounter')
element.setAttribute('Record','%d' % self._counter)
element.setAttribute('Time','%f' % time.time())
element.setAttribute('DateTime','%s' % time.strftime('%c'))
self.output_directory.write("\r\n")
self.output_directory.write(element.toxml())
logging.debug(element.toxml())
sleep(5)
pass
pass
示例6: render_GET
# 需要导入模块: from xml.dom.minidom import Element [as 别名]
# 或者: from xml.dom.minidom.Element import toxml [as 别名]
def render_GET(self, request):
"""
Render as HTML a listing of all known users with links to their
personal resources.
"""
listing = Element('ul')
for link, text in self._users():
linkElement = Element('a')
linkElement.setAttribute('href', link + '/')
textNode = Text()
textNode.data = text
linkElement.appendChild(textNode)
item = Element('li')
item.appendChild(linkElement)
listing.appendChild(item)
return self.template % {'users': listing.toxml()}
示例7: render
# 需要导入模块: from xml.dom.minidom import Element [as 别名]
# 或者: from xml.dom.minidom.Element import toxml [as 别名]
def render(self, request):
"""
Render as HTML a listing of all known users with links to their
personal resources.
"""
listing = Element("ul")
for link, text in self._users():
linkElement = Element("a")
linkElement.setAttribute("href", link + "/")
textNode = Text()
textNode.data = text
linkElement.appendChild(textNode)
item = Element("li")
item.appendChild(linkElement)
listing.appendChild(item)
return self.template % {"users": listing.toxml()}
示例8: tokenize
# 需要导入模块: from xml.dom.minidom import Element [as 别名]
# 或者: from xml.dom.minidom.Element import toxml [as 别名]
if node.localName == "add":
# set type attribute to start and add node as a child to output
node.setAttribute("type","start")
open_elements.peek().appendChild(node)
else:
open_elements.peek().appendChild(node)
open_elements.push(node)
elif event == END_ELEMENT:
# skip rdg element
if node.localName == "rdg":
continue
# in case of add deal with overlapping hierarchies
if node.localName == "add":
# create a clone of the node and set type attribute to end and add node as a child to output
clone = node.cloneNode(False)
clone.setAttribute("type","end")
open_elements.peek().appendChild(clone)
else:
open_elements.pop()
elif event == CHARACTERS:
tokens = tokenize(node.data)
if tokens:
textdata = "\n".join(tokens)
else:
textdata = re.sub("[^\S\n]+", "", node.data)
t = Text()
t.data = textdata
open_elements.peek().appendChild(t)
print(output.toxml())