mirror of
https://github.com/wxWidgets/Phoenix.git
synced 2026-01-08 04:50:07 +01:00
Add prettifyNode tool function
This commit is contained in:
@@ -1541,6 +1541,7 @@ def flattenNode(node, rstrip=True):
|
||||
Extract just the text from a node and its children, tossing out any child
|
||||
node tags and attributes.
|
||||
"""
|
||||
# TODO: can we just use ElementTree.tostring for this function?
|
||||
if node is None:
|
||||
return ""
|
||||
if sys.version_info < (3,):
|
||||
@@ -1561,6 +1562,18 @@ def flattenNode(node, rstrip=True):
|
||||
return text
|
||||
|
||||
|
||||
def prettifyNode(elem):
|
||||
"""
|
||||
Return a pretty-printed XML string for the Element. Useful for debugging
|
||||
or better understanding of xml trees.
|
||||
"""
|
||||
from xml.etree import ElementTree
|
||||
from xml.dom import minidom
|
||||
rough_string = ElementTree.tostring(elem, 'utf-8')
|
||||
reparsed = minidom.parseString(rough_string)
|
||||
return reparsed.toprettyxml(indent=" ")
|
||||
|
||||
|
||||
def appendText(node, text):
|
||||
"""
|
||||
Append some text to a docstring element, such as an item's briefDoc or
|
||||
@@ -1584,6 +1597,7 @@ def prependText(node, text):
|
||||
node.insert(0, ele)
|
||||
|
||||
|
||||
|
||||
def makeTextElement(text):
|
||||
element = et.Element('para')
|
||||
element.text = text
|
||||
|
||||
Reference in New Issue
Block a user