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


Python cElementTree.Element方法代码示例

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


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

示例1: save

# 需要导入模块: from xml.etree import cElementTree [as 别名]
# 或者: from xml.etree.cElementTree import Element [as 别名]
def save(self, name, settings=None):
        writer = GXXmlWriter()
        objects = ET.Element("Objects")
        for it in self:
            node = ET.SubElement(objects, "GXDLMS" + GXDLMSConverter.objectTypeToString(it.objectType))
            if it.shortName != 0:
                ET.SubElement(node, "SN").text = str(it.shortName)
            ET.SubElement(node, "LN").text = it.logicalName
            if it.version != 0:
                ET.SubElement(node, "Version").text = str(it.version)
            if it.description:
                ET.SubElement(node, "Description").text = it.description
            if not settings or settings.values:
                writer.objects = []
                writer.objects.append(node)
                it.save(writer)
        str_ = minidom.parseString(ET.tostring(objects, encoding='utf-8', method='xml')).toprettyxml(indent="  ")
        with open(name, "w") as f:
            f.write(str_) 
开发者ID:Gurux,项目名称:Gurux.DLMS.Python,代码行数:21,代码来源:GXDLMSObjectCollection.py

示例2: __call__

# 需要导入模块: from xml.etree import cElementTree [as 别名]
# 或者: from xml.etree.cElementTree import Element [as 别名]
def __call__(self, target):
        """
        Arguments:
            target (annotation) : the target annotation to be made usable
                will be an ET.Element
        Returns:
            a list containing lists of bounding boxes  [bbox coords, class name]
        """
        res = np.empty((0, 5))
        for obj in target.iter('object'):
            difficult = int(obj.find('difficult').text) == 1
            if not self.keep_difficult and difficult:
                continue
            name = obj.find('name').text.lower().strip()
            bbox = obj.find('bndbox')

            pts = ['xmin', 'ymin', 'xmax', 'ymax']
            bndbox = []
            for i, pt in enumerate(pts):
                cur_pt = int(bbox.find(pt).text)
                bndbox.append(cur_pt)
            label_idx = self.class_to_ind[name]
            bndbox.append(label_idx)
            res = np.vstack((res, bndbox))  # [xmin, ymin, xmax, ymax, label_ind]
        return res 
开发者ID:zllrunning,项目名称:hand-detection.PyTorch,代码行数:27,代码来源:wider_voc.py

示例3: create_bootstrap_aggregate_file

# 需要导入模块: from xml.etree import cElementTree [as 别名]
# 或者: from xml.etree.cElementTree import Element [as 别名]
def create_bootstrap_aggregate_file(self):
        url = self.api.makeurl(['source', self.prj, 'bootstrap-copy', '_aggregate'])

        root = ET.Element('aggregatelist')
        a = ET.SubElement(root, 'aggregate',
                          {'project': '{}:0-Bootstrap'.format(self.api.crings)})

        for package in self.bootstrap_packages():
            p = ET.SubElement(a, 'package')
            p.text = package

        ET.SubElement(a, 'repository', {'target': 'bootstrap_copy', 'source': 'standard'})
        ET.SubElement(a, 'repository', {'target': 'standard', 'source': 'nothing'})
        ET.SubElement(a, 'repository', {'target': 'images', 'source': 'nothing'})

        self.api.retried_PUT(url, ET.tostring(root)) 
开发者ID:openSUSE,项目名称:openSUSE-release-tools,代码行数:18,代码来源:freeze_command.py

示例4: generate_settings_file

# 需要导入模块: from xml.etree import cElementTree [as 别名]
# 或者: from xml.etree.cElementTree import Element [as 别名]
def generate_settings_file(target_path):
    source_path = xbmc.translatePath(
        os.path.join(ADDON.getAddonInfo('path'), 'resources', 'settings.xml'))
    root_target = ceT.Element("settings")
    tree_source = eT.parse(source_path)
    root_source = tree_source.getroot()
    for item in root_source.findall('category'):
        for setting in item.findall('setting'):
            if 'id' in setting.attrib:
                value = ''
                if 'default' in setting.attrib:
                    value = setting.attrib['default']
                ceT.SubElement(root_target, 'setting', id=setting.attrib['id'], value=value)
    tree_target = ceT.ElementTree(root_target)
    f = open(target_path, 'w')
    tree_target.write(f)
    f.close() 
开发者ID:primaeval,项目名称:script.tvguide.fullscreen,代码行数:19,代码来源:utils.py

示例5: indent_xml

