当前位置: 首页>>代码示例>>Python>>正文


Python Document.createElementNS方法代码示例

本文整理汇总了Python中xml.dom.minidom.Document.createElementNS方法的典型用法代码示例。如果您正苦于以下问题:Python Document.createElementNS方法的具体用法?Python Document.createElementNS怎么用?Python Document.createElementNS使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在xml.dom.minidom.Document的用法示例。


在下文中一共展示了Document.createElementNS方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: serialize

# 需要导入模块: from xml.dom.minidom import Document [as 别名]
# 或者: from xml.dom.minidom.Document import createElementNS [as 别名]
    def serialize(self):
        # doc = implementation.createDocument(self.namespace, None, None)
        doc = Document()
        ipsec_element = doc.createElementNS(self.namespace, "ipsec")
        sad_element = doc.createElementNS(self.namespace, "sad")
        spd_element = doc.createElementNS(self.namespace, "spd")
        ipsec_element.appendChild(sad_element)
        ipsec_element.appendChild(spd_element)
        doc.appendChild(ipsec_element)
        if self.SAs:
            for sa in self.SAs:
                saNode = sa.serialize(doc, self.namespace)
                sad_element.appendChild(saNode)
        else:
            print "No SAD entries."

        if self.SPs:
            for sp in self.SPs:
                spNode = sp.serialize(doc, self.namespace)
                spd_element.appendChild(spNode)
        else:
            print "No SPD entries."

        # print doc.toprettyxml()
        return doc
开发者ID:BackupTheBerlios,项目名称:vermont-svn,代码行数:27,代码来源:SAD_SPD.py

示例2: serach_E

# 需要导入模块: from xml.dom.minidom import Document [as 别名]
# 或者: from xml.dom.minidom.Document import createElementNS [as 别名]
def serach_E(n):
    for i in elements:
        if i.name==n:
            if i.data.hasChildNodes()==False:
                xmlfile = Document()
                temp1=xmlfile.createElementNS('xs','complexType')
                temp1.setAttribute('mixed','true')
                i.data.appendChild(temp1)
                temp2=xmlfile.createElementNS('xs','sequence')
                temp1.appendChild(temp2)
            return i.data.getElementsByTagName('complexType')[0].getElementsByTagName('sequence')[0]
    return None
开发者ID:ZhangBowen,项目名称:graduation_project,代码行数:14,代码来源:doc_read.py

示例3: get_XSD_r

# 需要导入模块: from xml.dom.minidom import Document [as 别名]
# 或者: from xml.dom.minidom.Document import createElementNS [as 别名]
def get_XSD_r(conf):
    xmlfile = Document()
    
    information = xmlfile.createElementNS('xs','schema')
    information.setAttributeNS('xmlns','xs','http://www.w3.org/2001/XMLSchema')
    information.setAttribute("targetNamespace",'http://www.w3school.com.cn')
    information.setAttribute('xmlns','http://www.w3school.com.cn')
    xmlfile.appendChild(information)
    conffile=open(conf)
    father=None

    while len(elements):
        elements.pop()
    for line in conffile.readlines():
        temp=line.split('=')
        for j in range(len(temp)):
            temp[j]=temp[j].strip()
        te = xmlfile.createElementNS('xs','element')
        te.setAttribute('name',temp[0])
        elements.append(XMLE(temp[0],te))
        if len(temp)>1:
            temp[0]=temp[1].split(';')
            for j in temp[0]:
                j=j.strip()
                if j == '':
                    continue
                j=j.split(':')
                if j[0]=='type':
                    if j[1]=='str':
                        te.setAttribute('type','xs:string')
                    elif j[1]=='int':
                        te.setAttribute('type','xs:positiveInteger')
                elif j[0]=='fix':
                    te.setAttribute('fixed',j[1])
                elif j[0]=='word'or j[0]=='contain' or j[0]=='maxo' or j[0]=='mino':
                    te.setAttribute(j[0],j[1])
                elif j[0]=='father':
                    father=serach_E(j[1])
                    if father == None:
                        te.setAttribute('error','no father node named :%s' % j[1])
            
            if father == None:
                information.appendChild(te)
            else:
                father.appendChild(te)
                father=None
    conffile.close()
    
    temp = conf.split('\\')            
    f=open('%s.xsdr' % temp[-1].split('.')[0] ,'w')
    xmlfile.writexml(f, "\t", "\t", "\n", "gbk")
    f.close()
