您好我正在尝试使用Python minidom更新以下XML中的属性NumberOfArg
。
<?xml version="1.0" encoding="utf-8"?>
<BootUpdaterGenerator OffsetImagesAddress="0x15000">
<!--Offset of Images Start Address (0xXX hexa, XX decimal)-->
<Locations>
<!--All Locations are relative to PIS parameter-->
<S19MapPath Name="out\code">
<!--Relative Path of .s19 and .map file-->
</S19MapPath>
<CnfPath Name="work\bsw\products\cnf\icsp_lifm\i">
<!--Relative Path of icsp_lifm_cnf.arxml file-->
</CnfPath>
<BuildDirPath Name="work\config\builddescription">
<!--Relative Path of builddescription.xml file-->
</BuildDirPath>
<CksCalcXmlPath Name="work\config\ckscalc\ckscalc_0b0.xml">
<!--Relative Full Path of ckscalc.xml file-->
</CksCalcXmlPath>
<ToolsDrive Name="A">
<!--Drive location for CKS_Calc and SignCalc-->
</ToolsDrive>
</Locations>
<SizeCoherencies>
<BootManager Size="0xF">
<!--Size of BootManager Coherency (0xXX hexa, XX decimal)-->
</BootManager>
<BootLoader Size="0x24">
<!--Size of BootLoader Coherency (0xXX hexa, XX decimal)-->
</BootLoader>
</SizeCoherencies>
<Sign_Tool Command="signcalc.exe" Path="A:\deltools\signcalc\12" Arg1=".\ckscalc_u.xml" Arg2="-L" NumberOfArg="1" />
<Options Checksum="yes" Signature="no" DeleteEmptyPage="no" DeleteEmptyPageSize="250" ImagesId="1">
<!--Checksum : "yes" or "no" depending on whether CKS_CALC on Output File is required or not-->
<!--Signature (not implemented) : "yes" or "no" depending on whether Signature on Output File is required or not-->
<!--DeleteEmptyPage : "yes" or "no" depending on whether Empty Pages have to be deleted from images or not-->
<!--DeleteEmptyPageSize : "value" size of Empty Page for deletion (0xXX hexa, XX decimal)-->
<!--ImagesId : Images loaded in BootUpdater : 1 : BootLoader, 2 : BootManager + BootLoader, 3 : HSM-->
</Options>
</BootUpdaterGenerator>
这是我到目前为止所做的:
rootNode = xml.dom.minidom.parse(buGeneratorXmlFile)
collection = rootNode.documentElement
signToolNode = collection.getElementsByTagName('Sign_Tool')
att = signToolNode[0].attributes.getNamedItem('NumberOfArg')
att.value = 2
#Update file
with open('test', "w") as f:
rootNode.writexml(f, encoding='UTF-8')
但是我收到了关于writexml的错误:
AttributeError: "'int' object has no attribute 'replace'"
请帮助:)
答案 0 :(得分:0)
遇到了问题! att.value
必须设置为str而不是int,因此att.value = '2'
可以工作:)