# 需要导入模块: from xml.etree import cElementTree [as 别名]
# 或者: from xml.etree.cElementTree import Element [as 别名]
def indent_xml(self, element: Element, level=0):
        indentation = '\n' + level * '    '
        if len(element):
            if not element.text or not element.text.strip():
                element.text = indentation + '    '
            if not element.tail or not element.tail.strip():
                element.tail = indentation
            for element in element:
                self.indent_xml(element, level + 1)
            if not element.tail or not element.tail.strip():
                element.tail = indentation
        else:
            if level and (not element.tail or not element.tail.strip()):
                element.tail = indentation

    # https://stackoverflow.com/a/27550126/5268548 
开发者ID:ClaudiuGeorgiu,项目名称:Obfuscapk,代码行数:18,代码来源:random_manifest.py

示例6: xml_elements_equal

# 需要导入模块: from xml.etree import cElementTree [as 别名]
# 或者: from xml.etree.cElementTree import Element [as 别名]
def xml_elements_equal(self, one: Element, other: Element) -> bool:
        if type(one) != type(other):
            return False
        if one.tag != other.tag:
            return False

        if one.text and other.text:
            if one.text.strip() != other.text.strip():
                return False
        elif one.text != other.text:
            return False

        if one.tail and other.tail:
            if one.tail.strip() != other.tail.strip():
                return False
        elif one.tail != other.tail:
            return False

        if one.attrib != other.attrib:
            return False
        if len(one) != len(other):
            return False

        return all(self.xml_elements_equal(e1, e2) for e1, e2 in zip(one, other)) 
开发者ID:ClaudiuGeorgiu,项目名称:Obfuscapk,代码行数:26,代码来源:random_manifest.py

示例7: remove_xml_duplicates

# 需要导入模块: from xml.etree import cElementTree [as 别名]
# 或者: from xml.etree.cElementTree import Element [as 别名]
def remove_xml_duplicates(self, root: Element):

        # Recursively eliminate duplicates starting from children nodes.
        for element in root:
            self.remove_xml_duplicates(element)

        non_duplicates = []
        elements_to_remove = []

        # Find duplicate nodes which have the same parent node.
        for element in root:
            if any(self.xml_elements_equal(element, nd) for nd in non_duplicates):
                elements_to_remove.append(element)
            else:
                non_duplicates.append(element)

        # Remove existing duplicates at this level.
        for element_to_remove in elements_to_remove:
            root.remove(element_to_remove) 
开发者ID:ClaudiuGeorgiu,项目名称:Obfuscapk,代码行数:21,代码来源:random_manifest.py

示例8: scramble_xml_element

# 需要导入模块: from xml.etree import cElementTree [as 别名]
# 或者: from xml.etree.cElementTree import Element [as 别名]
def scramble_xml_element(self, element: Element):
        children = []

        # Get the children of the current element.
        for child in element:
            children.append(child)

        # Remove the children from the current element (they will be added later
        # in a different order).
        for child in children:
            element.remove(child)

        # Shuffle the order of the children of the element and add them again to
        # the element. Then repeat the scramble operation recursively.
        random.shuffle(children)
        for child in children:
            element.append(child)
            self.scramble_xml_element(child) 
开发者ID:ClaudiuGeorgiu,项目名称:Obfuscapk,代码行数:20,代码来源:random_manifest.py

示例9: from_xml

# 需要导入模块: from xml.etree import cElementTree [as 别名]
# 或者: from xml.etree.cElementTree import Element [as 别名]
def from_xml(cls, xml, chunks_to_load=None, load_subtypes=True, type_separator=u"."):
        if sem.misc.is_string(xml):
            data = ET.parse(xml)
        elif isinstance(xml, ET.ElementTree):
            data = xml
        elif isinstance(xml, type(ET.Element("a"))): # did not ind a better way to do this
            data = xml
        else:
            raise TypeError("Invalid type for loading XML-SEM document: {0}".format(type(xml)))
        
        root = data.getroot()
        if root.tag != "sem":
            raise ValueError("Not sem xml file type: '{0}'".format(root.tag))
        doc_list = []
        for document in list(root):
            doc_list.append(Document.from_xml(document))
        return SEMCorpus(doc_list) 
开发者ID:YoannDupont,项目名称:SEM,代码行数:19,代码来源:document.py

示例10: newXMLPASCALfile

# 需要导入模块: from xml.etree import cElementTree [as 别名]
# 或者: from xml.etree.cElementTree import Element [as 别名]
def newXMLPASCALfile(imageheight, imagewidth, path, basename):
    # print(filename)
    annotation = ET.Element("annotation", verified="yes")
    ET.SubElement(annotation, "folder").text = "images"
    ET.SubElement(annotation, "filename").text = basename
    ET.SubElement(annotation, "path").text = path

    source = ET.SubElement(annotation, "source")
    ET.SubElement(source, "database").text = "test"

    size = ET.SubElement(annotation, "size")
    ET.SubElement(size, "width").text = str(imagewidth)
    ET.SubElement(size, "height").text = str(imageheight)
    ET.SubElement(size, "depth").text = "3"

    ET.SubElement(annotation, "segmented").text = "0"

    tree = ET.ElementTree(annotation)
    # tree.write("filename.xml")
    return tree 