开发者ID:ZhangBowen,项目名称:graduation_project,代码行数:54,代码来源:doc_read.py

示例4: createRequestXML

# 需要导入模块: from xml.dom.minidom import Document [as 别名]
# 或者: from xml.dom.minidom.Document import createElementNS [as 别名]
def createRequestXML(service, action, arguments=None):
    from xml.dom.minidom import Document

    doc = Document()

    # create the envelope element and set its attributes
    envelope = doc.createElementNS('', 's:Envelope')
    envelope.setAttribute('xmlns:s', 'http://schemas.xmlsoap.org/soap/envelope/')
    envelope.setAttribute('s:encodingStyle', 'http://schemas.xmlsoap.org/soap/encoding/')

    # create the body element
    body = doc.createElementNS('', 's:Body')

    # create the function element and set its attribute
    fn = doc.createElementNS('', 'u:%s' % action)
    fn.setAttribute('xmlns:u', 'urn:schemas-upnp-org:service:%s' % service)

    # setup the argument element names and values
    # using a list of tuples to preserve order

    # container for created nodes
    argument_list = []

    # iterate over arguments, create nodes, create text nodes,
    # append text nodes to nodes, and finally add the ready product
    # to argument_list
    if arguments is not None:
        for k, v in arguments:
            tmp_node = doc.createElement(k)
            tmp_text_node = doc.createTextNode(v)
            tmp_node.appendChild(tmp_text_node)
            argument_list.append(tmp_node)

    # append the prepared argument nodes to the function element
    for arg in argument_list:
        fn.appendChild(arg)

    # append function element to the body element
    body.appendChild(fn)

    # append body element to envelope element
    envelope.appendChild(body)

    # append envelope element to document, making it the root element
    doc.appendChild(envelope)

    # our tree is ready, conver it to a string
    return doc.toxml()
开发者ID:ViperGeek,项目名称:PyBitmessage,代码行数:50,代码来源:upnp.py

示例5: _buildbasicXMLdoc

# 需要导入模块: from xml.dom.minidom import Document [as 别名]
# 或者: from xml.dom.minidom.Document import createElementNS [as 别名]
 def _buildbasicXMLdoc(self):
     doc = Document()
     root_element = doc.createElementNS('http://api.uclassify.com/1/RequestSchema', 'uclassify')
     root_element.setAttribute("version", "1.01")
     root_element.setAttribute("xmlns", "http://api.uclassify.com/1/server/RequestSchema")
     doc.appendChild(root_element)
     return doc,root_element
开发者ID:Kullax,项目名称:WebScience16,代码行数:9,代码来源:uclassify.py

示例6: export_alignment_table_as_tei

# 需要导入模块: from xml.dom.minidom import Document [as 别名]
# 或者: from xml.dom.minidom.Document import createElementNS [as 别名]
def export_alignment_table_as_tei(table, indent=None):
    d = Document()
    root = d.createElementNS("http://interedition.eu/collatex/ns/1.0", "cx:apparatus") # fake namespace declarations
    root.setAttribute("xmlns:cx", "http://interedition.eu/collatex/ns/1.0")
    root.setAttribute("xmlns", "http://www.tei-c.org/ns/1.0")
    d.appendChild(root)
    for column in table.columns:
        value_dict = defaultdict(list)
        ws_flag = False
        for key, value in sorted(column.tokens_per_witness.items()):
            # value_dict key is reading, value is list of witnesses
            t_readings = "".join(item.token_data["t"] for item in value)
            if ws_flag == False and t_readings.endswith((" ", r"\u0009", r"\000a")): # space, tab, lf
                ws_flag = True
            value_dict[t_readings.strip()].append(key)

        # REVIEW [RHD]: Isn't there a method on table that can be used instead of this len(next(iter() etc?
        # otherwise I think there should be. Not sure what len(next(iter(etc))) represents.
        #
        # See https://stackoverflow.com/questions/4002874/non-destructive-version-of-pop-for-a-dictionary
        # It returns the number of witnesses that attest the one reading in the dictionary, that is, it peeks
        #   nondestructively at the value of the single dictionary item, which is a list, and counts the members
        #   of the list
        if len(value_dict) == 1 and len(next(iter(value_dict.values()))) == len(table.rows):
            # len(table.rows) is total number of witnesses; guards against nulls, which aren't in table
            key, value = value_dict.popitem() # there's just one item
            text_node = d.createTextNode(key)
            root.appendChild(text_node)
        else:
            # variation is either more than one reading, or one reading plus nulls
            app = d.createElementNS("http://www.tei-c.org/ns/1.0", "app")
            root.appendChild(app)
            for key, value in value_dict.items():
                # key is reading (with trailing whitespace stripped), value is list of witnesses
                rdg = d.createElementNS("http://www.tei-c.org/ns/1.0", "rdg")
                rdg.setAttribute("wit", " ".join(["#" + item for item in value_dict[key]]))
                text_node = d.createTextNode(key)
                rdg.appendChild(text_node)
                app.appendChild(rdg)
        if ws_flag:
            text_node = d.createTextNode(" ")
            root.appendChild(text_node)
    if indent:
        result = d.toprettyxml()
    else:
        result = d.toxml()
    return result
