创新设置:如何替换XML文件中的字符串? [英] Inno setup: how to replace a string in XML file?
问题描述
以下(引用)是XML文件的内容,该文件是我的软件包的一部分.
我想在安装过程中替换c:\path\myapp.exe
的值(用用户选择安装应用程序的真实路径替换).
那可能吗?怎么做?
The following (in quote) is the content of a XML file which is part of my package.
I'd like to replace the value of c:\path\myapp.exe
during the installation (with the real path where the user chose to install the application.
Is that possible? How to?
<?xml version="1.0" encoding="UTF-8"?>
<launchConfiguration type="org.eclipse.ui.externaltools.ProgramLaunchConfigurationType">
<listAttribute key="org.eclipse.debug.ui.favoriteGroups">
<listEntry value="org.eclipse.ui.externaltools.launchGroup"/>
</listAttribute>
<stringAttribute key="org.eclipse.ui.externaltools.ATTR_LAUNCH_CONFIGURATION_BUILD_SCOPE" value="${none}"/>
<stringAttribute key="org.eclipse.ui.externaltools.ATTR_LOCATION" value="c:\path\myapp.exe"/>
<stringAttribute key="org.eclipse.ui.externaltools.ATTR_TOOL_ARGUMENTS" value="${resource_loc}"/>
</launchConfiguration>
推荐答案
Your best option is to use the XML DOM to select and edit the required node as TLama suggested.
或者,您可以在要替换的位置安装带有已知字符串的模板文件. 然后可以将文件读取为字符串,进行修改,然后使用类似以下内容再次写回:
Alternatively, you can install a template file with a known string in the location you want to replace. The file can then be read as a string, modified and written back out again using something like:
[Code]
procedure WriteAppPath;
var
FileData: String;
begin
LoadStringFromFile(ExpandConstant('{app}\app.xml'), FileData);
StringChange(FileData, 'XXXXXMARKERXXXXX', ExpandConstant('{app}'));
SaveStringToFile(ExpandConstant('{app}\app.xml'), FileData, False);
end;
另请参见此问题有关对INI文件进行相同操作的问题.
See also this question about doing the same thing en masse to an INI file.
这篇关于创新设置:如何替换XML文件中的字符串?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!