【问题标题】:How do I set the xmlns attribute when using XMLFile in Wix 3在 Wix 3 中使用 XMLFile 时如何设置 xmlns 属性
【发布时间】: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>

【问题讨论】:

    标签: wix wix3


    【解决方案1】:

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

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

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

    【讨论】:

      【解决方案2】:

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

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2019-07-08
        • 2018-05-11
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多