本文整理汇总了Python中xml.dom.minidom.Document.toprettyxml方法的典型用法代码示例。如果您正苦于以下问题:Python Document.toprettyxml方法的具体用法?Python Document.toprettyxml怎么用?Python Document.toprettyxml使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类xml.dom.minidom.Document
的用法示例。
在下文中一共展示了Document.toprettyxml方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: main
# 需要导入模块: from xml.dom.minidom import Document [as 别名]
# 或者: from xml.dom.minidom.Document import toprettyxml [as 别名]
def main():
# Create the minidom document
doc=Document()
# Create the <wml> base element
svg = doc.createElement("svg")
svg.setAttribute('version', '1.1')
svg.setAttribute('baseProfile', 'full')
svg.setAttribute('xmlns', 'http://www.w3.org/2000/svg')
svg.setAttribute('xmlns:xlink', 'http://www.w3.org/1999/xlink')
svg.setAttribute('xmlns:ev', 'http://www.w3.org/2001/xml-events')
svg.setAttribute('height', '400px')
svg.setAttribute('width', '400px')
doc.appendChild(svg)
rect = doc.createElement('rect')
rect.setAttribute( 'x', '0' )
rect.setAttribute( 'y', '0' )
rect.setAttribute( 'width', '200' )
rect.setAttribute( 'height', '200' )
rect.setAttribute( 'fill', 'none' )
rect.setAttribute( 'stroke', 'black' )
rect.setAttribute( 'stroke-width', '5px' )
rect.setAttribute( 'stroke-opacity', '0.5' )
svg.appendChild( rect )
print doc.toprettyxml(indent=" ")
示例2: test_handle_repr_set
# 需要导入模块: from xml.dom.minidom import Document [as 别名]
# 或者: from xml.dom.minidom.Document import toprettyxml [as 别名]
def test_handle_repr_set(self):
''' '''
emotionml = Document()
repset_name = 'dimension-set'
repset = Representation(name='fear', representation='dimension')
emotionml = handle_repr_set(repset_name, repset, emotionml)
print emotionml.toprettyxml()
示例3: createXMLFile
# 需要导入模块: from xml.dom.minidom import Document [as 别名]
# 或者: from xml.dom.minidom.Document import toprettyxml [as 别名]
def createXMLFile():
# Create the minidom document
doc = Document()
# Create the <top> base element
top = doc.createElement("top")
doc.appendChild(top)
detectorSet = doc.createElement("t1_detector_set")
detectorSet.setAttribute("id", "1")
top.appendChild(detectorSet)
for (arm, planes) in deadChannelsMap.items(): #for every arm add arm tag and its childs
armElement = doc.createElement("t1_arm")
armElement.setAttribute("id", arm)
for (plane, chambers) in planes.items(): #for every plane add plane tag
planeElement = doc.createElement("t1_plane")
planeElement.setAttribute("id", plane)
for (chamber, channelTypes) in chambers.items(): #for every chamber add chamber tag
chamberElement = doc.createElement("t1_csc")
chamberElement.setAttribute("id", chamber)
for (channelType, channels) in channelTypes.items(): #for every channelType add plane tag
channelTypeElement = doc.createElement("t1_channel_type")
channelTypeElement.setAttribute("id", channelType)
channelTypeElement.setAttribute("fullmask", "no")
for (channel, trash) in channels.items(): #for every channel write tag
channelElement = doc.createElement("channel");
channelElement.setAttribute("id", channel)
channelTypeElement.appendChild(channelElement)
chamberElement.appendChild(channelTypeElement)
planeElement.appendChild(chamberElement)
armElement.appendChild(planeElement)
detectorSet.appendChild(armElement)
print doc.toprettyxml(indent=" ") #print XML document in readable way
示例4: writeDocument
# 需要导入模块: from xml.dom.minidom import Document [as 别名]
# 或者: from xml.dom.minidom.Document import toprettyxml [as 别名]
def writeDocument(files,outputFileName):
xmlDoc = Document()
root = xmlDoc.createElement('GizintaPlaylist')
xmlDoc.appendChild(root)
root.setAttribute("logTableName",'gzLog')
root.setAttribute("errorTableName",'gzError')
root.setAttribute("fileExtension",'.dwg')
root.setAttribute("xmlns:gizinta",'http://gizinta.com')
for fname in files:
fElem = xmlDoc.createElement("File")
root.appendChild(fElem)
nodeText = xmlDoc.createTextNode(fname)
fElem.appendChild(nodeText)
try:
xmlStr = xmlDoc.toprettyxml()
uglyXml = xmlDoc.toprettyxml(indent=' ')
text_re = re.compile('>\n\s+([^<>\s].*?)\n\s+</', re.DOTALL)
prettyXml = text_re.sub('>\g<1></', uglyXml)
fHandle = open(outputFileName, 'w')
fHandle.write(prettyXml)
fHandle.close()
except:
gzSupport.showTraceback()
xmlStr =""
return xmlStr
示例5: dict2xml
# 需要导入模块: from xml.dom.minidom import Document [as 别名]
# 或者: from xml.dom.minidom.Document import toprettyxml [as 别名]
class dict2xml(object):
def __init__(self, structure):
self.doc = Document()
if len(structure) == 1:
rootName = unicode(structure.keys()[0])
self.root = self.doc.createElement(rootName)
self.doc.appendChild(self.root)
self.build(self.root, structure[rootName])
def build(self, father, structure):
if type(structure) == dict:
for k in structure:
tag = self.doc.createElement(k)
father.appendChild(tag)
self.build(tag, structure[k])
elif type(structure) == list:
grandFather = father.parentNode
tagName = father.tagName
grandFather.removeChild(father)
for l in structure:
tag = self.doc.createElement(tagName)
self.build(tag, l)
grandFather.appendChild(tag)
else:
data = structure
tag = self.doc.createTextNode(data)
father.appendChild(tag)
def display(self):
print self.doc.toprettyxml(indent=" ")
示例6: BuildXMl
# 需要导入模块: from xml.dom.minidom import Document [as 别名]
# 或者: from xml.dom.minidom.Document import toprettyxml [as 别名]
def BuildXMl(url):
xbmc.executebuiltin("XBMC.Notification(Please Wait!,Refreshing Movie List,5000)")
link = GetContent(url)
newlink = ''.join(link.splitlines()).replace('\t','')
newlink=newlink[newlink.find('<b>Scroll Down To View Full Movie List</b>'):len(newlink)]
mydoc=Document()
mlist = mydoc.createElement("movielist")
mydoc.appendChild(mlist)
match=re.compile('<strong>(.+?)</strong><br /><img src="(.+?)" width="75" height="75" align="center" />').findall(newlink)
maxcountry = len(match)
for i in range(maxcountry):
(vCountry,vImg)=match[i]
xCountry= mydoc.createElement("country")
mlist.appendChild(xCountry)
xCountry.setAttribute("thumb", vImg)
xCountry.setAttribute("name", vCountry)
startlen = newlink.find('<strong>'+vCountry+'</strong><br /><img')
endlen = 0
if(i < maxcountry-1):
(vCountry2,vImg2)=match[i+1]
endlen=newlink.find('<strong>'+vCountry2+'</strong><br /><img')
else:
endlen = len(newlink)
ParseXML(startlen,endlen,newlink, mydoc,xCountry)
print mydoc.toprettyxml()
f = open(filename, 'w');f.write(mydoc.toprettyxml());f.close()
示例7: __repr__
# 需要导入模块: from xml.dom.minidom import Document [as 别名]
# 或者: from xml.dom.minidom.Document import toprettyxml [as 别名]
def __repr__(self):
if (self.menu_id == None):
xml = Document()
xml_menu = xml.createElement("menu")
x_no_menu = xml.createTextNode("No menu Loaded")
xml_menu.appendChild(x_no_menu)
xml.appendChild(xml_menu)
return xml.toprettyxml(indent=" ")
else :
xml = Document()
xml_menu = xml.createElement("menu")
xml.appendChild(xml_menu)
xml_menu_id = xml.createElement("id")
x_menu_id = xml.createTextNode(str(self.menu_id))
xml_menu_id.appendChild(x_menu_id)
xml_menu.appendChild(xml_menu_id)
xml_menu_name = xml.createElement("name")
x_menu_name = xml.createTextNode(str(self.menu_name))
xml_menu_name.appendChild(x_menu_name)
xml_menu.appendChild(xml_menu_name)
return xml.toprettyxml(indent=" ")
示例8: createfilexml
# 需要导入模块: from xml.dom.minidom import Document [as 别名]
# 或者: from xml.dom.minidom.Document import toprettyxml [as 别名]
def createfilexml(self):
global Mpath,Magent
homep=Mpath
if not os.path.isdir(homep+"/xssalertdefault"):
os.mkdir(homep+"/xssalertdefault")
f1=open(homep+"/xssalertdefault/payload.xml","w")
f2=open(homep+"/xssalertdefault/header.xml","w")
f3=open(homep+"/xssalertdefault/url.xml","w")
dom1=Document()
x=dom1.createElement("xssalert")
dom1.appendChild(x)
i=0
while i < 2:
xa=dom1.createElement("xssalertvector")
x.appendChild(xa)
vr=dom1.createElement("vector")
xa.appendChild(vr)
testvr=dom1.createCDATASection("??")
vr.appendChild(testvr)
i=i+1
f1.write(dom1.toprettyxml(" "))
dom2=Document()
y=dom2.createElement("xssalert")
dom2.appendChild(y)
i=0
while i<2:
xb=dom2.createElement("xssalertheader")
y.appendChild(xb)
hr=dom2.createElement("header")
xb.appendChild(hr)
testhr=dom2.createCDATASection("??")
hr.appendChild(testhr)
i=i+1
f2.write(dom2.toprettyxml(" "))
dom3=Document()
z=dom3.createElement("xssalert")
dom3.appendChild(z)
i=0
while i<2:
xc=dom3.createElement("xssalerturl")
z.appendChild(xc)
ur=dom3.createElement("url")
xc.appendChild(ur)
testhr=dom3.createCDATASection("??")
ur.appendChild(testhr)
i=i+1
f3.write(dom3.toprettyxml(" "))
f1.close()
f2.close()
f3.close()
self.file_create_alert.setText("Default directory with XML files Created in '"+homep+"' \n Replace '??' with your text")
示例9: test_add_section_to_xml
# 需要导入模块: from xml.dom.minidom import Document [as 别名]
# 或者: from xml.dom.minidom.Document import toprettyxml [as 别名]
def test_add_section_to_xml(self):
xml = Document()
toolbox = xml.createElement('toolbox')
xml.appendChild(toolbox)
add_section_to_xml("Section 1", ['script1.py', 'script2.py'], xml)
self.assertEqual(xml.toprettyxml(indent='\t'), exp_add_sect)
add_section_to_xml("Section 2", [], xml)
self.assertEqual(xml.toprettyxml(indent='\t'), exp_add_void_sect)
示例10: ancientOne
# 需要导入模块: from xml.dom.minidom import Document [as 别名]
# 或者: from xml.dom.minidom.Document import toprettyxml [as 别名]
def ancientOne(self):
""""
This will save all the Ancient One's xml data.
"""
doc = Document()
#create the root level element
root = doc.createElement("ancientone")
#create first level elements (sube elements to root element)
name = doc.createElement("name")
title = doc.createElement("title")
combatRating = doc.createElement("combatrating")
doomTrack = doc.createElement("doomtrack")
worshipers = doc.createElement("worshipers")
defence = doc.createElement("defence")
power = doc.createElement("power")
attack = doc.createElement("attack")
#create second level elements. Will attack to first level elements.
worshipersDescription = doc.createElement("description")
worshipersType = doc.createElement("type")
worshipersMods = doc.createElement("mods")
powerName = doc.createElement("name")
powerDescription = doc.createElement("description")
#time to put the basic structure together
doc.appendChild(root)
root.appendChild(name)
root.appendChild(title)
root.appendChild(combatRating)
root.appendChild(doomTrack)
root.appendChild(worshipers)
root.appendChild(defence)
root.appendChild(power)
root.appendChild(attack)
worshipers.appendChild(worshipersDescription)
worshipers.appendChild(worshipersMods)
worshipers.appendChild(worshipersType)
power.appendChild(powerName)
power.appendChild(powerDescription)
#now that the structure is all there, we need to get the values.
nameTxt = doc.createTextNode(str(self.txtAncientOneName.displayText()))
titleTxt = doc.createTextNode(str(self.txtAncientOneTitle.displayText()))
combatRatingTxt = doc.createTextNode(str(self.txtAncientOneCombatRating.displayText()))
name.appendChild(nameTxt)
print doc.toprettyxml(indent=" ")
示例11: dict2xml
# 需要导入模块: from xml.dom.minidom import Document [as 别名]
# 或者: from xml.dom.minidom.Document import toprettyxml [as 别名]
class dict2xml(object):
def __init__(self, structure):
if len(structure) == 1:
self.doc = Document()
rootName = str(structure.keys()[0])
self.root = self.doc.createElement(rootName)
self.doc.appendChild(self.root)
self.build(self.root, structure[rootName])
def build(self, father, structure):
if type(structure) == dict:
for k in structure:
if "/" in k:
tag = self.doc.createElement("location")
tag.setAttribute("path", k)
father.appendChild(tag)
self.build(tag, structure[k])
else:
tag = self.doc.createElement(k)
father.appendChild(tag)
self.build(tag, structure[k])
elif type(structure) == list:
grandFather = father.parentNode
tagName = father.tagName
grandFather.removeChild(father)
for l in structure:
#tag = self.doc.createElement(tagName)
self.build(father, l)
grandFather.appendChild(father)
elif isinstance(structure, MovieInfo):
tag = self.doc.createElement("movie")
tag.setAttribute("name", structure.name)
tag.setAttribute("path", structure.path)
tag.setAttribute("type", str(structure.type))
tag.setAttribute("flags", str(structure.flags))
father.appendChild(tag)
else:
data = str(structure)
tag = self.doc.createTextNode(data)
father.appendChild(tag)
def display(self):
print self.doc.toprettyxml(indent=" ")
def write(self, file_name):
try:
xmlstr = self.doc.toprettyxml() #self.doc.toxml('utf-8')
f = open(file_name, 'w')
f.write(xmlstr)
f.close()
except:
printStackTrace()
示例12: generate_reports
# 需要导入模块: from xml.dom.minidom import Document [as 别名]
# 或者: from xml.dom.minidom.Document import toprettyxml [as 别名]
def generate_reports(self, test_runner):
"""
Generates the XML reports to a given XMLTestRunner object.
"""
from xml.dom.minidom import Document
all_results = self._get_info_by_testcase()
outputHandledAsString = \
isinstance(test_runner.output, six.string_types)
if (outputHandledAsString and not os.path.exists(test_runner.output)):
os.makedirs(test_runner.output)
if not outputHandledAsString:
doc = Document()
testsuite = doc.createElement('testsuites')
doc.appendChild(testsuite)
parentElement = testsuite
for suite, tests in all_results.items():
if outputHandledAsString:
doc = Document()
parentElement = doc
suite_name = suite
if test_runner.outsuffix:
# not checking with 'is not None', empty means no suffix.
suite_name = '%s-%s' % (suite, test_runner.outsuffix)
# Build the XML file
testsuite = _XMLTestResult._report_testsuite(
suite_name, tests, doc, parentElement, self.properties
)
if outputHandledAsString:
xml_content = doc.toprettyxml(
indent='\t',
encoding=test_runner.encoding
)
filename = path.join(
test_runner.output,
'TEST-%s.xml' % suite_name)
with open(filename, 'wb') as report_file:
report_file.write(xml_content)
if self.showAll:
self.stream.writeln('Generated XML report: {}'.format(filename))
if not outputHandledAsString:
# Assume that test_runner.output is a stream
xml_content = doc.toprettyxml(
indent='\t',
encoding=test_runner.encoding
)
test_runner.output.write(xml_content)
示例13: test_update_tool_conf_xml
# 需要导入模块: from xml.dom.minidom import Document [as 别名]
# 或者: from xml.dom.minidom.Document import toprettyxml [as 别名]
def test_update_tool_conf_xml(self):
xml = Document()
toolbox = xml.createElement('toolbox')
xml.appendChild(toolbox)
section_dict = {"Section 1": ['script1.py', 'script2.py'],
"Section 2": ['script3.py']}
update_tool_conf_xml(xml, section_dict)
self.assertEqual(xml.toprettyxml(indent='\t'), exp_update_1)
section_dict["Section 3"] = ['script4.py', 'script5.py']
update_tool_conf_xml(xml, section_dict)
self.assertEqual(xml.toprettyxml(indent='\t'), exp_update_2)
示例14: calendar_to_xml
# 需要导入模块: from xml.dom.minidom import Document [as 别名]
# 或者: from xml.dom.minidom.Document import toprettyxml [as 别名]
def calendar_to_xml(xml_dir, calendar_list):
_adel_log.log("############ XML OUTPUT GENERATION -> CALENDAR ENTRIES ############ \n", 2)
# Create the minidom document
doc = Document()
xml = doc.createElement("Calendar_Entries")
doc.appendChild(xml)
for i in range(0, len(calendar_list)):
# Create the <Calendar_Entry> element
calendar_entry = doc.createElement("Calendar_Entry")
xml.appendChild(calendar_entry)
id = doc.createElement("id")
calendar_entry.appendChild(id)
id_text = doc.createTextNode(calendar_list[i][0])
id.appendChild(id_text)
calendarName = doc.createElement("calendarName")
calendar_entry.appendChild(calendarName)
calendarName_text = doc.createTextNode(calendar_list[i][1])
calendarName.appendChild(calendarName_text)
title = doc.createElement("title")
calendar_entry.appendChild(title)
title_text = doc.createTextNode(calendar_list[i][2])
title.appendChild(title_text)
eventLocation = doc.createElement("eventLocation")
calendar_entry.appendChild(eventLocation)
event_location_text = doc.createTextNode(calendar_list[i][3])
eventLocation.appendChild(event_location_text)
description = doc.createElement("description")
calendar_entry.appendChild(description)
description_text = doc.createTextNode(calendar_list[i][4])
description.appendChild(description_text)
all_day = doc.createElement("all_day")
calendar_entry.appendChild(all_day)
allDay_text = doc.createTextNode(calendar_list[i][5])
all_day.appendChild(allDay_text)
start = doc.createElement("start")
calendar_entry.appendChild(start)
start_text = doc.createTextNode(calendar_list[i][6])
start.appendChild(start_text)
end = doc.createElement("end")
calendar_entry.appendChild(end)
end_text = doc.createTextNode(calendar_list[i][7])
end.appendChild(end_text)
has_alarm = doc.createElement("has_alarm")
calendar_entry.appendChild(has_alarm)
has_alarm_text = doc.createTextNode(calendar_list[i][8])
has_alarm.appendChild(has_alarm_text)
# Print our newly created XML files to Log
_adel_log.log(make_pretty_xml(doc.toprettyxml(indent=" ", encoding="UTF-8")), 3)
# create xml file
xml_calendar = open(xml_dir + "/calendar.xml", "a+")
xml_calendar.write(make_pretty_xml(doc.toprettyxml(indent=" ", encoding="UTF-8")))
xml_calendar.close()
_adel_log.log("xmlParser: ----> calendar.xml created!", 4)
示例15: sms_messages_to_xml
# 需要导入模块: from xml.dom.minidom import Document [as 别名]
# 或者: from xml.dom.minidom.Document import toprettyxml [as 别名]
def sms_messages_to_xml(xml_dir, sms_list):
_adel_log.log("############ XML OUTPUT GENERATION -> SMS MESSAGES ############ \n", 2)
# Create the minidom document
doc = Document()
xml = doc.createElement("SMS_Messages")
doc.appendChild(xml)
for i in range(0, len(sms_list)):
# Create the <SMS_Message> element
sms_message = doc.createElement("SMS_Message")
xml.appendChild(sms_message)
id = doc.createElement("id")
sms_message.appendChild(id)
id_text = doc.createTextNode(sms_list[i][0])
id.appendChild(id_text)
thread_id = doc.createElement("thread_id")
sms_message.appendChild(thread_id)
thread_id_text = doc.createTextNode(sms_list[i][1])
thread_id.appendChild(thread_id_text)
number = doc.createElement("number")
sms_message.appendChild(number)
number_text = doc.createTextNode(sms_list[i][2])
number.appendChild(number_text)
person = doc.createElement("person")
sms_message.appendChild(person)
person_text = doc.createTextNode(sms_list[i][3])
person.appendChild(person_text)
date = doc.createElement("date")
sms_message.appendChild(date)
date_text = doc.createTextNode(sms_list[i][4])
date.appendChild(date_text)
read = doc.createElement("read")
sms_message.appendChild(read)
read_text = doc.createTextNode(sms_list[i][5])
read.appendChild(read_text)
type = doc.createElement("type")
sms_message.appendChild(type)
type_text = doc.createTextNode(sms_list[i][6])
type.appendChild(type_text)
subject = doc.createElement("subject")
sms_message.appendChild(subject)
subject_text = doc.createTextNode(sms_list[i][7])
subject.appendChild(subject_text)
body = doc.createElement("body")
sms_message.appendChild(body)
body_text = doc.createTextNode(sms_list[i][8])
body.appendChild(body_text)
# Print our newly created XML files to Log
_adel_log.log(make_pretty_xml(doc.toprettyxml(indent=" ", encoding="UTF-8")), 3)
# create xml file
xml_sms_messages = open(xml_dir + "/sms_Messages.xml", "a+")
xml_sms_messages.write(make_pretty_xml(doc.toprettyxml(indent=" ", encoding="UTF-8")))
xml_sms_messages.close()
_adel_log.log("xmlParser: ----> sms_Messages.xml created!", 4)