开发者ID:interedition,项目名称:collatex,代码行数:49,代码来源:core_functions.py

示例7: toWorkspaceXml

# 需要导入模块: from xml.dom.minidom import Document [as 别名]
# 或者: from xml.dom.minidom.Document import createElementNS [as 别名]
    def toWorkspaceXml(self, quantity=1, data=None):

        launchData = {}
        if self.data != None:
            for key in self.data:
                launchData[key] = self.data[key]
        if data != None:
            for key in data:
                launchData[key] = data[key]

        # why did I think this was a good idea?

        doc = Document()
        cluster = doc.createElementNS("http://www.globus.org/2008/06/workspace/metadata/logistics", "cluster")

        workspace = doc.createElement("workspace");
        cluster.appendChild(workspace)

        name = doc.createElement("name")
        name.appendChild(doc.createTextNode(self.name))
        workspace.appendChild(name)

        image = doc.createElement("image")
        image.appendChild(doc.createTextNode(self.ami))
        workspace.appendChild(image)

        quantityNode = doc.createElement("quantity")
        quantityNode.appendChild(doc.createTextNode(str(quantity)))
        workspace.appendChild(quantityNode)

        nic = doc.createElement("nic")
        nic.setAttribute("wantlogin","true")
        nic.appendChild(doc.createTextNode("public"))
        workspace.appendChild(nic)

        ctx = doc.createElement("ctx")
        workspace.appendChild(ctx)

        provides = doc.createElement("provides")
        provides.appendChild(doc.createElement("identity"))
        ctx.appendChild(provides)

        role = doc.createElement("role")
        role.setAttribute("hostname","true")
        role.setAttribute("pubkey","true")
        role.appendChild(doc.createTextNode(self.name))
        provides.appendChild(role)

        requires = doc.createElement("requires")
        requires.appendChild(doc.createElement("identity"))
        ctx.appendChild(requires)

        for key in launchData:
            dataNode = doc.createElement("data")
            dataNode.setAttribute("name", key)
            dataNode.appendChild(doc.createCDATASection(launchData[key]))
            requires.appendChild(dataNode)
        
        return cluster.toxml()
开发者ID:clemesha-ooi,项目名称:ctx-broker-scalability-harness,代码行数:61,代码来源:cpe_provisioner_ec2.py

示例8: _testElementReprAndStrUnicodeNS

# 需要导入模块: from xml.dom.minidom import Document [as 别名]
# 或者: from xml.dom.minidom.Document import createElementNS [as 别名]
def _testElementReprAndStrUnicodeNS():
    dom = Document()
    el = dom.appendChild(
        dom.createElementNS(u"http://www.slashdot.org", u"slash:abc"))
    string1 = repr(el)
    string2 = str(el)
    confirm(string1 == string2)
    confirm(string1.find("slash:abc") != -1)
    dom.unlink()
开发者ID:Bail-jw,项目名称:mediacomp-jes,代码行数:11,代码来源:test_minidom.py

示例9: to_xml

# 需要导入模块: from xml.dom.minidom import Document [as 别名]
# 或者: from xml.dom.minidom.Document import createElementNS [as 别名]
 def to_xml(self):
     document = Document()
     remover = document.createElementNS(XMLDOC_NAMESPACE, STOP_RECORDING_ROOT_NODE)
     remover.setAttribute(XMLDOC_XMLNS_ATTRIBUTE, XMLDOC_NAMESPACE)
     document.appendChild(remover)
     # object id
     id_node = document.createElement(STOP_RECORDING_ID_NODE)
     remover.appendChild(id_node)
     id_node.appendChild(document.createTextNode(self.object_id_))
     return document.toxml(encoding=XMLDOC_CODEPAGE)
