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


Python Document.createTextNode方法代码示例

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


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

示例1: xmlObjectDefinitionRepresentation

# 需要导入模块: from xml.dom.minidom import Document [as 别名]
# 或者: from xml.dom.minidom.Document import createTextNode [as 别名]
def xmlObjectDefinitionRepresentation(fileName, fileHash):
	doc = Document()
	dvObjectDefinition = doc.createElement('DIVAObjectDefinition')
	doc.appendChild(dvObjectDefinition)

	nextObject = doc.createElement('objectName')
	nextObject.appendChild(doc.createTextNode(fileName))
	dvObjectDefinition.appendChild(nextObject)

	nextObject = doc.createElement('categoryName')
	nextObject.appendChild(doc.createTextNode('ARCHIVE_DR'))
	dvObjectDefinition.appendChild(nextObject)

	nextObject = doc.createElement('comments')
	nextObject.appendChild(doc.createTextNode('MEDIASEALED FILE {}'.format(fileHash)))
	dvObjectDefinition.appendChild(nextObject)

	fileListObject = doc.createElement('fileList')
	dvObjectDefinition.appendChild(fileListObject)

	nextObject = doc.createElement('file')
	nextObject.appendChild(doc.createTextNode(fileName))
	nextObject.setAttribute('checksumType', 'MD5')
	nextObject.setAttribute('checksumValue', fileHash)	

	fileListObject.appendChild(nextObject)

	return ''.join(node.toprettyxml() for node in doc.childNodes)
开发者ID:patrickcusack,项目名称:BWF,代码行数:30,代码来源:objectdefinitionxml.py

示例2: list_bucket

# 需要导入模块: from xml.dom.minidom import Document [as 别名]
# 或者: from xml.dom.minidom.Document import createTextNode [as 别名]
    def list_bucket(self):
        dirL = self.user.list_bucket(self.bucketName, self.request.args)
        doc = Document()

        # Create the <wml> base element
        xList = doc.createElement("ListBucketResult")
        xList.setAttribute("xmlns", "http://doc.s3.amazonaws.com/2006-03-01")
        doc.appendChild(xList)

        # Create the main <card> element
        xName = doc.createElement("Name")
        xList.appendChild(xName)
        xNameText = doc.createTextNode(str(self.bucketName))
        xName.appendChild(xNameText)

        xIsTruncated = doc.createElement("IsTruncated")
        xList.appendChild(xIsTruncated)
        xIsTText = doc.createTextNode('false')
        xIsTruncated.appendChild(xIsTText)

        for obj in dirL:
            xObj = obj.create_xml_element(doc)
            xList.appendChild(xObj)

        x = doc.toxml();

        self.send_xml(x)
        self.finish(self.request)
开发者ID:Annatara,项目名称:nimbus,代码行数:30,代码来源:cbRequest.py

示例3: questions_to_aiml

# 需要导入模块: from xml.dom.minidom import Document [as 别名]
# 或者: from xml.dom.minidom.Document import createTextNode [as 别名]
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,代码行数:32,代码来源:converter.py

示例4: make_xml_string

# 需要导入模块: from xml.dom.minidom import Document [as 别名]
# 或者: from xml.dom.minidom.Document import createTextNode [as 别名]
    def make_xml_string(self, path, requestId):
        doc = Document()

        # Create the <wml> base element
        xError = doc.createElement("Error")
        doc.appendChild(xError)

        # Create the main <card> element
        xCode = doc.createElement("Code")
        xCodeText = doc.createTextNode(self.code)
        xCode.appendChild(xCodeText)
        xError.appendChild(xCode)

        xMsg = doc.createElement("Message")
        xMsgText = doc.createTextNode(self.eMsg)
        xMsg.appendChild(xMsgText)
        xError.appendChild(xMsg)

        xRsc = doc.createElement("Resource")
        xRscText = doc.createTextNode(path)
        xRsc.appendChild(xRscText)
        xError.appendChild(xRsc)

        xRId = doc.createElement("RequestId")
        xRIdText = doc.createTextNode(str(requestId))
        xRId.appendChild(xRIdText)
        xError.appendChild(xRId)

        for k in self.custom_xml.keys():
            xId = doc.createElement(k)
            xText = doc.createTextNode(self.custom_xml[k])
            xId.appendChild(xText)
            xError.appendChild(xId)

        return doc.toxml()
