tags:

views:

543

answers:

1

I am adding elements to an XML file during installation using the XmlFile element:

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

The empty file I am writing to looks like this:

<hibernate-configuration xmlns="urn:nhibernate-configuration-2.2">
  <session-factory>
  </session-factory>
</hibernate-configuration>

After running the installer I end up with this:

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

The problem is that the empty xmlns attribute is overriding the xmlns specified in the root node of the file so the property element is not recognised correctly by nhibernate.

How can I either set the value to match the root node or remove the xmlns attribute?

I have spent some time searching for an answer and the closest I've found is "do what you would do in MSXML" which doesn't help me as it doesn't say how to do it in WiX (e.g. what attribute on XmlFile to use).

EDIT To explain Rob's answer slightly, in a place where I can use nice formatting:

  • You add a document fragment by setting Node="document" on the XmlConfig element.
  • You have to explicitly set the namespace otherwise you get the default one again.
  • Also although you're adding a "document" it doesn't seem to work if you specify more than one element. You get a mysterious and thoroughly unhelpful "Setup wizard ended prematurely" runtime error.

So my fixed code looks like this:

<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>
+1  A: 

The problem here is that MSXML states that createElement will always give you the default namespace (just as you are seeing). I think you'll need to switch to the more complex but more powerful XmlConfig. In this case, try using a document fragment to add the entire element with correct namespace instead of depending on MSXML to create it for you.

Rob Mensching