开发者ID:Seymour-Lee,项目名称:face-detection-ssd-mobilenet,代码行数:22,代码来源:2_data_to_pascal_xml.py

示例11: visit

# 需要导入模块: from xml.etree import cElementTree [as 别名]
# 或者: from xml.etree.cElementTree import Element [as 别名]
def visit(self, node):
        xml_node = ElementTree.Element(node.display_name)

        # attributes
        for attr, attrValue in node.__dict__.items():
            if not attr.startswith('_') and attrValue is not None:
                xml_attr = ElementTree.SubElement(xml_node, attr)
                child_node = self.visit(attrValue)
                if type(child_node) is str:
                    xml_attr.text = child_node
                elif type(child_node) is list:
                    xml_attr.extend(child_node)
                else:
                    xml_attr.append(child_node)

        return xml_node 
开发者ID:boolangery,项目名称:py-lua-parser,代码行数:18,代码来源:printers.py

示例12: saveMean

# 需要导入模块: from xml.etree import cElementTree [as 别名]
# 或者: from xml.etree.cElementTree import Element [as 别名]
def saveMean(fname, data):
    root = et.Element('opencv_storage')
    et.SubElement(root, 'Channel').text = '3'
    et.SubElement(root, 'Row').text = str(imgSize)
    et.SubElement(root, 'Col').text = str(imgSize)
    meanImg = et.SubElement(root, 'MeanImg', type_id='opencv-matrix')
    et.SubElement(meanImg, 'rows').text = '1'
    et.SubElement(meanImg, 'cols').text = str(imgSize * imgSize * 3)
    et.SubElement(meanImg, 'dt').text = 'f'
    et.SubElement(meanImg, 'data').text = ' '.join(
        ['%e' % n for n in np.reshape(data, (imgSize * imgSize * 3))]
    )

    tree = et.ElementTree(root)
    tree.write(fname)
    x = xml.dom.minidom.parse(fname)
    with open(fname, 'w') as f:
        f.write(x.toprettyxml(indent='  ')) 
开发者ID:NervanaSystems,项目名称:ngraph-python,代码行数:20,代码来源:cifar_prepare.py

示例13: saveMean

# 需要导入模块: from xml.etree import cElementTree [as 别名]
# 或者: from xml.etree.cElementTree import Element [as 别名]
def saveMean(fname, data):
    root = et.Element('opencv_storage')
    et.SubElement(root, 'Channel').text = '3'
    et.SubElement(root, 'Row').text = str(IMGSIZE)
    et.SubElement(root, 'Col').text = str(IMGSIZE)
    meanImg = et.SubElement(root, 'MeanImg', type_id='opencv-matrix')
    et.SubElement(meanImg, 'rows').text = '1'
    et.SubElement(meanImg, 'cols').text = str(IMGSIZE * IMGSIZE * 3)
    et.SubElement(meanImg, 'dt').text = 'f'
    et.SubElement(meanImg, 'data').text = ' '.join(['%e' % n for n in np.reshape(data, (IMGSIZE * IMGSIZE * 3))])

    tree = et.ElementTree(root)
    tree.write(fname)
    x = xml.dom.minidom.parse(fname)
    with open(fname, 'w') as f:
        f.write(x.toprettyxml(indent = '  ')) 
开发者ID:Azure,项目名称:batch-shipyard,代码行数:18,代码来源:cifar_data_processing.py

示例14: isStartElement

# 需要导入模块: from xml.etree import cElementTree [as 别名]
# 或者: from xml.etree.cElementTree import Element [as 别名]
def isStartElement(self, name=None, getNext=False):
        if name is None:
            ret = isinstance(self.currentElement, (ET.Element,))
        else:
            ret = isinstance(self.currentElement, (ET.Element,)) and self.currentElement.tag == name
        if ret and getNext:
            self.getNext()
        return ret 
开发者ID:Gurux,项目名称:Gurux.DLMS.Python,代码行数:10,代码来源:GXXmlReader.py

示例15: send_feedback

# 需要导入模块: from xml.etree import cElementTree [as 别名]
# 或者: from xml.etree.cElementTree import Element [as 别名]
def send_feedback(self):
        """Print stored items to console/Alfred as XML."""
        root = ET.Element('items')
        for item in self._items:
            root.append(item.elem)
        sys.stdout.write('<?xml version="1.0" encoding="utf-8"?>\n')
        sys.stdout.write(ET.tostring(root).encode('utf-8'))
        sys.stdout.flush()

    ####################################################################
    # Updating methods
    #################################################################### 
开发者ID:TKkk-iOSer,项目名称:wechat-alfred-workflow,代码行数:14,代码来源:workflow.py


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