开发者ID:Annatara,项目名称:nimbus,代码行数:37,代码来源:cbException.py

示例5: _note2musicxml

# 需要导入模块: from xml.dom.minidom import Document [as 别名]
# 或者: from xml.dom.minidom.Document import createTextNode [as 别名]
def _note2musicxml(note):
    doc = Document()
    note_node = doc.createElement("note")
    if note==None:
        #note is a rest
        rest = doc.createElement("rest")
        note_node.appendChild(rest)
    else:
        #add pitch info
        pitch = doc.createElement("pitch")
        step = doc.createElement("step")
        step.appendChild(doc.createTextNode(note.name[:1]))
        pitch.appendChild(step)
        octave = doc.createElement("octave")
        octave.appendChild(doc.createTextNode(str(note.octave)))
        pitch.appendChild(octave)
        #check for alterations
        count = 0
        for i in note.name[1:]:
            if   i=="b": count-=1
            elif i=="#": count +=1
        if count != 0:
            alter = doc.createElement("alter")
            alter.appendChild(doc.createTextNode(str(count)))
            pitch.appendChild(alter)
            
        note_node.appendChild(pitch)

    return note_node
开发者ID:anzev,项目名称:mingus,代码行数:31,代码来源:MusicXML.py

示例6: parseRss

# 需要导入模块: from xml.dom.minidom import Document [as 别名]
# 或者: from xml.dom.minidom.Document import createTextNode [as 别名]
def parseRss(l, info):
    feed = Document()
    rss = feed.createElement("rss")
    channel = feed.createElement("channel")
    title = feed.createElement("title")
    title_text = feed.createTextNode(info["title"])
    link = feed.createElement("link")
    link_text = feed.createTextNode(info["root"])
    title.appendChild(title_text)
    link.appendChild(link_text)
    channel.appendChild(title)
    channel.appendChild(link)
    for p in l:
        item = feed.createElement('item')
        pair = {\
            'title':p['title'], 'description':p['content'],\
            'link':info['root']+'/'+p['rlink']}
        for n in pair.keys():
            node = feed.createElement(n)
            node_text = feed.createTextNode(pair[n])
            node.appendChild(node_text)
            item.appendChild(node)
        channel.appendChild(item)
    rss.appendChild(channel)
    feed.appendChild(rss)
    return feed.toxml()
开发者ID:wontoncc,项目名称:Seraph,代码行数:28,代码来源:rss.py

示例7: record_add_field

# 需要导入模块: from xml.dom.minidom import Document [as 别名]
# 或者: from xml.dom.minidom.Document import createTextNode [as 别名]
def record_add_field(rec, tag, ind1='', ind2='', subfields=[],
                     controlfield_value=''):
    doc = Document()
    datafield = doc.createElement('datafield')
    datafield.setAttribute('tag', tag)
    datafield.setAttribute('ind1', ind1)
    datafield.setAttribute('ind2', ind2)
    for subfield in subfields:
        field = doc.createElement('subfield')
        field.setAttribute('code', subfield[0])
        ## In order to be parsed it needs to a propper XML
        data = "<dummy>" + escape_for_xml(subfield[1]) + "</dummy>"
        try:
            data = parseString(data).firstChild
            for child in data.childNodes:
                field.appendChild(child.cloneNode(child))
        except ExpatError:
            field.appendChild(doc.createTextNode(str(subfield[1])))
        datafield.appendChild(field)
    if controlfield_value:
        controlfield = doc.createElement('controlfield')
        controlfield.setAttribute('tag', tag)
        controlfield.appendChild(doc.createTextNode(str(controlfield_value)))
        rec.appendChild(controlfield)
    else:
        rec.appendChild(datafield)
    return rec
