4

我在安装期间使用 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>
4

2 回答 2

2

我知道这是几年后的事了,但如果其他人遇到这个问题,我认为真正的解决方案是:

<util:XmlFile Id="SetOracleDialectProperty"
              Action="createElement"
              ElementPath="//hibernate-configuration/session-factory"
              Name="urn:nhibernate-configuration-2.2:property"
              Sequence="9"
              File="[INSTALLLOCATION]Config\hibernate.config"
              Value="NHibernate.Dialect.Oracle10gDialect"/>

change is from Name="property"to Name="urn:nhibernate-configuration-2.2:property"- 当配置被写入时,它会出现,就像它会识别它是默认命名空间一样。我在调整清单文件时遇到了同样的问题,这种方法对其进行了排序。

于 2012-04-14T19:02:05.177 回答
1

这里的问题是 MSXML 声明 createElement 将始终为您提供默认命名空间(正如您所见)。我认为您需要切换到更复杂但更强大的 XmlConfig。在这种情况下,请尝试使用文档片段来添加具有正确命名空间的整个元素,而不是依赖 MSXML 为您创建它。

于 2009-08-27T01:00:52.827 回答