本文整理汇总了Python中xml.dom.minidom.Document.createProcessingInstruction方法的典型用法代码示例。如果您正苦于以下问题:Python Document.createProcessingInstruction方法的具体用法?Python Document.createProcessingInstruction怎么用?Python Document.createProcessingInstruction使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类xml.dom.minidom.Document
的用法示例。
在下文中一共展示了Document.createProcessingInstruction方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: impl_create_pydevproject
# 需要导入模块: from xml.dom.minidom import Document [as 别名]
# 或者: from xml.dom.minidom.Document import createProcessingInstruction [as 别名]
def impl_create_pydevproject(self, system_path, user_path):
# create a pydevproject file
doc = Document()
doc.appendChild(doc.createProcessingInstruction('eclipse-pydev', 'version="1.0"'))
pydevproject = doc.createElement('pydev_project')
prop = self.add(doc, pydevproject,
'pydev_property',
'python %d.%d'%(sys.version_info[0], sys.version_info[1]))
prop.setAttribute('name', 'org.python.pydev.PYTHON_PROJECT_VERSION')
prop = self.add(doc, pydevproject, 'pydev_property', 'Default')
prop.setAttribute('name', 'org.python.pydev.PYTHON_PROJECT_INTERPRETER')
# add waf's paths
wafadmin = [p for p in system_path if p.find('wafadmin') != -1]
if wafadmin:
prop = self.add(doc, pydevproject, 'pydev_pathproperty',
{'name':'org.python.pydev.PROJECT_EXTERNAL_SOURCE_PATH'})
for i in wafadmin:
self.add(doc, prop, 'path', i)
if user_path:
prop = self.add(doc, pydevproject, 'pydev_pathproperty',
{'name':'org.python.pydev.PROJECT_SOURCE_PATH'})
for i in user_path:
self.add(doc, prop, 'path', '/${PROJECT_DIR_NAME}/'+i)
doc.appendChild(pydevproject)
return doc
示例2: impl_create_pydevproject
# 需要导入模块: from xml.dom.minidom import Document [as 别名]
# 或者: from xml.dom.minidom.Document import createProcessingInstruction [as 别名]
def impl_create_pydevproject(self, appname, system_path, user_path):
# create a pydevproject file
doc = Document()
doc.appendChild(doc.createProcessingInstruction("eclipse-pydev", 'version="1.0"'))
pydevproject = doc.createElement("pydev_project")
prop = self.add(
doc, pydevproject, "pydev_property", "python %d.%d" % (sys.version_info[0], sys.version_info[1])
)
prop.setAttribute("name", "org.python.pydev.PYTHON_PROJECT_VERSION")
prop = self.add(doc, pydevproject, "pydev_property", "Default")
prop.setAttribute("name", "org.python.pydev.PYTHON_PROJECT_INTERPRETER")
# add waf's paths
wafadmin = [p for p in system_path if p.find("wafadmin") != -1]
if wafadmin:
prop = self.add(
doc, pydevproject, "pydev_pathproperty", {"name": "org.python.pydev.PROJECT_EXTERNAL_SOURCE_PATH"}
)
for i in wafadmin:
self.add(doc, prop, "path", i)
if user_path:
prop = self.add(doc, pydevproject, "pydev_pathproperty", {"name": "org.python.pydev.PROJECT_SOURCE_PATH"})
for i in user_path:
self.add(doc, prop, "path", "/" + appname + "/" + i)
doc.appendChild(pydevproject)
return doc
示例3: dumps
# 需要导入模块: from xml.dom.minidom import Document [as 别名]
# 或者: from xml.dom.minidom.Document import createProcessingInstruction [as 别名]
def dumps(self, obj):
"""
Dump the given object which may be a container of any objects
supported by the reports added to the manager.
"""
document = Document()
if self.stylesheet:
type = "text/xsl"
href = "file://%s" % posixpath.abspath(self.stylesheet)
style = document.createProcessingInstruction("xml-stylesheet",
"type=\"%s\" href=\"%s\"" % (type, href))
document.appendChild(style)
node = document.createElement(self.name)
document.appendChild(node)
if self.version:
node.setAttribute("version", self.version)
try:
self.call_dumps(obj, node)
except KeyError as e:
raise ValueError("Unsupported type: %s" % e)
return document
示例4: go
# 需要导入模块: from xml.dom.minidom import Document [as 别名]
# 或者: from xml.dom.minidom.Document import createProcessingInstruction [as 别名]
def go(tests, output_prefix) :
"""genere les balises de tests de l arbre xml et leurs contenus."""
from xml.dom.minidom import Document
doc = Document()#creation du document
doc.appendChild(doc.createProcessingInstruction("xml-stylesheet",
"type=\"text/xsl\" href=\"report.xsl\""))
testsElt = doc.createElement("tests")#creation du noeud "tests"
doc.appendChild(testsElt)
#creation des noeuds "test" et de leurs contenus
for test in tests:
testElt = doc.createElement("test")
testsElt.appendChild(testElt)
#construction du noeud diagnostic
testElt.appendChild(serializeDiagnostic(doc, test["diagnostic"]))
#creation du noeud "comparisons"
comparisons = doc.createElement("comparisons")
#pour chaque instance de comparaison
for comparison in test["comparisons"]:
comparisons.appendChild(serializeComparison(doc, comparison))
testElt.appendChild(comparisons)
output_file = os.path.join(output_prefix, 'report.xml')
output_file_xsl = os.path.join(output_prefix, 'report.xsl')
#on genere le fichier xml
logfile = open(output_file, 'w')
logfile.write(doc.toprettyxml(indent=" ", encoding="UTF-8"))
logfile.close()
print 'Le fichier résultat est', output_file
# copie de la feuille xsl
shutil.copyfile('xslt/report.xsl', output_file_xsl)
示例5: main
# 需要导入模块: from xml.dom.minidom import Document [as 别名]
# 或者: from xml.dom.minidom.Document import createProcessingInstruction [as 别名]
def main(args):
# Input file should be called men.csv
filename = 'men.csv'
# The XML nodes will be named <bot>
single_item = 'bot'
safe_filename = filename[:-4]
try:
f = csv.reader(open(filename, 'r'))
except IOError:
print('ERROR: Input file men.csv not found in current working directory')
sys.exit(1)
doc = Document()
# Use the file name as the root node name
root_element = doc.createElement(safe_filename)
doc.appendChild(root_element)
# Add the style sheet info
pi = doc.createProcessingInstruction('xml-stylesheet',
'type="text/xsl"'
'href="men.xsl"')
doc.insertBefore(pi, doc.firstChild)
# Get the header row from the csv file
# If it's missing or short, use a default
columns = next(f)
if len(columns) < 4:
columns = ['ipaddress','port','seq_no','active']
# Remove white space from around column names
for i in range(len(columns)):
columns[i] = columns[i].strip()
# Populate the XML document
index = 0
for row in f:
index += 1
item = doc.createElement(single_item)
item.setAttribute('id', str(index))
root_element.appendChild(item)
for c in enumerate(create_col_nodes(columns, item, doc)):
# jpo: Strip white space from node entries
row[0] = row[0].strip()
c[1].appendChild(doc.createTextNode(row.pop(0)))
output_file = safe_filename + ".xml"
# jpo: Add indents and newlines to the XML output
doc.writexml(open(output_file, 'w'), ' ' * 2, ' ' * 2, '\n') # Write file
print("Done: Created %s" % output_file)
示例6: save_logs_as_xml
# 需要导入模块: from xml.dom.minidom import Document [as 别名]
# 或者: from xml.dom.minidom.Document import createProcessingInstruction [as 别名]
def save_logs_as_xml(results, handle):
'''save the chats in results (from get_chats or get_chats_between) as xml
to handle (file like object)
the caller is responsible of closing the handle
'''
from xml.dom.minidom import Document
doc = Document()
doc.appendChild(doc.createProcessingInstruction("xml-stylesheet",
"type=\"text/css\" href=\"conversation.css\""))
conversation = doc.createElement("conversation")
doc.appendChild(conversation)
for stat, timestamp, message, nick, account in results:
timestamp_tag = doc.createElement("timestamp")
date_text = time.strftime('[%c]', time.gmtime(timestamp))
timestamp_text = doc.createTextNode(date_text)
timestamp_tag.appendChild(timestamp_text)
nick_tag = doc.createElement("nick")
nick_text = doc.createTextNode(nick)
nick_tag.appendChild(nick_text)
timestamp_tag.appendChild(nick_tag)
status_tag = doc.createElement("status")
status_text = doc.createTextNode(str(stat))
status_tag.appendChild(status_text)
timestamp_tag.appendChild(status_tag)
account_tag = doc.createElement("account")
account_text = doc.createTextNode(account)
account_tag.appendChild(account_text)
timestamp_tag.appendChild(account_tag)
message_tag = doc.createElement("message")
message_text = doc.createTextNode(message)
message_tag.appendChild(message_text)
timestamp_tag.appendChild(message_tag)
conversation.appendChild(timestamp_tag)
handle.write(doc.toprettyxml(indent=" ", encoding="UTF-8"))
示例7: impl_create_cproject
# 需要导入模块: from xml.dom.minidom import Document [as 别名]
# 或者: from xml.dom.minidom.Document import createProcessingInstruction [as 别名]
def impl_create_cproject(self, executable, waf_executable, appname, workspace_includes, cpppath, source_dirs=[]):
doc = Document()
doc.appendChild(doc.createProcessingInstruction('fileVersion', '4.0.0'))
cconf_id = cdt_core + '.default.config.1'
cproject = doc.createElement('cproject')
storageModule = self.add(doc, cproject, 'storageModule',
{'moduleId': cdt_core + '.settings'})
cconf = self.add(doc, storageModule, 'cconfiguration', {'id':cconf_id})
storageModule = self.add(doc, cconf, 'storageModule',
{'buildSystemId': oe_cdt + '.managedbuilder.core.configurationDataProvider',
'id': cconf_id,
'moduleId': cdt_core + '.settings',
'name': 'Default'})
self.add(doc, storageModule, 'externalSettings')
extensions = self.add(doc, storageModule, 'extensions')
extension_list = """
VCErrorParser
MakeErrorParser
GCCErrorParser
GASErrorParser
GLDErrorParser
""".split()
self.add(doc, extensions, 'extension', {'id': cdt_core + '.ELF', 'point':cdt_core + '.BinaryParser'})
for e in extension_list:
self.add(doc, extensions, 'extension', {'id': cdt_core + '.' + e, 'point':cdt_core + '.ErrorParser'})
storageModule = self.add(doc, cconf, 'storageModule',
{'moduleId': 'cdtBuildSystem', 'version': '4.0.0'})
config = self.add(doc, storageModule, 'configuration',
{'artifactName': appname,
'id': cconf_id,
'name': 'Default',
'parent': cdt_bld + '.prefbase.cfg'})
folderInfo = self.add(doc, config, 'folderInfo',
{'id': cconf_id+'.', 'name': '/', 'resourcePath': ''})
toolChain = self.add(doc, folderInfo, 'toolChain',
{'id': cdt_bld + '.prefbase.toolchain.1',
'name': 'No ToolChain',
'resourceTypeBasedDiscovery': 'false',
'superClass': cdt_bld + '.prefbase.toolchain'})
self.add(doc, toolChain, 'targetPlatform', {'binaryParser': 'org.eclipse.cdt.core.ELF', 'id': cdt_bld + '.prefbase.toolchain.1', 'name': ''})
waf_build = '"%s" %s'%(waf_executable, eclipse.fun)
waf_clean = '"%s" clean'%(waf_executable)
self.add(doc, toolChain, 'builder',
{'autoBuildTarget': waf_build,
'command': executable,
'enableAutoBuild': 'false',
'cleanBuildTarget': waf_clean,
'enableIncrementalBuild': 'true',
'id': cdt_bld + '.settings.default.builder.1',
'incrementalBuildTarget': waf_build,
'managedBuildOn': 'false',
'name': 'Gnu Make Builder',
'superClass': cdt_bld + '.settings.default.builder'})
tool_index = 1;
for tool_name in ("Assembly", "GNU C++", "GNU C"):
tool = self.add(doc, toolChain, 'tool',
{'id': cdt_bld + '.settings.holder.' + str(tool_index),
'name': tool_name,
'superClass': cdt_bld + '.settings.holder'})
if cpppath or workspace_includes:
incpaths = cdt_bld + '.settings.holder.incpaths'
option = self.add(doc, tool, 'option',
{'id': incpaths + '.' + str(tool_index),
'name': 'Include Paths',
'superClass': incpaths,
'valueType': 'includePath'})
for i in workspace_includes:
self.add(doc, option, 'listOptionValue',
{'builtIn': 'false',
'value': '"${workspace_loc:/%s/%s}"'%(appname, i)})
for i in cpppath:
self.add(doc, option, 'listOptionValue',
{'builtIn': 'false',
'value': '"%s"'%(i)})
if tool_name == "GNU C++" or tool_name == "GNU C":
self.add(doc,tool,'inputType',{ 'id':'org.eclipse.cdt.build.core.settings.holder.inType.' + str(tool_index), \
'languageId':'org.eclipse.cdt.core.gcc' if tool_name == "GNU C" else 'org.eclipse.cdt.core.g++','languageName':tool_name, \
'sourceContentType':'org.eclipse.cdt.core.cSource,org.eclipse.cdt.core.cHeader', \
'superClass':'org.eclipse.cdt.build.core.settings.holder.inType' })
tool_index += 1
if source_dirs:
sourceEntries = self.add(doc, config, 'sourceEntries')
for i in source_dirs:
self.add(doc, sourceEntries, 'entry',
{'excluding': i,
'flags': 'VALUE_WORKSPACE_PATH|RESOLVED',
'kind': 'sourcePath',
'name': ''})
self.add(doc, sourceEntries, 'entry',
{
'flags': 'VALUE_WORKSPACE_PATH|RESOLVED',
#.........这里部分代码省略.........
示例8: Xul
# 需要导入模块: from xml.dom.minidom import Document [as 别名]
# 或者: from xml.dom.minidom.Document import createProcessingInstruction [as 别名]
class Xul(object):
"""This is the base xul element which all
other elements inherit from. Also is used
as the base container for the document
>>> x = Xul(); x+=Window(); print x
<?xml version="1.0" ?>
<?xml-stylesheet type="text/css" href="chrome://global/skin"?>
<window height="600" title="Xul Application" width="800" xmlns="\
http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul" \
xmlns:html="http://www.w3.org/1999/xhtml"/>
<BLANKLINE>
"""
def __init__(self, element=None, kwargs=None, addprop=None):
"""This is a init function that is used to initilize common
thing across the different children.
"""
self._properties = { "align": "string", "allowevents": "string",
"allownegativeassertions": "string", "eclass": "string",
"class": "string", "coalesceduplicatearcs": "string",
"collapsed": "string", "container": "string",
"containment": "string", "context": "string",
"contextmenu": "string", "datasources": "string",
"dir": "string", "edir": "string", "empty": "string",
"equalsize": "string", "flags": "string", "flex": "string",
"height": "string", "hidden": "string", "eid": "string",
"id": "string", "insertafter": "string", "insertbefore": "string",
"left": "string", "maxheight": "string", "maxwidth": "string",
"menu": "string", "minheight": "string", "minwidth": "string",
"mousethrough": "string", "observes": "string", "ordinal": "string",
"orient": "string", "pack": "string", "persist": "string",
"popup": "string", "position": "string",
"preference-editable": "string", "querytype": "string",
"ref": "string", "removeelement": "string",
"sortDirection": "string", "sortResource": "string",
"sortResource2": "string", "statustext": "string", "style": "string",
"template": "string", "tooltip": "string", "tooltiptext": "string",
"top": "string", "uri": "string", "wait-cursor": "string",
"width": "string", "xmlns": "string", "xmlns:html": "string" }
if(addprop):
self._properties = dict(self._properties, **addprop)
self._doc = Document()
type(self).__name__="xulelement"
if(element):
self._element = self._doc.createElement(element)
else:
self._element = self._doc
self._doc.appendChild(self._doc.createProcessingInstruction(\
"xml-stylesheet","type=\"text/css\" href=\"chrome://global/skin\""))
if(kwargs):
for key in kwargs:
if(key=="eid"):
self.__setattr__("id", kwargs[key])
elif(key=="eclass"):
self.__setattr__("class", kwargs[key])
elif(key=="eopen"):
self.__setattr__("open", kwargs[key])
elif(key=="etype"):
self.__setattr__("type", kwargs[key])
elif(key=="edir"):
self.__setattr__("dir", kwargs[key])
else:
self.__setattr__(key, kwargs[key])
def __setattr__(self, name, value):
if name in self.__dict__ or name in ["_element", "_doc",
"_properties"]:
super(Xul, self).__setattr__(name, value)
else:
element = self.getelement()
if STRICT:
if name in self._properties:
element.setAttribute(str(name), str(value))
else:
raise StrictError("Your trying to add an attribute that \
is not supported by the element")
else:
element.setAttribute(str(name), str(value))
def __getattr__(self, name):
if name in self.__dict__:
super(Xul, self).__getattr__(name)
else:
element = self.getelement()
ret = Attribute(name, element.getAttribute(name))
return ret
def _adder(self, other, parent):
"""This is a helper function so it's possible to go
recursively through adding elements"""
if(self == other):
raise SelfReference('Your adding your self')
if type(other).__name__=="list" or type(other).__name__=="List":
last = None
for other_element in other:
if type(other_element).__name__=="list":
if(last):
self._adder(other_element, last)
last = List(other_element)
last.parent = parent
else:
raise EmptyList("You cant start with two lists")
elif type(other_element).__name__=="str" or \
#.........这里部分代码省略.........
示例9: impl_create_cproject
# 需要导入模块: from xml.dom.minidom import Document [as 别名]
# 或者: from xml.dom.minidom.Document import createProcessingInstruction [as 别名]
def impl_create_cproject(self, executable, waf, appname, workspace_includes, cpppath, source_dirs=[]):
doc = Document()
doc.appendChild(doc.createProcessingInstruction("fileVersion", "4.0.0"))
cconf_id = cdt_core + ".default.config.1"
cproject = doc.createElement("cproject")
storageModule = self.add(doc, cproject, "storageModule", {"moduleId": cdt_core + ".settings"})
cconf = self.add(doc, storageModule, "cconfiguration", {"id": cconf_id})
storageModule = self.add(
doc,
cconf,
"storageModule",
{
"buildSystemId": oe_cdt + ".managedbuilder.core.configurationDataProvider",
"id": cconf_id,
"moduleId": cdt_core + ".settings",
"name": "Default",
},
)
self.add(doc, storageModule, "externalSettings")
extensions = self.add(doc, storageModule, "extensions")
extension_list = """
VCErrorParser
MakeErrorParser
GCCErrorParser
GASErrorParser
GLDErrorParser
""".split()
ext = self.add(doc, extensions, "extension", {"id": cdt_core + ".ELF", "point": cdt_core + ".BinaryParser"})
for e in extension_list:
ext = self.add(doc, extensions, "extension", {"id": cdt_core + "." + e, "point": cdt_core + ".ErrorParser"})
storageModule = self.add(doc, cconf, "storageModule", {"moduleId": "cdtBuildSystem", "version": "4.0.0"})
config = self.add(
doc,
storageModule,
"configuration",
{"artifactName": appname, "id": cconf_id, "name": "Default", "parent": cdt_bld + ".prefbase.cfg"},
)
folderInfo = self.add(doc, config, "folderInfo", {"id": cconf_id + ".", "name": "/", "resourcePath": ""})
toolChain = self.add(
doc,
folderInfo,
"toolChain",
{
"id": cdt_bld + ".prefbase.toolchain.1",
"name": "No ToolChain",
"resourceTypeBasedDiscovery": "false",
"superClass": cdt_bld + ".prefbase.toolchain",
},
)
targetPlatform = self.add(
doc,
toolChain,
"targetPlatform",
{"binaryParser": "org.eclipse.cdt.core.ELF", "id": cdt_bld + ".prefbase.toolchain.1", "name": ""},
)
waf_build = '"%s" %s' % (waf, eclipse.fun)
waf_clean = '"%s" clean' % (waf)
builder = self.add(
doc,
toolChain,
"builder",
{
"autoBuildTarget": waf_build,
"command": executable,
"enableAutoBuild": "false",
"cleanBuildTarget": waf_clean,
"enableIncrementalBuild": "true",
"id": cdt_bld + ".settings.default.builder.1",
"incrementalBuildTarget": waf_build,
"managedBuildOn": "false",
"name": "Gnu Make Builder",
"superClass": cdt_bld + ".settings.default.builder",
},
)
for tool_name in ("Assembly", "GNU C++", "GNU C"):
tool = self.add(
doc,
toolChain,
"tool",
{"id": cdt_bld + ".settings.holder.1", "name": tool_name, "superClass": cdt_bld + ".settings.holder"},
)
if cpppath or workspace_includes:
incpaths = cdt_bld + ".settings.holder.incpaths"
option = self.add(
doc,
tool,
"option",
{
"id": incpaths + ".1",
"name": "Include Paths",
"superClass": incpaths,
"valueType": "includePath",
#.........这里部分代码省略.........
示例10: Document
# 需要导入模块: from xml.dom.minidom import Document [as 别名]
# 或者: from xml.dom.minidom.Document import createProcessingInstruction [as 别名]
#!/usr/bin/python
import sys, os, re
from xml.dom.minidom import Document
tables=[]
errors=[]
ingroup = False
currenttable = ''
xmlDoc = Document()
pi= xmlDoc.createProcessingInstruction("xml-stylesheet","type=\"text/xsl\" href=\"template.xsl\"")
xmlDoc.insertBefore(pi, xmlDoc.documentElement)
wml = xmlDoc.createElement("database")
xmlDoc.appendChild(wml)
schema = open(sys.argv[1], 'r')
result = file(sys.argv[2],"w")
createTablePattern = re.compile(r'^\s+create_table \"([a-z_-]+)\"',re.M|re.I)
endTablePattern = re.compile(r'^\s+end',re.M|re.I)
fieldPattern = re.compile(r'^\s+t\.[a-z]+\s+\"([a-z0-9-_]+)\"',re.M|re.I)
for i, line in enumerate(schema):
if re.match('^\s+$',line,re.M|re.I):