如何在安装过程中将大于和小于字符插入 WiX 修改的 XML 文件中?

发布于 2024-09-13 17:35:30 字数 1952 浏览 1 评论 0原文

我正在使用 WiX 为我的应用程序编写 Windows 安装数据库。我有一个与我的应用程序一起安装的 XML 文件,该文件需要填充安装过程中获得的信息。 WiXUtilExtension 标签 util:XmlFileutil:XmlConfig 原则上是执行此操作的好方法,但它们并不能完全解决我的问题。具体来说,我需要插入一些 javascript:

<?js
    //some javascript that must include formatted string properties
    //so that [PropertyName] evaluates to its value during installation
?>

但将该文本作为 util:XmlFile/@Value 属性的值,它将无法编译(毫不奇怪 - 错误 CNDL0104)。反斜杠和 [\ ](方括号的转义序列)似乎都无法转义大于或小于字符。

我还尝试将插入的文本放入 util:XmlConfig 元素的内部文本中,但由于存在 Javascript 标记,它只是忽略该文本。将内部文本包装在 CDATA 标记中会插入文本,但会将大于和小于字符替换为其实体“& gt;”和“& lt;”,不带引号和空格。

有什么窍门呢?

编辑:仍在努力解决这个问题,但更多细节可能有助于进一步澄清。下面是一个 XML 文件的示例,其结构是我需要在安装时修改的。

<?xml version="1.0"?>
<RootElement>
    <SubElement>
        <?js
            //insert Javascript here with formatted property values e.g. [PropertyName]
        ?>
    </SubElement>
</RootElement>

在我的 WiX 代码中,我有:

<util:XmlConfig Id="EditXml" File="foo.xml" Action="create" Node="value" On="install" ElementPath="//RootElement/SubElement" Sequence="1" >
    <![CDATA[//the Javascript code]]>
</util:XmlConfig>

当然,它将文本放置在 Javascript 处理指令旁边,而不是放在其中。因此,我研究了使用 XPath 访问 XML 处理指令标签,认为也许我不是使用 util:XmlConfig/@ElementPath 属性的正确值。我以前从未使用过 XPath,但我认为以下更改之一会起作用:

ElementPath="//RootElement/SubElement/processing-instruction('js')"
ElementPath="processing-instruction('js')//RootElement/SubElement"
ElementPath="//processing-instruction('js')"
ElementPath="processing-instruction('js')"

但无济于事。我只是使用这种语法,还是还有其他解决方案?

预先感谢您的帮助!

I'm using WiX to author a Windows Installation database for my application. I've got an XML file that is installed along with my app, which needs to be filled with information obtained during installation. The WiXUtilExtension tags util:XmlFile and util:XmlConfig are great ways to do this, in principle, but they don't quite solve my problem. Specifically, I need to insert some javascript:

<?js
    //some javascript that must include formatted string properties
    //so that [PropertyName] evaluates to its value during installation
?>

but with that text as the value of the util:XmlFile/@Value attribute, it won't compile (no surprise - error CNDL0104). And neither backslash nor [\ ] (escape sequence for square bracket) seem to escape the greater-than or less-than characters.

I also tried placing the inserted text into the inner text of the util:XmlConfig element, but with the Javascript tag present, it just ignores the text. Wrapping the inner text in CDATA tags inserts the text, but replaces the greater- and less-than characters with their entities "& gt;" and "& lt;", without the quotes and spaces.

What's the trick?

EDIT: Still struggling with this problem, but some more details might help clarify further. Here's an example of an XML file with the structure I need to modify on install.

<?xml version="1.0"?>
<RootElement>
    <SubElement>
        <?js
            //insert Javascript here with formatted property values e.g. [PropertyName]
        ?>
    </SubElement>
</RootElement>

In my WiX code, I had:

<util:XmlConfig Id="EditXml" File="foo.xml" Action="create" Node="value" On="install" ElementPath="//RootElement/SubElement" Sequence="1" >
    <![CDATA[//the Javascript code]]>
</util:XmlConfig>

which, of course, placed the text next to the Javascript processing instruction, rather than within it. So I looked into accessing XML processing instruction tags with XPath, thinking that perhaps I wasn't using the correct value for the util:XmlConfig/@ElementPath attribute. I've never used XPath before, but I thought one of the following changes would work:

ElementPath="//RootElement/SubElement/processing-instruction('js')"
ElementPath="processing-instruction('js')//RootElement/SubElement"
ElementPath="//processing-instruction('js')"
ElementPath="processing-instruction('js')"

but to no avail. Am I just off with this syntax, or is there another solution altogether?

Thanks in advance for the help!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

心欲静而疯不止 2024-09-20 17:35:30

我没有工具来验证这是否有效,但我会尝试将它们替换为它们的实体(><),但是不要不要将其包装在 CDATA 块中。实体本质上是原始 XML 的“转义序列”。

I don't have the tools to verify that this works, but I would try replacing them with their entities (> and <), but don't wrap it in a CDATA block. Entities essentially are the "escape sequence" for raw XML.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文