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

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>

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.

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.

Related

how to resolve burn variables in the bootstrap xml

One of my goals in creating the bootstrap project is to set a default log location. I would like the location to be based on the local app data folder. I cannot figure out how to reference the builtin Burn variable LocalAppDataFolder. I have found information about how to reference these variables in code, but not in the xml.
The reference to the property looks like this:
<MsiPackage SourceFile="MyInstaller.msi" LogPathVariable="[LogLocation]" />
The property is set like this:
<Variable Name="LogLocation" Value="[LocalAppDataFolder]MyLogFolder\Setup" Type="string"/>
The log output shows:
Initializing string variable 'LogLocation' to value
'[LocalAppDataFolder]MyLogFolder\Setup'
What am I missing to resolve [LocalAppDataFolder] ?
thanks in advance.
It's normal for the log output to show the un-formatted value, so that part looks correct. I think what you are missing is LogPathVariable should be specified without the brackets.
<MsiPackage SourceFile="MyInstaller.msi" LogPathVariable="LogLocation" />

XPath for web.config applicationSettings webdeploy parameters.xml file is not correct

I use webdeploy to deploy my web site project with a parameters.xml file I have been using a for a while. So far the parameters I've added are all element attributes and it all works well. But I am trying to get the xpath right to update an applicationSettings element value (not attributes) and am failing, badly, to work out if its my poor xpath skills to blame or a misunderstanding of the way the parameters file works.
When I do a deployment the field is not updated, it compiles fine and no errors\warnings during deployment. I want to be able to set this to True or False.
So I have following parameters field
<parameter name="ShowExceptionCallStackOnErrorView" description="Display a call stack on the UI Error view - true for debug only." defaultValue="False" tags="">
<parameterEntry kind="XmlFile" scope="\\web.config$" match="/configuration/applicationSettings/abc.123.Properties.Settings/setting[#name='ShowExceptionCallStackOnErrorView']/value" />
</parameter>
trying to match to the following application settings section
<configuration>
<applicationSettings>
<abc.123.Properties.Settings>
<setting name="ShowExceptionCallStackOnErrorView" serializeAs="String">
<value>True</value>
Any help would be much appreciated!
It's not giving you an error because it is simply not finding a match to replace. You need to add /text() to the end of your match tag if you want it to replace the contents of the value tag. As follows...
<parameter name="ShowExceptionCallStackOnErrorView" description="Display a call stack on the UI Error view - true for debug only." defaultValue="False" tags="">
<parameterEntry kind="XmlFile" scope="\\web.config$" match="/configuration/applicationSettings/abc.123.Properties.Settings/setting[#name='ShowExceptionCallStackOnErrorView']/value/text()" />
</parameter>

Ant loadfile override property

I'm trying to use the Ant task <loadfile> in a loop to parse the contents of a file. I have something like
<loadfile srcFile="#{some.input}" property="my.property">
Since Ant properties are immutable, this doesn't work for me. I need 'my.property' to update on every iteration. Is there a way to achieve this? I know Ant-contrib has a <var> task but I'm not sure how to use <loadfile> with it.
Any recommendations?
Thanks.
<loadfile property="foo" srcfile="bar.txt"/>
... do some actions, perhaps in a <for> loop ...
<var name="foo" unset="true"/>
You can then use foo again in <loadfile>
The Ant plugin Flaka provides a let task, allowing to overwrite existing properties or variables like that =
<project xmlns:fl="antlib:it.haefelinger.flaka">
<property name="my.property" value="value"/>
<fl:let> my.property ::= 'anothervalue'</fl:let>
</project>
So no need to unset first and set afterwards. btw. Flaka has a unset task also ;-)
Ant contrib also has a var task that unsets.
Lucks: It is convention to accept one of the answers so people know the question is resolved. I recommend you accept Gilbert's since he post a correct answer first.
One of the built-in tasks that are able to override the property value is script.
Below is a script and the output that proves the property value changed.
<project name="test">
<property name="bshJar" value="C:\lang\java\bsh-1.3.0.jar:C:\lang\java\bsf.jar:C:\lang\java\commons-logging-1.1.1.jar" />
<property name="a" value="first" />
<echo>a=${a}</echo>
<script manager="bsf" language="beanshell" classpath="${bshJar}"><![CDATA[
project.setProperty("a", "fourth");
]]></script>
<echo>a=${a}</echo>
</project>
Output:
a=first
a=fourth
I just ended up using the <unset> task provided by Antelope
http://antelope.tigris.org/
Did you try the script in ANT.
<script language="javascript">
project.setProperty("my.property", "somevalue");
</script>
You could create a new property in your MacroDef for each srcFile:
<loadfile srcFile="#{some.input}" property="#{some.input}_Prop">
<echo message="#{some.input} Contents: ${#{some.input}_Prop}"/>

