【发布时间】:2015-10-23 08:56:58
【问题描述】:
您好,我正在尝试使用 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'"
请帮忙:)
【问题讨论】:
标签: xml python-2.7 minidom