无法在 XML 文件中找到节点 [英] Unable to find node in XML file

查看:41
本文介绍了无法在 XML 文件中找到节点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个安装程序,我需要通过它来更新 XML 文件.我已经做了很多次这些事情来更新应用程序配置文件.但是这个 XML 文件几乎没有什么不同,我在寻找节点时遇到了问题.我不知道为什么它不起作用.我有以下 XML:

<Report IncludeConfigFile="true" IncludeHtml="true" DisplayName="Red White Application" TargetVersion="1.0.0"><合并插件><MergePlugIn Path="Siemens.Automation.Diagnostics.PlugIn.dll" Type="Siemens.Automation.Diagnostics.PlugIn.ConfigurationMerger"/></MergePlugIns></报告></Siemens.Automation.Diagnostics>

我想更新 MergePlugin 值的类型,但我遇到了问题.以下是我在做什么:

<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='红白应用'[\]]/MergePlugIns/MergePlugIn[\[]@Path='Siemens.Automation.Diagnostics.PlugIn.dll'[\]]/@Type"SelectionLanguage="XPath" Permanent="yes" Value="HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\SIPLACE\$(var.ProductName)"/>

但它给出了无法找到节点的错误.我错过了什么?

解决方案

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

鉴于此答案的解决方法,您必须替换 XPath 的第一部分:

<块引用>

/Siemens.Automation.Diagnostics

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

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

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

粘贴到此在线 XPath 测试器时成功.

I have a installer through which i need to update an XML file. I have done these kinds of stuff many time to update application config files. But this XML file is little different and i am facing an issue to find the node. I don't know why it is not working. I have below 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>

I want to update Type of MergePlugin value but i am facing issue. Below is what i am doing:

<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)"/>

But it gives an error that unable to find node. What i am missing?

解决方案

Some XPath libraries have trouble when element names contain period (".").

Given the workaround from this answer, you have to replace the first part of your XPath:

/Siemens.Automation.Diagnostics

by

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

and with proper escaping for MSI formatted field the answer finally is:

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

It succeeds when pasted in this online XPath tester.

这篇关于无法在 XML 文件中找到节点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