开发者ID:GiorgosPa,项目名称:harvesting-kit,代码行数:29,代码来源:utils.py

示例8: save_pairs

# 需要导入模块: from xml.dom.minidom import Document [as 别名]
# 或者: from xml.dom.minidom.Document import createTextNode [as 别名]
def save_pairs(pairs, path):
    doc = Document()
    corpus = doc.createElement('entailment-corpus')
    doc.appendChild(corpus)
    
    i = 0
    for pair in pairs:
        try:
            text, hypothesis, entailment = pair
        except ValueError:
            print "Too many values: ", pair
            continue
        i += 1
        pair = doc.createElement('pair')
        pair.setAttribute('id', str(i))
        pair.setAttribute('value', str(entailment).upper())
        corpus.appendChild(pair)
        
        t = doc.createElement('t')
        pair.appendChild(t)
        
        t_text = doc.createTextNode(text)
        t.appendChild(t_text)
        
        h = doc.createElement('h')
        pair.appendChild(h)
        
        h_text = doc.createTextNode(hypothesis)
        h.appendChild(h_text)
    f = open(path, 'w')
    doc.writexml(f, addindent=' ', newl='\n')
开发者ID:aurora1625,项目名称:rte-experiment,代码行数:33,代码来源:save_dataset.py

示例9: wrapInMinimalHeader

# 需要导入模块: from xml.dom.minidom import Document [as 别名]
# 或者: from xml.dom.minidom.Document import createTextNode [as 别名]
    def wrapInMinimalHeader(self, title, text):
        """
        Wraps the text into  a minimal header and returns it as
        string
        """
        doc = Document()

        # create elements
        elMwiki = doc.createElement("mediawiki")
        elPage = doc.createElement("page")
        elTitle = doc.createElement("title")
        elRev = doc.createElement("revision")
        elText = doc.createElement("text")

        textstr = doc.createTextNode(text)
        titlestr = doc.createTextNode(title)

        doc.appendChild(elMwiki)
        elMwiki.setAttribute("xmlns", "http://www.mediawiki.org/xml/export-0.4/")
        elMwiki.setAttribute("xmlns:xsi", "http://www.w3.org/2001/XMLSchema-instance")
        elMwiki.setAttribute(
            "xsi:schemaLocation", "http://www.mediawiki.org/xml/export-0.4/ http://www.mediawiki.org/xml/export-0.4.xsd"
        )
        elMwiki.setAttribute("version", "0.4")
        elMwiki.setAttribute("xml:lang", "de")

        elMwiki.appendChild(elPage)
        elPage.appendChild(elTitle)
        elPage.appendChild(elRev)
        elRev.appendChild(elText)
        elText.appendChild(textstr)
        elTitle.appendChild(titlestr)

        return doc.toxml()  # don't prettify
开发者ID:jhamb,项目名称:rest2wiki,代码行数:36,代码来源:rest2wiki.py

示例10: build

# 需要导入模块: from xml.dom.minidom import Document [as 别名]
# 或者: from xml.dom.minidom.Document import createTextNode [as 别名]
	def build(self):
		doc = Document()
		root = doc.createElement('content')
		root.setAttribute('count', str(len(self.questionList)))
		doc.appendChild(root)

		index = 0
		for q in self.questionList:
			index += 1
			qnode = doc.createElement(q.qtype)
			qnode.setAttribute('id', str(index))
			que = doc.createElement('question')
			queText = doc.createTextNode(q.content)
			que.appendChild(queText)
			qnode.appendChild(que)

			ind = 0
			for item in q.items:
				ind += 1
				itemNode = doc.createElement('item')
				itemNode.setAttribute('id', str(ind))
				itemNode.appendChild(doc.createTextNode(item))
				qnode.appendChild(itemNode)
			root.appendChild(qnode)

		return doc.toprettyxml(indent='    ')
