使用nant xmlpoke更改nhibernate配置

如何使用nant从nhibernate.config文件更改连接字符串 问题是所有的例子都是关于改变属性值,但是nhibernate有内部文本 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>
    ....
我需要更改属性connection.connection_string
<xmlpoke        file="${nhibernate.file}"
        xpath="/hibernate-configuration/session-factory/add[@key='connection.connection_string']/@value"
        value="${connection.string}">
</xmlpoke>
这在这种情况下不起作用。 谢谢     
已邀请:
您正在使用的示例xpath指的是名为
add
的元素,其属性名为
key
。在你的情况下,你正在寻找具有
name
属性的
property
元素。 接下来,由于您要更改内部文本而不是
property
元素上的
@value
属性,因此应删除尾随属性引用。 最后,由于NHibernate xml具有特定的命名空间,因此您必须通知xmlpoke使用正确的命名空间。 所以任务应该是这样的:
<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>
注意:我没有对此进行测试,但是一般的xml / xpath规则在这里工作,所以我希望它有效。此外,可能有一种方法可以向xmlpoke指示指定的命名空间应该是默认的,从而消除了对xpath中所有各个部分的名称空间前缀的需要。 祝好运!     

要回复问题请先登录注册