[在此处输入图像描述][1]。你知道吗
如何分别获取regname,type。。。在python中。我需要得到类型值和地址分别。你知道吗
for regfile in root.findall('regfile'):
reg_value = regfile.find('reg').text
print(reg_value)
for reg in regfile.findall('reg'):
name = reg.find('name').text
type = reg.find('text').text
我试过了,但它抛出了类似“AttributeError:'NoneType'对象没有属性'text'”的错误
<regfile regfilename="blkreq" type="blk_required_v2_rdl_rf_t" num="1" addr="0x0" incr="0x8">
<name><![CDATA[blk_required_v2_rdl_rf_t]]></name>
<description><![CDATA[]]></description>
<property name="num" value="1"/>
<reg regname="uid_v2" type="block_uid_v2_t" num="1" addr="0x4" incr="0x4">
<name><![CDATA[Block Unique ID Type]]></name>
<description><![CDATA[The IPID and the Platform Type together provides Unique ID of an IP]]></description>
<property name="msbhigh" value="1"/>
<property name="num" value="1"/>
<property name="retention" value=""/>
<property name="width" value="32"/>
<property name="shared" value="0"/>
<property name="accesswidth" value="8"/>
<field fieldname="ipid">
<name><![CDATA[Design IP Identification]]></name>
<description><![CDATA[This is reserved for future use.]]></description>
<msb>31</msb>
<lsb>8</lsb>
<property name="hw_r" value="1"/>
<property name="reset" value="0h"/>
<property name="retention" value=""/>
<property name="sw_r" value="1"/>
<property name="width" value="0"/>
</field>
<field fieldname="platform">
<name><![CDATA[Platform]]></name>
<description><![CDATA[Implementation for the specific platform class (asic, fpga, vp, etc) - supplied
a global parameter, PLATFORM_TYPE, by the RTL and defined in the platform package in DVI_LIB.
The reset value shall reflect the configuration.]]></description>
<msb>3</msb>
<lsb>0</lsb>
<property name="hw_w" value="1"/>
<property name="reset" value=""/>
<property name="retention" value=""/>
<property name="sw_r" value="1"/>
<property name="width" value="0"/>
</field>
</reg>
您可以使用
xml.etree.ElementTree
包将xml代码解析到树中,并按以下方式对其进行迭代:child.attrib
是一个字典:您可以通过child.attrib["type"]
简单地获得特定的属性类型。看看这个复制对于live example。你知道吗编辑-根据以下评论中的要求:
使用get方法可以得到属性。你知道吗
相关问题 更多 >
编程相关推荐