开发者ID:BuaaBoys,项目名称:Online-questionnaire-survey-system,代码行数:28,代码来源:questions.py

示例11: positionToXml

# 需要导入模块: from xml.dom.minidom import Document [as 别名]
# 或者: from xml.dom.minidom.Document import createTextNode [as 别名]
    def positionToXml(self):
        doc = Document()

        xml_position_node = doc.createElement(WFConstants.TAG_NAME_POSITION)

        xml_name_node = doc.createElement(WFConstants.TAG_NAME_NAME)
        xml_name_node_content = doc.createTextNode(self.name)
        xml_name_node.appendChild(xml_name_node_content)

        xml_x_node = doc.createElement(WFConstants.TAG_NAME_X)
        xml_x_node_content = doc.createTextNode(self.x)
        xml_x_node.appendChild(xml_x_node_content)

        xml_y_node = doc.createElement(WFConstants.TAG_NAME_Y)
        xml_y_node_content = doc.createTextNode(self.y)
        xml_y_node.appendChild(xml_y_node_content)

        xml_width_node = doc.createElement(WFConstants.TAG_NAME_WIDTH)
        xml_width_node_content = doc.createTextNode(self.width)
        xml_width_node.appendChild(xml_width_node_content)

        xml_height_node = doc.createElement(WFConstants.TAG_NAME_HEIGHT)
        xml_height_node_content = doc.createTextNode(self.height)
        xml_height_node.appendChild(xml_height_node_content)

        xml_position_node.appendChild(xml_name_node)
        xml_position_node.appendChild(xml_x_node)
        xml_position_node.appendChild(xml_y_node)
        xml_position_node.appendChild(xml_width_node)
        xml_position_node.appendChild(xml_height_node)

        return xml_position_node
开发者ID:aaamarkin,项目名称:WFcreater,代码行数:34,代码来源:WFNodes.py

示例12: make_mobile_xml

# 需要导入模块: from xml.dom.minidom import Document [as 别名]
# 或者: from xml.dom.minidom.Document import createTextNode [as 别名]
def make_mobile_xml(Pchtml,MobileUrl):
    #Pchtml = "http://sina2.com.cn"
    #MobileUrl="http://html5.sina2.com.cn"
    #Create minidom document
    doc = Document()
    #Create the <urlset> element
    #urlset = doc.createElement("urlset")
    #doc.appendChild(urlset)
    #Create the <url> element
    url = doc.createElement("url")
    doc.appendChild(url)
    #Create <loc> element
    paragraph1 = doc.createElement("loc")
    url.appendChild(paragraph1)
    locurl = doc.createTextNode(Pchtml)
    #locurl = doc.createCDATASection(Pchtml)
    paragraph1.appendChild(locurl)
    #Create data element
    data = doc.createElement("data")
    url.appendChild(data)
    #Create display element
    display = doc.createElement("display")
    data.appendChild(display)
    #Create html5_url element
    html5_url = doc.createElement("html5_url")
    display.appendChild(html5_url)
    #Create mobile url
    mobile_url = doc.createTextNode(MobileUrl)
    #mobile_url = doc.createCDATASection(MobileUrl)
    html5_url.appendChild(mobile_url)
    #print
    f.write(doc.toprettyxml(indent="  ",encoding="UTF-8"))
开发者ID:xbox,项目名称:python_generate_baidu_mobile_xml,代码行数:34,代码来源:generate.py

示例13: post

