Exemplo n.º 1
0
 def img_to_html(self, parent):
     node = Element('img')
     node.attrib = {
         "src":
         "http://upload.wikimedia.org/wikipedia/commons/thumb/1/16/CBRF.png/200px-CBRF.png"
     }
     parent.append(node)
Exemplo n.º 2
0
def copy_element(from_element, to_element=None, path_to_copy=None):
    """
    Copies the element at path_to_copy in from_element and uses it to create or update
    the first element found at the same location (path_to_copy) in to_element.

    If path_to_copy is not provided, from_element is copied to the root of to_element.
    """

    from_element = get_element(from_element, path_to_copy)
    dest_element = get_element(to_element, path_to_copy)

    if from_element is None:
        return None

    if dest_element is None:
        if path_to_copy is None:
            dest_element = Element(from_element.tag)
        else:
            dest_element = insert_element(Element(from_element.tag), 0,
                                          path_to_copy)

    dest_element.tag = from_element.tag
    dest_element.text = from_element.text
    dest_element.tail = from_element.tail
    dest_element.attrib = from_element.attrib

    copied_children = []

    for elem in from_element:
        copied_children.append(copy_element(elem))

    for idx, child in enumerate(copied_children):
        dest_element.insert(idx, child)

    return dest_element
Exemplo n.º 3
0
 def tasks_to_html(self, parent, tasks):
     print tasks
     node = Element("table")
     node.attrib = {"border": "1"}
     for id, (code, date) in tasks.iteritems():
         keyTdNode1 = Element("td")
         self.data_to_html(keyTdNode1, id)
         keyTdNode2 = Element("td")
         self.data_to_html(keyTdNode2, code)
         keyTdNode3 = Element("td")
         self.data_to_html(keyTdNode3, date)
         trNode = Element("tr")
         trNode.attrib = {"valign": "top"}
         trNode.append(keyTdNode1)
         trNode.append(keyTdNode2)
         trNode.append(keyTdNode3)
         node.append(trNode)
     parent.append(node)
Exemplo n.º 4
0
 def dict_to_html(self, parent, dict):
     node = Element("table")
     for key, value in dict.iteritems():
         keyTdNode1 = Element("td")
         self.data_to_html(keyTdNode1, key)
         keyTdNode2 = Element("td")
         self.data_to_html(keyTdNode2, value)
         trNode = Element("tr")
         trNode.attrib = {"valign": "top"}
         trNode.append(keyTdNode1)
         trNode.append(keyTdNode2)
         node.append(trNode)
     parent.append(node)
def create_xmlFile(image_name, message):

    xml_path = annotation_path + '/' + image_name.split('.')[0] + '.xml'
    if not os.path.exists(xml_path):
        with open(xml_path, 'w', encoding='utf-8') as f:
            f.write()
        root = Element("annotation")
        file_name = Element('file_name')
        file_name.attrib = message[0]
        root.append(file_name)
        size = Element('size')
        root.append(size)
        width = Element('width')
        height = Element('height')
        depth = Element('depth')
        size.append(width)
        size.append(height)
        size.append(depth)
    node_object = Element('object')
    name = Element('name')
    name.attrib = message[len(message) - 1]
    node_object.append(name)
    bndbox = Element('bndbox')
    xmin = Element('xmin')
    xmin.attrib = message[1]
    ymin = Element('ymin')
    ymin.attrib = message[2]
    xmax = Element('xmax')
    xmax.attrib = message[3]
    ymax = Element('ymax')
    ymax.attrib = message[4]
    bndbox.append(xmin)
    bndbox.append(ymin)
    bndbox.append(xmax)
    bndbox.append(ymax)
    node_object.append(bndbox)
    root.append(node_object)
    tree = ET.ElementTree(root)
    tree.write(xml_path, 'utf-8')