Dan
Dan

Reputation: 7744

How do I set the xmlns attribute when using XMLFile in Wix 3

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:

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>

Upvotes: 4

Views: 3009

Answers (2)

James Horsley
James Horsley

Reputation: 41

I know this is years later but if anyone else comes across this I think the true solution is this:

<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" - when config is written it will apprear as just as it will recognize it is the default namespace. I had the same problem adjusting manifest files and this approach sorted it.

Upvotes: 2

Rob Mensching
Rob Mensching

Reputation: 35976

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.

Upvotes: 1

Related Questions