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


Python SubElement.getchildren方法代码示例

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


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

示例1: set_text

# 需要导入模块: from xml.etree.ElementTree import SubElement [as 别名]
# 或者: from xml.etree.ElementTree.SubElement import getchildren [as 别名]
def set_text(entry, name, ttype, value):
    elements = entry.findall(ATOM(name))
    if not elements:
        element = SubElement(entry, ATOM(name))
    else:
        element = elements[0]
    element.set('type', ttype)
    [element.remove(e) for e in element.getchildren()]
    if ttype in ["html", "text"]:
        element.text = value
    elif ttype == "xhtml":
        element.text = ""
        try:
            div = fromstring((u"<div xmlns='http://www.w3.org/1999/xhtml'>%s</div>" % value).encode('utf-8'))
            element.append(div)
        except:
            element.text = value
            element.set('type', 'html')
开发者ID:myblup,项目名称:atompubbase,代码行数:20,代码来源:util.py

示例2: _to_xml

# 需要导入模块: from xml.etree.ElementTree import SubElement [as 别名]
# 或者: from xml.etree.ElementTree.SubElement import getchildren [as 别名]
    def _to_xml(self, element=None, instance=None):

        """
        The opposite of "_from_xml".
        Lowercase underscore names are converted to CamelCase.
        """

        inst = (instance or self)

        # Renaming the root
        node_name = inst.__class__.__name__

        if hasattr(inst, BASE_PROP_NODE):
            if inst._node_name is not None:
                node_name = inst._node_name

        if hasattr(inst, BASE_PROP_NODE_SAVE):
            if inst._node_name_save is not None:
                node_name = inst._node_name_save

        elem = (Element(node_name) if element is None else element)

        map = None

        # "Map" is a base class that sets the correspondence between XML
        # elements and class properties, i.e. what's not in this class doesn't
        # get written to the file.

        for classtype in getmro(inst.__class__):
            if (classtype.__name__.endswith(BASE_MAP_SUFFIX) and
                    classtype.__name__ != BaseMap.__name__):
                map = classtype
                break

        if map is None:
            return elem

        for prop in dir(map):

            property = getattr(inst, prop)

            if (prop.startswith("_") or
                callable(property) or
                property is None):
                continue

            # Lists

            if isinstance(property, BaseResourceList):
                for item in property.items:
                    el = SubElement(elem, self._converter.to_camelcase(prop))
                    self._to_xml(el, item)
                continue

            if isinstance(property, BaseResourceSimpleList):
                for item in property.items:
                    el = SubElement(elem, self._converter.to_camelcase(prop))
                    el.text = str(item)
                continue

            # Everything else

            el = SubElement(elem, self._converter.to_camelcase(prop))

            if isinstance(property, BaseMap):
                self._to_xml(el, property)
                if (len(el.getchildren()) == 0) and (el.text is None):
                    elem.remove(el)
            else:
                el.text = str(property)

        return elem
开发者ID:scottbarstow,项目名称:iris-python,代码行数:74,代码来源:base_resource.py

示例3: execIscDataRec

# 需要导入模块: from xml.etree.ElementTree import SubElement [as 别名]
# 或者: from xml.etree.ElementTree.SubElement import getchildren [as 别名]
def execIscDataRec(MSGID,SUBJECT,FILES):
    import siteConfig
    
    try:
       # logEvent('*** iscDataRec ***', sys.argv[1:]) 
        logEvent('SUBJECT:', SUBJECT, 'MSGID:', MSGID,"FILES:",FILES)
     
        time1 = time.clock() 
        
        #get our MHS id
        ourMhsID = siteConfig.GFESUITE_MHSID
        
        # for most transactions, first attachment is the data file, 2nd file is the
        # XML destinations.  The ISCREQUEST is unique with only 1 file being the
        # XML destinations.  We simulate two files naming them the same.
        if SUBJECT == "ISCREQUEST":
            FILES.append(FILES[0])
        
        dataFile = FILES[0]  #first attachment is always the data file
        if len(FILES) > 1:
            xmlFile = FILES[1]  #second attachment is the xml destinations file
            fd = open(xmlFile,'rb')
            xmlFileBuf = fd.read()
            fd.close()
            try:
                destTree = ElementTree.ElementTree(ElementTree.XML(xmlFileBuf))
                iscE = destTree.getroot()
            except:
                logProblem("Malformed XML received")
                return
        
        #no XML destination information. Default to dx4f,px3 98000000, 98000001
        else:
            # create a xml element tree to replace the missing one.  This will
            # occur when OB8.2 sites send ISC data to OB8.3 sites, and also when
            # active table exchanges occur.  We default to 98000000 and 98000001
            # on dx4 since that is where the primary and svcbu servers are located.
            # This will cause log errors until everyone is on OB8.3.
            iscE = Element('isc')
            destinationsE = SubElement(iscE, 'destinations')
            for x in xrange(98000000, 98000002):
                for shost in ['dx4f','px3f']:
                    addressE = SubElement(destinationsE, 'address')
                    serverE = SubElement(addressE, 'server')
                    serverE.text = shost
                    portE = SubElement(addressE, 'port')
                    portE.text = str(x)
                    protocolE = SubElement(addressE, 'protocol')
                    protocolE.text = "20070723"   #match this from IFPProtocol.C
                    mhsE = SubElement(addressE, 'mhsid')
                    mhsE.text = siteConfig.GFESUITE_MHSID
        
        irt = IrtAccess.IrtAccess("")
        
        # find source xml
        found = False
        for srcE in iscE.getchildren():
            if srcE.tag == "source":
                for addressE in srcE:
                    srcServer = irt.decodeXMLAddress(addressE)
                    if srcServer is None:
                        continue
                    found = True
                    logEvent("Source:",irt.printServerInfo(srcServer))
                    break
        if not found:
            logEvent("Source: <unknown>")
        
        # find destinations xml
        found = False
        for destE in iscE.getchildren():
            if destE.tag == "destinations":
                found = True
                break
        if not found:
            logProblem("destinations packet missing from xml")
            return
        
        # decode and print the source server (if present)
        for addressE in destE:
            if addressE.tag != "address":
                continue
        
            destServer = irt.decodeXMLAddress(addressE)
        
            # find destination server information
            mhsidDest=serverDest=portDest=protocolDest=None
            for attrE in addressE.getchildren():
                if attrE.tag == "mhsid":
                    mhsidDest = attrE.text
                elif attrE.tag == "server":
                    serverDest = attrE.text
                elif attrE.tag == "port":
                    portDest = attrE.text
                elif attrE.tag == "protocol":
                    protocolDest = attrE.text
                    
            if destServer['mhsid'].upper() != ourMhsID.upper():
                logDebug(SUBJECT, 'Not our mhs of ' + ourMhsID + \
                  ', so skipped:', irt.printServerInfo(destServer))
#.........这里部分代码省略.........
开发者ID:KeithLatteri,项目名称:awips2,代码行数:103,代码来源:iscDataRec.py


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