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


Python ZDom.createElement方法代码示例

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


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

示例1: createHtmlElement

# 需要导入模块: from zoundry.base.zdom.dom import ZDom [as 别名]
# 或者: from zoundry.base.zdom.dom.ZDom import createElement [as 别名]
def createHtmlElement(parentElement, elementName, attrMap = {}, elementText = None):
    u"""createHtmlElement(Node, string, map, string) -> Node
    Creates a element given element name, attribute map and optional element node text.
    If the parentElement node is None, then element is under new document (zdom).
     """ #$NON-NLS-1$
    element = None
    elementName = getNoneString(elementName)
    elementText = getNoneString(elementText)
    if not elementName:
        return None
    dom = None
    if parentElement:
        dom = parentElement.ownerDocument
    else:
        dom = ZDom()
        dom.loadXML(ELEMENT_TEMPLATE)
        parentElement = dom.documentElement
    try:
        element = dom.createElement(elementName)
        parentElement.appendChild(element)
        for (n,v) in attrMap.iteritems():
            if n and v:                
                element.setAttribute(n,v)
        if elementText:
            element.setText(elementText)
    except:
        pass    
    return element
开发者ID:Tidosho,项目名称:zoundryraven,代码行数:30,代码来源:xhtmldocutil.py

示例2: _save

# 需要导入模块: from zoundry.base.zdom.dom import ZDom [as 别名]
# 或者: from zoundry.base.zdom.dom.ZDom import createElement [as 别名]
    def _save(self):
        if not self.registryFile:
            return

        mediaStorageDir = os.path.basename(self.registryFile)

        dom = ZDom()
        dom.loadXML(u"<registry/>") #$NON-NLS-1$
        registryElem = dom.documentElement
        for fileName in self.fileMap:
            (size, timestamp, uploadResponse) = self.fileMap[fileName]
            relativeFileName = makeRelativePath(mediaStorageDir, fileName)
            url = uploadResponse.getUrl()
            embedFragment = uploadResponse.getEmbedFragment()
            metaData = uploadResponse.getMetaData()

            entryElem = dom.createElement(u"entry") #$NON-NLS-1$
            entryElem.setAttribute(u"size", unicode(size)) #$NON-NLS-1$
            entryElem.setAttribute(u"timestamp", unicode(timestamp)) #$NON-NLS-1$

            fileElem = dom.createElement(u"file") #$NON-NLS-1$
            urlElem = dom.createElement(u"url") #$NON-NLS-1$
            embedElem = dom.createElement(u"embed") #$NON-NLS-1$
            metaDataElem = dom.createElement(u"metaData") #$NON-NLS-1$

            # When in portable mode, save the file paths as relative (which will
            # only happen when the image is on the same drive as the app).
            if isPortableEnabled():
                fileElem.setText(relativeFileName)
            else:
                fileElem.setText(fileName)

            entryElem.appendChild(fileElem)
            if url:
                urlElem.setText(unicode(url))
            entryElem.appendChild(urlElem)
            if embedFragment is not None:
                embedElem.appendChild(dom.importNode(embedFragment, True))
            entryElem.appendChild(embedElem)
            if metaData is not None:
                metaDataElem.appendChild(dom.importNode(metaData, True))
            entryElem.appendChild(metaDataElem)

            registryElem.appendChild(entryElem)

        dom.save(self.registryFile, True)
开发者ID:Tidosho,项目名称:zoundryraven,代码行数:48,代码来源:mediastoragereg.py

示例3: _serializeResponseInfo

# 需要导入模块: from zoundry.base.zdom.dom import ZDom [as 别名]
# 或者: from zoundry.base.zdom.dom.ZDom import createElement [as 别名]
    def _serializeResponseInfo(self, metaFile, connectionRespInfo, dataFilename):
        dom = ZDom()
        dom.loadXML(u"""<http-connection-response />""") #$NON-NLS-1$
        rootElem = dom.documentElement
        urlElem = dom.createElement(u"url") #$NON-NLS-1$
        urlElem.setText(connectionRespInfo.getURL())
        rootElem.appendChild(urlElem)

        dataFileElem = dom.createElement(u"data-file") #$NON-NLS-1$
        dataFileElem.setText(dataFilename)
        rootElem.appendChild(dataFileElem)

        respCodeElem = dom.createElement(u"response-code") #$NON-NLS-1$
        respCodeElem.setText(unicode(connectionRespInfo.getCode()))
        rootElem.appendChild(respCodeElem)

        respMsgElem = dom.createElement(u"response-message") #$NON-NLS-1$
        respMsgElem.setText(unicode(connectionRespInfo.getMessage()))
        rootElem.appendChild(respMsgElem)

        headersElem = dom.createElement(u"response-headers") #$NON-NLS-1$
        rootElem.appendChild(headersElem)

        for headerName in connectionRespInfo.getHeaders():
            headerVal = connectionRespInfo.getHeader(headerName)
            headerElem = dom.createElement(u"header") #$NON-NLS-1$
            headerElem.setAttribute(u"name", headerName) #$NON-NLS-1$
            headerElem.setText(headerVal)
            headersElem.appendChild(headerElem)

        dom.save(metaFile, True)
