0

我在 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.

有任何想法吗?

4

1 回答 1

2

不幸的是,内置的 XML 系统搜索不支持名称空间是对的。但是我对您的 XPath 感到困惑。与命名空间无关的搜索不应该仍然反映元素层次结构吗?我认为您所拥有的充其量可能会找到一个 ApplicationsSettings 元素,该元素具有一个子 Source 和一个子 Server,但请参考 ApplicationSettings 元素而不是 Server 元素。如果它完全有效。

我建议改变:

/ApplicationSettings/Source/Server

改为(未经测试):

/*[local-name() = 'ApplicationSettings']/*[local-name() = 'Source']/*[local-name() = 'Server']
于 2010-11-15T15:25:35.690 回答