# 需要导入模块: from xml.dom.minidom import Document [as 别名]
# 或者: from xml.dom.minidom.Document import createTextNode [as 别名]
    def post(self):
        global current_user
        form = cgi.FieldStorage()
        category_name = (form["category"].value).strip(" ")
        category_user = (form[category_name].value).strip(" ")
        uname = User(key_name=category_user)
        category = Category(key_name=category_name, parent=uname)
        allItems = db.query_descendants(category)

        doc = Document()
        # create category element
        cat = doc.createElement("CATEGORY")
        doc.appendChild(cat)
        # create name element
        name = doc.createElement("NAME")
        cat.appendChild(name)
        # create text node inside name
        n = doc.createTextNode(category_name)
        name.appendChild(n)

        for i in allItems:
            # create item element
            item = doc.createElement("ITEM")
            cat.appendChild(item)
            # create name element
            name = doc.createElement("NAME")
            item.appendChild(name)
            # create text node inside name
            n = doc.createTextNode(i.name)
            name.appendChild(n)

        self.response.out.write("%s" % doc.toprettyxml())
        self.response.out.write("<br><br><div>Go back to the <a href=" "/" ">welcome page</a><div>")
开发者ID:MariannaCo,项目名称:OST,代码行数:35,代码来源:voting.py

示例14: main

# 需要导入模块: from xml.dom.minidom import Document [as 别名]
# 或者: from xml.dom.minidom.Document import createTextNode [as 别名]
def main():
    _format, input, output = sys.argv[1:4]

    f = open(input)
    articles = json.loads(f.read())
    fwrt = open(output, 'w')
    if _format == 'csv':
        wrt = csv.writer(fwrt)
        for url, subject in articles:
            wrt.writerow([url, subject])
    elif _format == 'xml':
        doc = Document()
        e_articles = doc.createElement("articles")
        doc.appendChild(e_articles)
        for url, subject in articles:
            e_article = doc.createElement("article")
            e_article_name = doc.createElement("name")
            e_article_url = doc.createElement("url")
            e_article_name.appendChild(doc.createTextNode(subject))
            e_article_url.appendChild(doc.createTextNode(url))
            e_article.appendChild(e_article_name)
            e_article.appendChild(e_article_url)
            e_articles.appendChild(e_article)
        fwrt.write(doc.toprettyxml(indent="  "))
    fwrt.close()
开发者ID:andrix,项目名称:sworkflow,代码行数:27,代码来源:export_articles.py

示例15: saveTextureList

# 需要导入模块: from xml.dom.minidom import Document [as 别名]
# 或者: from xml.dom.minidom.Document import createTextNode [as 别名]
 def saveTextureList(self, *args, **kwargs):
   ''' write an xml file with a list of the scenes textures and timestamps '''
   fileNodes = pm.ls(type='file')
   sceneName = path.getSceneName()
   xmlFileName = sceneName+'_textureList'
   
   doc = Document()
   textureList = doc.createElement('textureList')
   textureList.setAttribute('sceneName', sceneName)
   doc.appendChild(textureList)
   
   for node in fileNodes:
     fileTextureName = pm.getAttr(node+'.fileTextureName')
     if os.path.isfile(fileTextureName):
       time = os.path.getmtime(fileTextureName)
       
       textureNode = doc.createElement('textureNode')
       textureNode.setAttribute('nodeName', node)
       textureList.appendChild(textureNode)
       
       texturePath = doc.createElement('path')
       texturePath.appendChild(doc.createTextNode(fileTextureName) )
       textureNode.appendChild(texturePath)
       
       textureTime = doc.createElement('time')   
       textureTime.appendChild(doc.createTextNode(str(time) ) )
       textureNode.appendChild(textureTime)
     
   f = open(self.settingsPath+xmlFileName+'.xml', 'w+')
   #f.write(doc.toprettyxml(indent='    ') ) #This is super slow !!!!!
   doc.writexml(f)
   f.close()
开发者ID:kotchin,项目名称:mayaSettings,代码行数:34,代码来源:lcTexture.py


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