问题描述
在我的inno设置脚本中,有一个[code]部分,我需要在其中添加一些代码:
In my inno setup script there is a [code] section and I need to add some code to:
- 打开xml文件
- 然后在特定位置添加一个节点
- 将文件保存回硬盘驱动器
我需要能够在\ documents \ docotype中编辑一个名为config.xml的文件
I need to be able to edit a file called config.xml in \documents\docotype
文件中有一些类似这样的代码:
in the file there is some code like this:
<References>
<ArrayOfString xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<string>System.dll</string>
<string>System.Core.dll</string>
<string>System.Drawing.dll</string>
<string>System.Windows.Forms.dll</string>
<string>System.XML.dll</string>
</ArrayOfString>
</References>
我需要它看起来像这样:
I need it to look like this:
<References>
<ArrayOfString xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<string>System.dll</string>
<string>System.Core.dll</string>
<string>System.Drawing.dll</string>
<string>System.Windows.Forms.dll</string>
<string>System.XML.dll</string>
<string>C:\\bin\Custom\cutty109.dll</string>
</ArrayOfString>
</References>
所以实际上我只需要在"ArrayOfString"部分的文件中添加以下行
So really I just need to add the following line into the file in the 'ArrayOfString' section
<string>C:\\bin\Custom\cutty109.dll</string>
我敢肯定这是有可能的,但是我不知道怎么做.
I'm sure this must be possible but I have no clue how..
谢谢
推荐答案
请参考 CodeAutomation.iss示例与inno install一起提供.并使用此代码代替修改XML文档"部分下的原始代码.
Please refer the CodeAutomation.iss example provided along with inno install. And use this code instead the original code under the 'Modify the XML document' section.
{ Modify the XML document }
NewNode := XMLDoc.createElement('string');
XMLDoc.setProperty('SelectionLanguage', 'XPath');
RootNode := XMLDoc.selectSingleNode('//References/ArrayOfString');
RootNode.appendChild (NewNode);
RootNode.lastChild.text :='C:\\bin\Custom\cutty109.dll';
{ Save the XML document }
这篇关于使用inno设置将节点添加到现有XML文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!