一般用ElementTree包
import xml.etree.ElementTree as ET
首先传入xml文件名,创建解析对象:
tree = ET.parse(xml_file)
然后获取根结点:
root = tree.getroot()
获取了根结点,也就是整个xml的根结点,就可以用
findall
来找子结点
比如找到’object’结点
root.findall("object")
,此时返回的是
所有object结点的list
,可以用index选择其中一个进行下一步操作
以下面这个xml为例
<annotation>
<folder>jpg</folder>
<filename>001801.jpg</filename>
<path>D:\part4_Picture\2019-7-8\wuhan_3\jpg\001801.jpg</path>
<source>
<database>Unknown</database>
</source>
<width>4608</width>
<height>2592</height>
<depth>3</depth>
</size>
<segmented>0</segmented>
<object>
<name>lsqxz</name>
<pose>Unspecified</pose>
<truncated>0</truncated>
<difficult>0</difficult>
<bndbox>
<xmin>2000</xmin>
<ymin>1236</ymin>
<xmax>2057</xmax>
<ymax>1298</ymax>
</bndbox>
</object>
</annotation>
object这个结点下面还有子结点,name,poe,bndbox等等
我们可以遍历所有的object结点,对每个Object结点进行分析
for obj in root.findall("object"):
cls_name = obj.findall("name")[0].text
bbox = obj.findall("bndbox")[0]
xmin = bbox.findall("xmin")[0].text
ymin = bbox.findall("ymin")[0].text
This method is used to find a specific single element in the document. It is essentially equivalent to calling the .find()method on the document's root element;
# encoding:utf-8
import xml.etree.ElementTree as ET
from xml.dom.minidom import parseString
import codecs
import sys
def get_xml_dict(source_file_name...
minixml常用函数接口:均需包含头文件#include mxml.h
mxml_node_t *mxmlFindElement(mxml_node_t *node, mxml_node_t *top,const char *name, const char *attr,const char *value, int descend);
desc:
node节点为被查找的结点
top为顶层结点
name, attrr, value为NULL时表示任意匹配; 否则为
MLP和Cross Attention的关系 (参考Memory-Space Visual Prompting for Efficient Vision-Language Fine-Tuning)
Classifier guidance与Classifier free diffusion的简单理解
Monkey: Image Resolution and Text Label Are Important Things for Large Multi-modal Models