Change nhibernate config with nant xmlpoke

How can I change the connection string from nhibernate.config file using nant
the problem is that all examples are about changing attribute value, but nhibernate has inner text
eq:
<hibernate-configuration xmlns="urn:nhibernate-configuration-2.2">
<session-factory>
<property name="connection.connection_string">Data Source.\server;Database=UnitTestDb;UID=user;pwd=pass;</property>
<property name="dialect">NHibernate.Dialect.MsSql2008Dialect</property>
<property name="connection.provider">NHibernate.Connection.DriverConnectionProvider</property>
<property name="connection.driver_class">NHibernate.Driver.SqlClientDriver</property>
<property name="show_sql">true</property>
<property name="connection.release_mode">auto</property>
<property name="adonet.batch_size">500</property>
....
I need to change property connection.connection_string
<xmlpoke file="${nhibernate.file}"
xpath="/hibernate-configuration/session-factory/add[#key='connection.connection_string']/#value"
value="${connection.string}">
</xmlpoke>
this does not work in this case.
Thanks
The sample xpath you're using refers to elements named add with attributes called key. In your case you are looking for property elements with attributes called name.
Next, since you want to change the inner text and not the #value attribute on the property element you should remove the trailing attribute reference.
And finally, since the NHibernate xml has a specific namespace you will have to inform xmlpoke to use the correct namespace.
So the task should look like this:
<xmlpoke file="${nhibernate.file}"
xpath="/nhc:hibernate-configuration/nhc:session-factory/nhc:property[#name='connection.connection_string']"
value="${connection.string}">
<namespaces>
<namespace prefix="nhc" uri="urn:nhibernate-configuration-2.2" />
</namespaces>
</xmlpoke>
Note: I've not tested this out, but general xml/xpath rules are in work here so I hope it works. Also, it could be that there is a way to indicate to xmlpoke that the specified namespace should be the default and thus eliminate the need to namespace prefix all the various parts in the xpath.
Good luck!

nhibernate datasource sqlite relative filepath

I have the following nhibernate cfg file:
<property name="connection.provider">NHibernate.Connection.DriverConnectionProvider</property>
<property name="connection.driver_class">NHibernate.Driver.SQLite20Driver</property>
<property name="connection.connection_string">Data Source=dbFile.db;Version=3</property>
<property name="dialect">NHibernate.Dialect.SQLiteDialect</property>
However this creates and references dbFile.db in the bin/Debug folder. I was wondering if there is any way to refernce another folder i.e. something like .../app/database/dbFile.db?
Thanks in advance
You can set the connection string property from c# code. You have to do this before you call the Configure() method.
var configuration = new Configuration();
config.SetProperty(NHibernate.Cfg.Environment.ConnectionString, myCustomDbPath);
configuration.Configure();
Hope that helps.
Maybe you can use DataDirectory-Property to start from the Exe-Path:
Data Source=|DataDirectory|../app/database/dbFile.db;Version=3
or
Data Source=jdbc:sqlite:../app/database/path.db;Version=3
Edit: After some googling i found out that this probably won't work. if not i would go with striders solution setting the property at runtime.