我在安装期间使用 XmlFile 元素向 XML 文件添加元素:
<util:XmlFile Id="SetOracleDialectProperty"
Action="createElement"
ElementPath="//hibernate-configuration/session-factory"
Name="property"
Sequence="9"
File="[INSTALLLOCATION]Config\hibernate.config"
Value="NHibernate.Dialect.Oracle10gDialect"/>
我正在写入的空文件如下所示:
<hibernate-configuration xmlns="urn:nhibernate-configuration-2.2">
<session-factory>
</session-factory>
</hibernate-configuration>
运行安装程序后,我最终得到了这个:
<hibernate-configuration xmlns="urn:nhibernate-configuration-2.2">
<session-factory>
<property xmlns="">NHibernate.Dialect.Oracle10gDialect</property>
</session-factory>
</hibernate-configuration>
问题是空的 xmlns 属性覆盖了文件根节点中指定的 xmlns,因此 nhibernate 无法正确识别属性元素。
如何设置值以匹配根节点或删除 xmlns 属性?
我花了一些时间寻找答案,我发现最接近的是“做你在 MSXML 中会做的事情”,这对我没有帮助,因为它没有说明如何在 WiX 中做到这一点(例如 XmlFile 上的什么属性使用)。
编辑 为了稍微解释 Rob 的回答,在一个我可以使用漂亮格式的地方:
- 通过在 XmlConfig 元素上设置 Node="document" 来添加文档片段。
- 您必须明确设置名称空间,否则您将再次获得默认名称。
- 此外,尽管您要添加一个“文档”,但如果您指定多个元素,它似乎不起作用。您会收到一个神秘且完全无用的“安装向导提前结束”运行时错误。
所以我的固定代码如下所示:
<util:XmlConfig Id="MsSqlDialect"
Action="create"
ElementPath="//hibernate-configuration/session-factory"
File="[INSTALLLOCATION]Config\hibernate.config"
Node="document">
<![CDATA[
<property xmlns="urn:nhibernate-configuration-2.2" name="dialect">NHibernate.Dialect.Oracle10gDialect</property>
]]>
</util:XmlConfig>