开发者ID:cpaton,项目名称:dvblink-plex-client,代码行数:12,代码来源:recorded_tv.py

示例10: init

# 需要导入模块: from xml.dom.minidom import Document [as 别名]
# 或者: from xml.dom.minidom.Document import createElementNS [as 别名]
def init( metadata ):
	global doc
	if metadata is None:
		doc = Document()
		root = doc.createElementNS( NAMESPACES[ 'kml' ].uri, 'kml' )
		root.setAttribute( 'xmlns', NAMESPACES[ 'kml' ].uri )
		root.setAttribute( 'xmlns:' + NAMESPACES[ 'foaf' ].prefix, NAMESPACES[ 'foaf' ].uri )
		root.setAttribute( 'xmlns:' + NAMESPACES[ 'dc' ].prefix, NAMESPACES[ 'dc' ].uri )
		root.setAttribute( 'xmlns:' + NAMESPACES[ 'xml' ].prefix, NAMESPACES[ 'xml' ].uri )
		doc.appendChild( root )
	else:	
		doc = parseString( metadata )
开发者ID:Aladdin-Unimi,项目名称:Learning-Week-2012-Software,代码行数:14,代码来源:kml.py

示例11: testRemoveAttrNS

# 需要导入模块: from xml.dom.minidom import Document [as 别名]
# 或者: from xml.dom.minidom.Document import createElementNS [as 别名]
def testRemoveAttrNS():
    dom = Document()
    child = dom.appendChild(
            dom.createElementNS("http://www.python.org", "python:abc"))
    child.setAttributeNS("http://www.w3.org", "xmlns:python",
                                            "http://www.python.org")
    child.setAttributeNS("http://www.python.org", "python:abcattr", "foo")
    confirm(len(child.attributes) == 2)
    child.removeAttributeNS("http://www.python.org", "abcattr")
    confirm(len(child.attributes) == 1)

    dom.unlink()
开发者ID:mancoast,项目名称:CPythonPyc_test,代码行数:14,代码来源:213_test_minidom.py

示例12: createFeed

# 需要导入模块: from xml.dom.minidom import Document [as 别名]
# 或者: from xml.dom.minidom.Document import createElementNS [as 别名]
def createFeed(examples):
    doc = Document()
    feed = doc.createElementNS("http://www.w3.org/2005/Atom", "feed")
    feed.setAttribute("xmlns", "http://www.w3.org/2005/Atom") #ug, is this for real??
    for example in examples:
        s = os.stat("../examples/" + example["example"])
        example["modified"] = s.st_mtime
    
    examples.sort(key=lambda x:x["modified"])
    for example in sorted(examples, key=lambda x:x["modified"], reverse=True):
        entry = doc.createElementNS("http://www.w3.org/2005/Atom", "entry")
        
        title = doc.createElementNS("http://www.w3.org/2005/Atom", "title")
        title.appendChild(doc.createTextNode(example["title"] or example["example"]))
        entry.appendChild(title)
        
        link = doc.createElementNS("http://www.w3.org/2005/Atom", "link")
        link.setAttribute("href", example["example"])
        entry.appendChild(link)
    
        summary = doc.createElementNS("http://www.w3.org/2005/Atom", "summary")
        summary.appendChild(doc.createTextNode(example["shortdesc"] or example["example"]))
        entry.appendChild(summary)
        
        updated = doc.createElementNS("http://www.w3.org/2005/Atom", "updated")
        updated.appendChild(doc.createTextNode(
            time.strftime("%Y-%m-%dT%I:%M:%SZ",time.gmtime(example["modified"]))))
        entry.appendChild(updated)
        
        feed.appendChild(entry)

    doc.appendChild(feed)
    return doc
开发者ID:klokan,项目名称:oldmapsonline,代码行数:35,代码来源:exampleparser.py

示例13: to_xml

# 需要导入模块: from xml.dom.minidom import Document [as 别名]
# 或者: from xml.dom.minidom.Document import createElementNS [as 别名]
 def to_xml(self):
     document = Document()
     stop_stream = document.createElementNS(XMLDOC_NAMESPACE, STREAMER_STOP_ROOT_NODE)
     stop_stream.setAttribute(XMLDOC_XMLNS_ATTRIBUTE, XMLDOC_NAMESPACE)
     document.appendChild(stop_stream)
     
     if self.channel_handle_ != None:
         channel_handle = document.createElement(STREAMER_CHANNEL_HANDLE_NODE)
         stop_stream.appendChild(channel_handle)
         channel_handle.appendChild(document.createTextNode(str(self.channel_handle_)))
     elif self.client_id_ != None:
         client_id = document.createElement(STREAMER_CLIENT_ID_NODE)
         stop_stream.appendChild(client_id)
         client_id.appendChild(document.createTextNode(str(self.client_id_)))
     return document.toxml(encoding=XMLDOC_CODEPAGE)
