【发布时间】:2009-08-26 21:34:40
【问题描述】:
我在安装期间使用 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>
【问题讨论】: