本文整理汇总了Python中xml.dom.toxml方法的典型用法代码示例。如果您正苦于以下问题:Python dom.toxml方法的具体用法?Python dom.toxml怎么用?Python dom.toxml使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类xml.dom
的用法示例。
在下文中一共展示了dom.toxml方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: testEmptyXMLNSValue
# 需要导入模块: from xml import dom [as 别名]
# 或者: from xml.dom import toxml [as 别名]
def testEmptyXMLNSValue(self):
doc = parseString("<element xmlns=''>\n"
"<foo/>\n</element>")
doc2 = parseString(doc.toxml())
self.confirm(doc2.namespaceURI == xml.dom.EMPTY_NAMESPACE)
示例2: testAAA
# 需要导入模块: from xml import dom [as 别名]
# 或者: from xml.dom import toxml [as 别名]
def testAAA(self):
dom = parseString("<abc/>")
el = dom.documentElement
el.setAttribute("spam", "jam2")
self.confirm(el.toxml() == '<abc spam="jam2"/>', "testAAA")
a = el.getAttributeNode("spam")
self.confirm(a.ownerDocument is dom,
"setAttribute() sets ownerDocument")
self.confirm(a.ownerElement is dom.documentElement,
"setAttribute() sets ownerElement")
dom.unlink()
示例3: testAAB
# 需要导入模块: from xml import dom [as 别名]
# 或者: from xml.dom import toxml [as 别名]
def testAAB(self):
dom = parseString("<abc/>")
el = dom.documentElement
el.setAttribute("spam", "jam")
el.setAttribute("spam", "jam2")
self.confirm(el.toxml() == '<abc spam="jam2"/>', "testAAB")
dom.unlink()
示例4: testWriteXML
# 需要导入模块: from xml import dom [as 别名]
# 或者: from xml.dom import toxml [as 别名]
def testWriteXML(self):
str = '<?xml version="1.0" ?><a b="c"/>'
dom = parseString(str)
domstr = dom.toxml()
dom.unlink()
self.confirm(str == domstr)
示例5: test_toprettyxml_preserves_content_of_text_node
# 需要导入模块: from xml import dom [as 别名]
# 或者: from xml.dom import toxml [as 别名]
def test_toprettyxml_preserves_content_of_text_node(self):
# see issue #4147
for str in ('<B>A</B>', '<A><B>C</B></A>'):
dom = parseString(str)
dom2 = parseString(dom.toprettyxml())
self.assertEqual(
dom.getElementsByTagName('B')[0].childNodes[0].toxml(),
dom2.getElementsByTagName('B')[0].childNodes[0].toxml())
示例6: testCloneElementDeep
# 需要导入模块: from xml import dom [as 别名]
# 或者: from xml.dom import toxml [as 别名]
def testCloneElementDeep(self):
dom, clone = self._setupCloneElement(1)
self.confirm(len(clone.childNodes) == 1
and clone.childNodes.length == 1
and clone.parentNode is None
and clone.toxml() == '<doc attr="value"><foo/></doc>'
, "testCloneElementDeep")
dom.unlink()
示例7: testEncodings
# 需要导入模块: from xml import dom [as 别名]
# 或者: from xml.dom import toxml [as 别名]
def testEncodings(self):
doc = parseString('<foo>€</foo>')
self.confirm(doc.toxml() == u'<?xml version="1.0" ?><foo>\u20ac</foo>'
and doc.toxml('utf-8') ==
'<?xml version="1.0" encoding="utf-8"?><foo>\xe2\x82\xac</foo>'
and doc.toxml('iso-8859-15') ==
'<?xml version="1.0" encoding="iso-8859-15"?><foo>\xa4</foo>',
"testEncodings - encoding EURO SIGN")
# Verify that character decoding errors raise exceptions instead
# of crashing
self.assertRaises(UnicodeDecodeError, parseString,
'<fran\xe7ais>Comment \xe7a va ? Tr\xe8s bien ?</fran\xe7ais>')
doc.unlink()
示例8: testSerializeCommentNodeWithDoubleHyphen
# 需要导入模块: from xml import dom [as 别名]
# 或者: from xml.dom import toxml [as 别名]
def testSerializeCommentNodeWithDoubleHyphen(self):
doc = create_doc_without_doctype()
doc.appendChild(doc.createComment("foo--bar"))
self.assertRaises(ValueError, doc.toxml)