Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/wix/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在Wix 3中使用XMLFile时,如何设置xmlns属性_Wix_Wix3 - Fatal编程技术网

在Wix 3中使用XMLFile时,如何设置xmlns属性

在Wix 3中使用XMLFile时,如何设置xmlns属性,wix,wix3,Wix,Wix3,在安装过程中,我使用XmlFile元素向XML文件添加元素: <util:XmlFile Id="SetOracleDialectProperty" Action="createElement" ElementPath="//hibernate-configuration/session-factory" Name="property" Sequence="9"

在安装过程中,我使用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>
<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>

运行安装程序后,我最终得到以下结果:

<hibernate-configuration xmlns="urn:nhibernate-configuration-2.2">
  <session-factory>
    <property xmlns="">NHibernate.Dialect.Oracle10gDialect</property>
  </session-factory>
</hibernate-configuration>

NHibernate.方言
问题是空的xmlns属性覆盖了文件根节点中指定的xmlns,因此nhibernate无法正确识别property元素

如何设置与根节点匹配的值或删除xmlns属性

我花了一些时间搜索答案,我发现最接近的答案是“在MSXML中做你想做的事”,这对我没有帮助,因为它没有说明如何在WiX中做这件事(例如,在XmlFile中使用什么属性)

编辑 为了稍微解释一下Rob的答案,在一个我可以使用良好格式的地方:

  • 通过在XmlConfig元素上设置Node=“document”,可以添加文档片段
  • 必须显式设置名称空间,否则将再次获得默认名称空间
  • 另外,尽管您正在添加一个“文档”,但如果您指定了多个元素,它似乎不起作用。您会遇到一个神秘且毫无帮助的“安装向导过早结束”运行时错误
因此,我的固定代码如下所示:

<hibernate-configuration xmlns="urn:nhibernate-configuration-2.2">
  <session-factory>
  </session-factory>
</hibernate-configuration>
<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>

NHibernate.方言
]]>

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

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

<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”
——编写配置时,它会像识别默认名称空间一样显示。我在调整清单文件时遇到了同样的问题,这种方法将其排序