close

from xml.dom.minidom import Document

def WriteXML():
    doc = Document()
    annotation = doc.createElement('annotation')
    doc.appendChild(annotation)
    
    title = doc.createElement('Title')
    title_text = doc.createTextNode('Write Data in XML File')
    title.appendChild(title_text)
    annotation.appendChild(title)
    
    fname = '1.xml'
    with open('C:\ '+ fname, 'w') as f:
        doc.writexml(f, indent='\t', newl='\n', addindent='\t', encoding='utf-8')
    f.close

結果如下圖:

 

 

 

def WriteXML():
    doc = Document()
    annotation = doc.createElement('annotation')
    doc.appendChild(annotation)
    
    title = doc.createElement('Title')
    title_text = doc.createTextNode('Write Data in XML File')
    title.appendChild(title_text)
    annotation.appendChild(title)
    
    Box = doc.createElement('Box')
    rect = doc.createElement('RectType')
    rect_text = doc.createTextNode('RECT')
    rect.appendChild(rect_text)
    Box.appendChild(rect)
    width = doc.createElement('width')
    width_text = doc.createTextNode('360')
    width.appendChild(width_text)
    Box.appendChild(width)
    height = doc.createElement('height')
    height_text = doc.createTextNode('240')
    height.appendChild(height_text)
    Box.appendChild(height)
    annotation.appendChild(Box)
    
    fname = '1.xml'
    with open('C:\pythonwork-gpu\Faster-RCNN\ '+ fname, 'w') as f:
        doc.writexml(f, indent='\t', newl='\n', addindent='\t', encoding='utf-8')
    f.close

結果如下圖:

 

 

arrow
arrow
    文章標籤
    python python3.x xml write
    全站熱搜

    楓綺 發表在 痞客邦 留言(0) 人氣()