开发者

How to use a namespace in the XPath expression in the ISXmlLocator table?

I'm using XML System Search and XML File Changes in an InstallShield project. In a previous installation a user selected a hostname and port for a server. When the user installs again it would be ideal if the previous settings are shown. The idea is to read the values from the XML file if it exists using the XML System Search feature.

I'm able to get this working given that the XML does not contain any namespace information. Here is an example of the XML without a namespace:

<?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>

The XPath query I'm using to get to the Server element is:

/ApplicationSettings/Source/Server

If I add some namespace information then the XML System Search does not wo开发者_JAVA技巧rk.

<?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>

I've also tried the following XPath expression:

/*[local-name() = 'ApplicationSettings' and *[local-name() = 'Source' and *[local-name() = 'Server']]]

This does not work and in the log it seems it does find the element, but not the attribute:

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.

Any ideas?


Unfortunately you're right that the built-in XML System Search doesn't support namespaces. However I'm confused about your XPath. Shouldn't the namespace-agnostic search still reflect the element hierarchy? I think at best the one you had might find an ApplicationsSettings element that has a child Source with a child Server, but refer to the ApplicationSettings element instead of the Server element. If it works at all.

I'd suggest changing:

/ApplicationSettings/Source/Server

into this instead (untested):

/*[local-name() = 'ApplicationSettings']/*[local-name() = 'Source']/*[local-name() = 'Server']
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