本文整理汇总了Python中xml.dom.minidom.Document类的典型用法代码示例。如果您正苦于以下问题:Python Document类的具体用法?Python Document怎么用?Python Document使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Document类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: _render
def _render(self, result):
document = Document()
testsuite = document.createElement('testsuite')
testsuite.setAttribute('name', 'avocado')
testsuite.setAttribute('tests', self._escape_attr(result.tests_total))
testsuite.setAttribute('errors', self._escape_attr(result.errors + result.interrupted))
testsuite.setAttribute('failures', self._escape_attr(result.failed))
testsuite.setAttribute('skipped', self._escape_attr(result.skipped + result.cancelled))
testsuite.setAttribute('time', self._escape_attr(result.tests_total_time))
testsuite.setAttribute('timestamp', self._escape_attr(datetime.datetime.now()))
document.appendChild(testsuite)
for test in result.tests:
testcase = self._create_testcase_element(document, test)
status = test.get('status', 'ERROR')
if status in ('PASS', 'WARN'):
pass
elif status == 'SKIP':
testcase.appendChild(Element('skipped'))
elif status == 'FAIL':
element, system_out = self._create_failure_or_error(document,
test,
'failure')
testcase.appendChild(element)
testcase.appendChild(system_out)
elif status == 'CANCEL':
testcase.appendChild(Element('skipped'))
else:
element, system_out = self._create_failure_or_error(document,
test,
'error')
testcase.appendChild(element)
testcase.appendChild(system_out)
testsuite.appendChild(testcase)
return document.toprettyxml(encoding='UTF-8')
开发者ID:EIChaoYang,项目名称:avocado,代码行数:34,代码来源:xunit.py
示例2: send_server_status
def send_server_status(self, status):
doc = Document()
rootNode = doc.createElement('server')
rootNode.setAttribute("status", status)
doc.appendChild(rootNode)
response = self.send_packet("/server/status", doc)
if response is False:
Logger.warn("SMRequest::send_server_status Unable to send packet")
return False
document = self.get_response_xml(response)
if document is None:
Logger.warn("SMRequest::send_server_status response not XML")
return False
rootNode = document.documentElement
if rootNode.nodeName != "server":
Logger.error("SMRequest::send_server_status response not valid %s"%(rootNode.toxml()))
return False
if not rootNode.hasAttribute("name") or rootNode.getAttribute("name") != self.name:
Logger.error("SMRequest::send_server_status response invalid name")
return False
if not rootNode.hasAttribute("status") or rootNode.getAttribute("status") != status:
Logger.error("SMRequest::send_server_status response invalid status")
return False
return True
开发者ID:bloveing,项目名称:openulteo,代码行数:30,代码来源:SMRequestManager.py
示例3: storeToFile
def storeToFile(self, suffix=""):
if not self.dataToStore:
return
doc = Document()
results = doc.createElement("results")
doc.appendChild(results)
for a in self.dataToStore:
item = doc.createElement("item")
for k, d in a.items():
tag = doc.createElement(k)
if k == "author":
tag2 = doc.createElement("name")
data = doc.createTextNode(d)
tag2.appendChild(data)
tag.appendChild(tag2)
else:
data = doc.createTextNode(" ".join(d.split()))
tag.appendChild(data)
item.appendChild(tag)
results.appendChild(item)
timestamp = time.strftime("%H%M%S_")
f = open("output/" + timestamp + self.board + "_" + self.section + "_" + str(suffix) + ".xml", "w")
f.write(doc.toprettyxml(indent=" ", encoding="utf-8"))
f.close()
self.dataToStore = []
开发者ID:xjerab13,项目名称:M-Eco-WP3-package,代码行数:27,代码来源:netdoktor.py
示例4: testTaxes3
def testTaxes3(self):
doc = Document()
parent_node = doc.createElement('parent_node')
doc.appendChild(parent_node)
data = {
'default-tax-table': {
'tax-rules': [
{
'shipping-taxed': False,
'rate': 0.08375,
'tax-area': {
'us-zip-area': ['100*'],
}
},
{
'shipping-taxed': True,
'rate': 0.04,
'tax-area': {
'us-state-area': ['NY'],
}
}
]
}
}
self.gc._taxes(doc, parent_node, data)
xml1 = "<parent_node><tax-tables><default-tax-table>\
<tax-rules><default-tax-rule><shipping-taxed>false</shipping-taxed>\
<rate>0.08375</rate><tax-area><us-zip-area><zip-pattern>100*</zip-pattern>\
</us-zip-area></tax-area></default-tax-rule>\
<default-tax-rule><shipping-taxed>true</shipping-taxed>\
<rate>0.04</rate><tax-area><us-state-area><state>NY</state></us-state-area>\
</tax-area></default-tax-rule>\
</tax-rules></default-tax-table></tax-tables></parent_node>"
doc_good = parseString(xml1)
self.assertEquals(doc.toxml(), doc_good.toxml())
开发者ID:aldarund,项目名称:merchant,代码行数:35,代码来源:google_checkout_tests.py
示例5: testShippingExclude
def testShippingExclude(self):
doc = Document()
parent_node = doc.createElement('parent_node')
doc.appendChild(parent_node)
data = {
'us-state-area': ['AK','HI'],
'us-zip-area': ['90210', '04005', '04092'],
'us-country-area': 'CONTINENTAL_48',
'world-area': True,
'postal-area': [{
'country-code': 'US',
'postal-code-pattern': ['94043', '90211'],
},
],
}
self.gc._shipping_allowed_excluded(doc, parent_node, data)
xml1 = "<parent_node><us-state-area><state>AK</state></us-state-area>\
<us-state-area><state>HI</state></us-state-area>\
<us-zip-area><zip-pattern>90210</zip-pattern></us-zip-area>\
<us-zip-area><zip-pattern>04005</zip-pattern></us-zip-area>\
<us-zip-area><zip-pattern>04092</zip-pattern></us-zip-area>\
<us-country-area country-area='CONTINENTAL_48'/>\
<world-area/>\
<postal-area><country-code>US</country-code>\
<postal-code-pattern>94043</postal-code-pattern>\
<postal-code-pattern>90211</postal-code-pattern></postal-area>\
</parent_node>"
doc_good = parseString(xml1)
self.assertEquals(doc.toxml(), doc_good.toxml())
开发者ID:aldarund,项目名称:merchant,代码行数:29,代码来源:google_checkout_tests.py
示例6: consoleElement
def consoleElement(deviceType, port):
"""
Creates a character device element, a <console> element, as a child
of L{device element<devicesElement>}, that specifies the console character
device to be used. Examples from libvirt.org:
Domain Logfile: This disables all input on the character device, and
sends output into the virtual machine's logfile.
- type: stdio
- port: 1
@param deviceType: device type
@type deviceType: String
@param port: port number
@type port: String
@return: <console> element
@rtype: String
"""
document = Document()
deviceElem = document.createElement('console')
deviceElem.setAttribute('type', deviceType)
portElem = document.createElement('target')
portElem.setAttribute('port', port)
deviceElem.appendChild(portElem)
return deviceElem
开发者ID:Awingu,项目名称:open-ovf,代码行数:27,代码来源:OvfLibvirt.py
示例7: questions_to_aiml
def questions_to_aiml(questions):
punctuation = "\"`[email protected]#$%^&()-_=+[{]}\|;:',<.>/?"
_puncStripRE = re.compile("[" + re.escape(punctuation) + "]")
# Create the minidom document
doc = Document()
# Create the <aiml> base element
aiml = doc.createElement("aiml")
doc.appendChild(aiml)
for question, answer in questions:
patterns = (re.sub(_puncStripRE, "", question), re.sub(_puncStripRE, "*", question))
for p in patterns:
category = doc.createElement("category")
pattern = doc.createElement("pattern")
pattern.appendChild(doc.createTextNode(p.upper()))
template = doc.createElement("template")
template.appendChild(doc.createTextNode(answer))
category.appendChild(pattern)
category.appendChild(template)
aiml.appendChild(category)
# Print our newly created XML
return doc.toxml()
开发者ID:jordanorc,项目名称:iaae,代码行数:30,代码来源:converter.py
示例8: test_handle_repr_set
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()
开发者ID:ebegoli,项目名称:EMLPy,代码行数:7,代码来源:testeml.py
示例9: createDoc
def createDoc(path):
file = open(path, "w")
doc = Document()
wml = doc.createElement("data")
doc.appendChild(wml)
file.write(doc.toprettyxml(indent=" "))
file.close()
开发者ID:ubuntunux,项目名称:Blender,代码行数:7,代码来源:__init__.py
示例10: __init__
def __init__(self, mlist, addPic, featurelist):
#def __init__(self, mlist):
Document.__init__(self)
self.mlist=mlist
self.addPic=addPic
self.featurelist=featurelist
self.generateXML()
开发者ID:hycsam,项目名称:GUI-Test-Automation-by-Image-Recognition,代码行数:7,代码来源:realXMLGenerator.py
示例11: __init__
def __init__(self, data=None):
Document.__init__(self)
if data is not None:
self.__dict__ = parseString(data).__dict__
self.annotations = { }
开发者ID:ComputerNetworks-UFRGS,项目名称:ManP2P-ng,代码行数:7,代码来源:message.py
示例12: read
class pythonbits_config:
"""Class for holding pythonbits config strings. read() or create_dom() must be called before first use. Access strings through obj.strings[key]"""
def __init__(self):
self.strings={}
self.file=tempdir()+"config.xml"
if not os.path.exists(self.file):
update_url = "https://github.com/Ichabond/Pythonbits/raw/master/config.xml"
opener = _MyOpener()
nconf = opener.open(update_url)
if (nconf.info()["Status"]=="200 OK"):
open(tempdir()+"config.xml", "w").write(nconf.read())
else:
__logerror("Cannot update config file.")
def __del__(self):
self.file.close()
def read(self, file=0):
if(file==0):
file=self.file
self.xml = parse(file)
self.load_strings()
def write(self, file=0):
if(file==0):
file=self.file
location = self.file.name
file.close()
file = open(location, "w")
file.write(self.xml.toprettyxml())
file.close()
self.file = open(location, "r")
def set_location(self, location):
try:
self.file = open(location, "r")
except IOError:
self.file = open(location, "w")
def load_strings(self):
for node in self.xml.getElementsByTagName("string"):
self.strings[node.getAttribute("name")]=node.firstChild.data.replace('\n','').replace('\t','')
def add_string(self, name, data):
container = self.xml.getElementsByTagName("pythonbits")[0]
stringtag = self.xml.createElement("string")
stringtag.setAttribute("name", name)
stringtag.appendChild(self.xml.createTextNode(data))
container.appendChild(stringtag)
self.load_strings()
def del_string(self, name):
del self.strings[name]
###Horrible hack. Write real code.
self.create_dom()
for (name, entry) in self.strings.items():
self.add_string(name, entry)
def create_dom(self):
self.xml = Document()
self.xml.appendChild(self.xml.createElement("pythonbits"))
开发者ID:kylev,项目名称:Pythonbits,代码行数:60,代码来源:pythonbits.py
示例13: exportXacroRobot
def exportXacroRobot(robot):
global output
global name
doc = Document()
root = doc.createElement("robot")
doc.appendChild(root)
root.setAttribute("xmlns:xacro","http://www.ros.org/wiki/xacro")
root.setAttribute("name",robot.name)
if name == 'nao':
root.appendChild(ur.short(doc,'xacro:include','filename',output[output.rfind('/')+1:output.find('.')]+ 'Transmission.xacro'))
root.appendChild(ur.short(doc,'xacro:include','filename',output[output.rfind('/')+1:output.find('.')]+ 'Gazebo.xacro'))
root.appendChild(ur.short(doc,'xacro:include','filename',output[output.rfind('/')+1:output.find('.')]+ 'hands.xacro'))
includeVisualCollision(robot)
for i in dicXacro.keys():
print "exporting " +str(dicXacro[i]) + ' xacro'
exportXacroRobotChain(robot,i)
if output.find('/') != -1:
filenamerobot = output[output.rfind('/')+1:output.find('.')]+ i + '.xacro'
else :
filenamerobot = output[0:output.find('.')]+ i + str('.xacro')
root.appendChild(ur.short(doc,'xacro:include','filename',filenamerobot))
## Transmission elements not available from Aldebaran libraries yet
# exportXacroRobotElementList(robot,'Transmission')
## Plugin not implemented yet : neither mimic joints, camera or ros_control
# exportXacroRobotElementList(robot,'Gazebo')
root.appendChild(ur.short(doc,'xacro:include','filename',output[output.rfind('/')+1:output.find('.')]+ 'sensors.xacro'))
exportSensorsXacro(robot,output[output.rfind('/')+1:output.find('.')]+ 'sensors.xacro')
root.appendChild(ur.short(doc,'xacro:include','filename',output[output.rfind('/')+1:output.find('.')]+ 'visual_collisions.xacro'))
filename = output[0:output.find('.')]+ 'robot' + str('.xacro')
print filename
writeCommentedXacro(doc,filename)
开发者ID:cottsay,项目名称:romeo_robot,代码行数:32,代码来源:generate_urdf.py
示例14: exportXacroRobotElementList
def exportXacroRobotElementList(robot,element):
global output
doc = Document()
root = doc.createElement("robot")
doc.appendChild(root)
root.setAttribute("xmlns:xacro","http://www.ros.org/wiki/xacro")
print 'create element file'
for i in robot.elements:
try:
if element == 'Transmission':
if i.name.find(element) != -1:
root.appendChild(i.to_xml(doc))
elif element == 'Gazebo':
if i.reference != None:
root.appendChild(i.to_xml(doc))
elif i.plugins != []:
root.appendChild(i.to_xml(doc))
elif element == 'material':
if type(i) == romeo_description.urdf.Material:
root.appendChild(i.to_xml(doc))
except AttributeError:
pass
filename = output[0:output.find('.')]+ str(element) + '.xacro'
print filename
writeCommentedXacro(doc, filename)
开发者ID:cottsay,项目名称:romeo_robot,代码行数:25,代码来源:generate_urdf.py
示例15: devicesElement
def devicesElement(*devices):
"""
Creates a <devices> element, a child of L{domain element
<domainElement>}, is the parent element for all devices.
Devices:
========
-L{<Emulator<emulatorElement>}
-L{<Disk<diskElement>}
-L{<Network<networkElement>}
-L{<Input<inputElement>}
-L{<Graphics<graphicsElement>}
@param devices: tuple of Libvirt devices
@type devices: DOM Element tuple
@return: <devices> element
@rtype: DOM Element
"""
document = Document()
deviceElem = document.createElement('devices')
addDevice(deviceElem, devices)
return deviceElem
开发者ID:Awingu,项目名称:open-ovf,代码行数:25,代码来源:OvfLibvirt.py
示例16: do_call_exit
def do_call_exit(self):
if d.sessionProperties["persistent"]:
mode = "suspend"
else:
mode = "logout"
document = Document()
rootNode = document.createElement("logout")
rootNode.setAttribute("mode", mode)
document.appendChild(rootNode)
url = "%s/logout.php" % (self.base_url)
request = urllib2.Request(url)
request.add_header("Content-type", "text/xml; charset=UTF-8")
request.add_data(document.toxml())
try:
url = self.urlOpener.open(request)
except urllib2.HTTPError, exc:
if exc.code == 500:
Logger.warn("Service failurek")
return False
Logger.debug("HTTP request return code %d (%s)" % (exc.code, exc.msg))
Logger.debug(" * return: %s" % (str(exc.read())))
return False
开发者ID:skdong,项目名称:nfs-ovd,代码行数:27,代码来源:ovd-client.py
示例17: graphicsElement
def graphicsElement(graphicsType, listen=None, port=None):
"""
Creates a <graphics> element, a child of L{device element<devicesElement>},
that specifies the graphics framebuffer device, either on the host or
through a VNC server.
@param graphicsType: frame buffer type: sdl or vnc
@type graphicsType: String
@param listen: IP address for VNC server
@type listen: String
@param port: port for VNC server
@type port: String
@return: <graphics> element
@rtype: DOM Element
"""
document = Document()
elem = document.createElement('graphics')
elem.setAttribute('type', graphicsType)
if(listen != None):
elem.setAttribute('listen', listen)
if(port != None):
elem.setAttribute('port', port)
return elem
开发者ID:Awingu,项目名称:open-ovf,代码行数:26,代码来源:OvfLibvirt.py
示例18: _testElementReprAndStrUnicode
def _testElementReprAndStrUnicode():
dom = Document()
el = dom.appendChild(dom.createElement(u"abc"))
string1 = repr(el)
string2 = str(el)
confirm(string1 == string2)
dom.unlink()
开发者ID:mancoast,项目名称:CPythonPyc_test,代码行数:7,代码来源:213_test_minidom.py
示例19: parallalElement
def parallalElement(deviceType, path, port):
"""
Creates a character device element, a <parallel> element, as a child
of L{device element<devicesElement>}, that specifies the parallel character
device to be used.
@param deviceType: device type
@type deviceType: String
@param path: source path
@type path: String
@param port: port number
@type port: String
@return: <parallel> element
@rtype: DOM Element
"""
document = Document()
deviceElem = document.createElement('parallel')
deviceElem.setAttribute('type', deviceType)
portElem = document.createElement('source')
portElem.setAttribute('path', path)
portElem = document.createElement('target')
portElem.setAttribute('port', port)
deviceElem.appendChild(portElem)
return deviceElem
开发者ID:Awingu,项目名称:open-ovf,代码行数:27,代码来源:OvfLibvirt.py
示例20: testAttributeRepr
def testAttributeRepr():
dom = Document()
el = dom.appendChild(dom.createElement(u"abc"))
node = el.setAttribute("abc", "def")
confirm(str(node) == repr(node))
dom.unlink()
confirm(len(Node.allnodes) == 0)
开发者ID:mancoast,项目名称:CPythonPyc_test,代码行数:7,代码来源:213_test_minidom.py
注:本文中的xml.dom.minidom.Document类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论