本文整理匯總了Python中xml.dom.pulldom.PROCESSING_INSTRUCTION屬性的典型用法代碼示例。如果您正苦於以下問題:Python pulldom.PROCESSING_INSTRUCTION屬性的具體用法?Python pulldom.PROCESSING_INSTRUCTION怎麽用?Python pulldom.PROCESSING_INSTRUCTION使用的例子?那麽, 這裏精選的屬性代碼示例或許可以為您提供幫助。您也可以進一步了解該屬性所在類xml.dom.pulldom
的用法示例。
在下文中一共展示了pulldom.PROCESSING_INSTRUCTION屬性的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: testProcessingInstruction
# 需要導入模塊: from xml.dom import pulldom [as 別名]
# 或者: from xml.dom.pulldom import PROCESSING_INSTRUCTION [as 別名]
def testProcessingInstruction(self):
piText = []
for event, node in pulldom.parse(self.testFile):
if event == pulldom.PROCESSING_INSTRUCTION:
piText.append(node.data)
try:
result = u"".join(piText)
# Weird how the repr for PI data is different from text and char data.
# Still, the whole xml.dom.* and xml.sax.* hierarchy is rather a
# labyrinthine mess under jython, mostly because it's so old, and
# yet survived through major evolutionary changes in both jython and java.
self.failUnlessEqual(repr(result), r"u'ΛΜΝΞΟ'")
except Exception, x:
self.fail("Unexpected exception joining pi data pieces: %s" % str(x))
示例2: _test_thorough
# 需要導入模塊: from xml.dom import pulldom [as 別名]
# 或者: from xml.dom.pulldom import PROCESSING_INSTRUCTION [as 別名]
def _test_thorough(self, pd, before_root=True):
"""Test some of the hard-to-reach parts of the parser, using a mock
parser."""
evt, node = next(pd)
self.assertEqual(pulldom.START_DOCUMENT, evt)
# Just check the node is a Document:
self.assertTrue(hasattr(node, "createElement"))
if before_root:
evt, node = next(pd)
self.assertEqual(pulldom.COMMENT, evt)
self.assertEqual("a comment", node.data)
evt, node = next(pd)
self.assertEqual(pulldom.PROCESSING_INSTRUCTION, evt)
self.assertEqual("target", node.target)
self.assertEqual("data", node.data)
evt, node = next(pd)
self.assertEqual(pulldom.START_ELEMENT, evt)
self.assertEqual("html", node.tagName)
evt, node = next(pd)
self.assertEqual(pulldom.COMMENT, evt)
self.assertEqual("a comment", node.data)
evt, node = next(pd)
self.assertEqual(pulldom.PROCESSING_INSTRUCTION, evt)
self.assertEqual("target", node.target)
self.assertEqual("data", node.data)
evt, node = next(pd)
self.assertEqual(pulldom.START_ELEMENT, evt)
self.assertEqual("p", node.tagName)
evt, node = next(pd)
self.assertEqual(pulldom.CHARACTERS, evt)
self.assertEqual("text", node.data)
evt, node = next(pd)
self.assertEqual(pulldom.END_ELEMENT, evt)
self.assertEqual("p", node.tagName)
evt, node = next(pd)
self.assertEqual(pulldom.END_ELEMENT, evt)
self.assertEqual("html", node.tagName)
evt, node = next(pd)
self.assertEqual(pulldom.END_DOCUMENT, evt)