开发者ID:cpaton,项目名称:dvblink-plex-client,代码行数:17,代码来源:streamer.py

示例14: to_xml

# 需要导入模块: from xml.dom.minidom import Document [as 别名]
# 或者: from xml.dom.minidom.Document import createElementNS [as 别名]
 def to_xml(self):
     document = Document()
     epg_searcher = document.createElementNS(XMLDOC_NAMESPACE, SEARCHING_ROOT_NODE)
     epg_searcher.setAttribute(XMLDOC_XMLNS_ATTRIBUTE, XMLDOC_NAMESPACE)
     document.appendChild(epg_searcher)        
     if self.is_epg_short_:
         epg_short = document.createElement(SEARCHING_EPG_SHORT_NODE)
         epg_searcher.appendChild(epg_short)
         epg_short.appendChild(document.createTextNode(XMLNODE_VALUE_TRUE))                    
     
     start_time = document.createElement(SEARCHING_START_TIME_NODE)
     epg_searcher.appendChild(start_time)
     start_time.appendChild(document.createTextNode(str(self.start_time_)))
     
     requested_count = document.createElement(SEARCHING_COUNT_NODE)
     epg_searcher.appendChild(requested_count)
     requested_count.appendChild(document.createTextNode(str(self.requested_count_)))
     
     end_time = document.createElement(SEARCHING_END_TIME_NODE)
     epg_searcher.appendChild(end_time)
     end_time.appendChild(document.createTextNode(str(self.end_time_)))
     
     if self.program_id_ != None:
         program_id = document.createElement(SEARCHING_PROGRAM_ID_NODE)
         epg_searcher.appendChild(program_id)
         program_id.appendChild(document.createTextNode(str(self.program_id_)))
         
     if self.keywords_ != None:
         keywords = document.createElement(SEARCHING_KEYWORDS_NODE)
         epg_searcher.appendChild(keywords)
         keywords.appendChild(document.createTextNode(self.keywords_.decode(XMLDOC_CODEPAGE)))
     
     if self.genre_mask_ != None:
         genre_mask = document.createElement(SEARCHING_GENRE_MASK_NODE)
         epg_searcher.appendChild(genre_mask)
         genre_mask.appendChild(document.createTextNode(str(self.genre_mask_)))
         
     if self.channels_ids_:
         channels_ids = document.createElement(SEARCHING_CHANNELS_IDS_NODE)
         epg_searcher.appendChild(channels_ids)
         for id in self.channels_ids_:
             id_node = document.createElement(SEARCHING_CHANNEL_ID_NODE)
             channels_ids.appendChild(id_node)
             id_node.appendChild(document.createTextNode(id))               
     return document.toxml(encoding=XMLDOC_CODEPAGE)
开发者ID:cpaton,项目名称:dvblink-plex-client,代码行数:47,代码来源:epg_searcher.py

示例15: append

# 需要导入模块: from xml.dom.minidom import Document [as 别名]
# 或者: from xml.dom.minidom.Document import createElementNS [as 别名]
    def append(self, extensionElement):
        """
        Creates an Tag for each attribute and adds them to the given DOM Element 'extensionElement'
        """
        doc = Document()

        for x in self._attributes:
            if self._attributes[x]["enabled"]:
                attribute = doc.createElementNS("urn:oasis:names:tc:SAML:2.0:assertion", "saml2:Attribute")
                # Namespaces
                attribute.setAttribute("xmlns:saml2", "urn:oasis:names:tc:SAML:2.0:assertion")
                attribute.setAttribute("xmlns:eCH-0113", "http://www.ech.ch/xmlns/eCH-0113/1")

                # Attribute
                attribute.setAttribute("Name", self._attributes[x]["id"])
                attribute.setAttribute("eCH-0113:required", "true")

                extensionElement.appendChild(attribute)
开发者ID:tspycher,项目名称:python-suisseid,代码行数:20,代码来源:attributes.py


注:本文中的xml.dom.minidom.Document.createElementNS方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。