开发者ID:Tidosho,项目名称:zoundryraven,代码行数:33,代码来源:urlcache.py

示例4: serialize

# 需要导入模块: from zoundry.base.zdom.dom import ZDom [as 别名]
# 或者: from zoundry.base.zdom.dom.ZDom import createElement [as 别名]
 def serialize(self, packet):
     dom = ZDom()
     dom.loadXML(u"<zup:usage-packet xmlns:zup='%s' />" % IZBlogAppNamespaces.RAVEN_USAGE_STATS_NAMESPACE) #$NON-NLS-1$
     
     rootElem = dom.documentElement
     rootElem.setAttribute(u"packet-id", packet.getId()) #$NON-NLS-1$
     
     for key in packet.getAttributes():
         value = packet.getAttributes()[key]
         attrElem = dom.createElement(u"zup:attribute", IZBlogAppNamespaces.RAVEN_USAGE_STATS_NAMESPACE) #$NON-NLS-1$
         rootElem.appendChild(attrElem)
         attrElem.setAttribute(u"name", key) #$NON-NLS-1$
         attrElem.setText(value)
     
     return dom
开发者ID:Tidosho,项目名称:zoundryraven,代码行数:17,代码来源:usageio.py

示例5: importPersonalDictionary

# 需要导入模块: from zoundry.base.zdom.dom import ZDom [as 别名]
# 或者: from zoundry.base.zdom.dom.ZDom import createElement [as 别名]
    def importPersonalDictionary(self):
        joeyConfigDom = self._getJoeyUserConfigDom()
        if not joeyConfigDom:
            return
        try:
            node = joeyConfigDom.selectSingleNode(u"/joey/user-config/spell-check/language") #$NON-NLS-1$
            if not node:
                return
            spellcheckLang = getNoneString( node.getText())
            if not spellcheckLang:
                return

            # FIXME (EPW) we could support other languages...
            if not spellcheckLang == u"en_US": #$NON-NLS-1$
                return

            # 1) read all words from ZBW personal-dictionary.xml file
            # 2) create new spellchecker.xml DOM
            # 3) save new Raven spellchecker file to 'PROFILE\LANG\spellchecker.xml'

            joeyDictFile = os.path.join(self.pathToJoeyProfile, u"spelling/personal-dictionary.xml") #$NON-NLS-1$
            dom = ZDom()
            dom.load(joeyDictFile)
            dom.setNamespaceMap(ZBW_PERSONAL_DICTIONARY_NSS_MAP)
            wordNodeList = dom.selectNodes(u"/pd:personal-dictionary/pd:word") #$NON-NLS-1$
            
            newDom = ZDom()
            newDom.loadXML(ZBlogWriterDictionaryImporter.SPELLCHECK_TEMPLATE)
            newDom.setNamespaceMap(RAVEN_SPELLCHECK_NSS_MAP)
            personalDictElem = newDom.selectSingleNode(u"/spl:spellchecker/spl:personal-dictionary") #$NON-NLS-1$
            
            for wordNode in wordNodeList:
                word = wordNode.getText()
                newWordElem = newDom.createElement(u"word", IZBlogAppNamespaces.RAVEN_SPELLCHECKER_NAMESPACE) #$NON-NLS-1$
                newWordElem.setText(word)
                personalDictElem.appendChild(newWordElem)
            
            outputDir = os.path.join(self.pathToRavenProfile, u"spellcheck/en_US") #$NON-NLS-1$
            os.makedirs(outputDir)
            outputFile = os.path.join(outputDir, u"spellchecker.xml") #$NON-NLS-1$
            newDom.save(outputFile, True)
        except ZException, ze:
            # FIXME (EPW) need to report errors in some way
            ze.printStackTrace()
开发者ID:Tidosho,项目名称:zoundryraven,代码行数:46,代码来源:zbwimporter.py


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