我在 InstallShield 项目中使用 XML 系统搜索和 XML 文件更改。在以前的安装中,用户选择了服务器的主机名和端口。当用户再次安装时,最好显示以前的设置。这个想法是使用 XML 系统搜索功能从 XML 文件中读取值(如果存在)。
鉴于 XML 不包含任何命名空间信息,我能够完成这项工作。下面是一个没有命名空间的 XML 示例:
<?xml version="1.0" encoding="UTF-8"?>
<ApplicationSettings ProductVersion="2.4.0.0001" Version="1">
<Source Mechanism="Server">
<Server Host="127.0.0.1" Port="11111"></Server>
</Source>
</ApplicationSettings>
我用来访问 Server 元素的 XPath 查询是:
/ApplicationSettings/Source/Server
如果我添加一些命名空间信息,则 XML 系统搜索不起作用。
<?xml version="1.0" encoding="UTF-8"?>
<ApplicationSettings ProductVersion="2.4.0.0001" Version="1" xmlns="http://127.0.0.1/schema/ApplicationSetting.xsd">
<Source Mechanism="Server">
<Server Host="127.0.0.1" Port="11111"></Server>
</Source>
</ApplicationSettings>
我还尝试了以下 XPath 表达式:
/*[local-name() = 'ApplicationSettings' and *[local-name() = 'Source' and *[local-name() = 'Server']]]
这不起作用,在日志中它似乎确实找到了元素,但没有找到属性:
MSI (c) (84:C8) [10:47:17:836]: Invoking remote custom action. DLL: C:\Users\CZIETS~1\AppData\Local\Temp\MSIFF9E.tmp, Entrypoint: ISXmlAppSearch
InstallShield 10:47:17: Searching for an XML Attribute value using the Element '/*[local-name() = 'ApplicationSettings' and *[local-name() = 'Source' and *[local-name() = 'Server']]]' and the Attribute 'Host'.
InstallShield 10:47:17: Attribute 'Host' not found using the following Element: '/*[local-name() = 'ApplicationSettings' and *[local-name() = 'Source' and *[local-name() = 'Server']]]'. Check for the existence of the Attribute.
InstallShield 10:47:17: Searching for an XML Attribute value using the Element '/*[local-name() = 'ApplicationSettings' and *[local-name() = 'Source' and *[local-name() = 'Server']]]' and the Attribute 'Port'.
InstallShield 10:47:17: Attribute 'Port' not found using the following Element: '/*[local-name() = 'ApplicationSettings' and *[local-name() = 'Source' and *[local-name() = 'Server']]]'. Check for the existence of the Attribute.
Action ended 10:47:17: ISXmlAppSearch. Return value 1.
有任何想法吗?