XmlFile UpdateElement don't wants to update inner text

Sep 2, 2011 at 12:37 PM

Hi.

I have config file (hibernate.cfg.xml) looks like this:

<?xml version="1.0" encoding="utf-8"?>
<hibernate-configuration  xmlns="urn:nhibernate-configuration-2.2" >
  <session-factory>
    <property name="proxyfactory.factory_class">NHibernate.ByteCode.Castle.ProxyFactoryFactory, NHibernate.ByteCode.Castle</property>
    <property name="cache.use_query_cache">true</property>
    <property name="connection.provider">NHibernate.Connection.DriverConnectionProvider</property>
    <property name="dialect">NHibernate.Dialect.MsSql2008Dialect</property>
    <property name="connection.driver_class">NHibernate.Driver.SqlClientDriver</property>
    <property name="connection.connection_string">MyConnectionString</property>
    <property name="max_fetch_depth">1</property>

    <property name="command_timeout">180</property>
    <!-- YOU CAN HAVE MULTIPLE MAPPING ASSEMBLIES HERE -->
    <mapping assembly="SmartDrive.Data.NHibernateData" />
  </session-factory>
</hibernate-configuration>

I want to update MyConnectionString value to the new one and use the following code:

<MSBuild.ExtensionPack.Xml.XmlFile
      TaskAction="UpdateElement"
      File="$(DropLocation)\$(BuildNumber)\Release\hibernate.cfg.xml"
      XPath="/hibernate-configuration[@xmlns='urn:nhibernate-configuration-2.2']/session-factory/property[@name='connection.connection_string']"
      InnerText="MyNewConnString"/>

Log shows that target was executed successfully, but value was not changed in target file. I tried other Actions (AddElement etc.) with this file, but with the same result. With other config file this actions works fine.

P.S. I used the 4.0.3 version of components.

Coordinator
Sep 4, 2011 at 11:20 AM

You need to specify the namespace. 

 

    <ItemGroup>
        <Namespaces Include="Mynamespace">
            <Prefix>x</Prefix>
            <Uri>urn:nhibernate-configuration-2.2</Uri>
        </Namespaces>
    </ItemGroup>
    <Target Name="DefaultWithNameSpace">
        <MSBuild.ExtensionPack.Xml.XmlFile TaskAction="UpdateElement" 
                                           File="d:\a\hibernate.cfg.xml" 
                                           XPath="/x:hibernate-configuration/x:session-factory/x:property[@name='connection.connection_string']"
                                           InnerText="MyNewConnString" 
                                           Namespaces="@(Namespaces)"/>
    </Target>

Regards

Mike

 

Sep 5, 2011 at 7:21 AM

Thanks. Works great.