在XML文件中找不到节点

时间:2019-01-14 07:26:31

标签: xml xpath wix windows-installer

我有一个安装程序,需要通过该安装程序来更新XML文件。我已经做了很多这类的事情来更新应用程序配置文件。但是此XML文件几乎没有什么不同,我在查找节点方面面临着一个问题。我不知道为什么它不起作用。我下面有XML:

<?xml version="1.0" encoding="utf-8"?>
<Siemens.Automation.Diagnostics 

 xmlns="http://www.siemens.com/Automation/2004/09/Diagnostics/ReportConfiguration">
       <Report IncludeConfigFile="true" IncludeHtml="true" DisplayName="Red White Application" TargetVersion="1.0.0">
        <MergePlugIns>
          <MergePlugIn Path="Siemens.Automation.Diagnostics.PlugIn.dll" Type="Siemens.Automation.Diagnostics.PlugIn.ConfigurationMerger" />
        </MergePlugIns>

      </Report>
    </Siemens.Automation.Diagnostics>

我想更新MergePlugin的Type值,但我面临问题。下面是我在做什么:

<util:XmlFile Id="UpdateProductName" Action="setValue" File="[ERRORREPORT]$(var.ErrorReportAdrFile)"
                      ElementPath="/Siemens.Automation.Diagnostics[\[]@xmlns='http://www.siemens.com/Automation/2004/09/Diagnostics/ReportConfiguration'[\]]/Report[\[]@DisplayName='Red White Application'[\]]/MergePlugIns/MergePlugIn[\[]@Path='Siemens.Automation.Diagnostics.PlugIn.dll'[\]]/@Type"
                      SelectionLanguage="XPath" Permanent="yes" Value="HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\SIPLACE\$(var.ProductName)"/>

但是它给出了一个错误,即找不到节点。我想念的是什么?

1 个答案:

答案 0 :(得分:1)

当元素名称包含句点(".")时,某些XPath库会遇到问题。

鉴于this answer中的解决方法,您必须替换XPath的第一部分:

/Siemens.Automation.Diagnostics

作者

/*[name(.)='Siemens.Automation.Diagnostics']

并且对于MSI格式的字段进行适当的转义,答案最终是:

/*[\[]name(.)='Siemens.Automation.Diagnostics'[\]]

粘贴到此online XPath tester中后,它会成功。