擅长:python、mysql、java
<p>我建议一种不同的方法:将xml保存为模板,用标准Python字符串操作替换占位符。在</p>
<p>例如</p>
<pre><code>AndroidManifest_template.xml:
<meta-data android:value="%(channel_name)s" android:name="UMENG_CHANNEL"/>
python:
manifest_original_xml_fh = open("../AndroidManifest_template.xml", "r")
manifest_xml_fh = open("../AndroidManifest.xml", "w")
for each_config_line in manifest_original_xml_fh:
each_config_line = each_config_line % {'channel_name': channel_name}
print each_config_line
</code></pre>