isu*_*anu 2 nant nhibernate xmlpoke
如何使用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>
....
Run Code Online (Sandbox Code Playgroud)
我需要更改属性connection.connection_string
<xmlpoke file="${nhibernate.file}"
xpath="/hibernate-configuration/session-factory/add[@key='connection.connection_string']/@value"
value="${connection.string}">
</xmlpoke>
Run Code Online (Sandbox Code Playgroud)
这在这种情况下不起作用.
谢谢
您正在使用的示例xpath指的是使用add被称为属性命名的元素key.在您的情况下,您正在寻找property具有所谓属性的元素name.
接下来,由于您要更改内部文本而不是元素@value上的属性,因此property应删除尾随属性引用.
最后,由于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>
Run Code Online (Sandbox Code Playgroud)
注意:我没有对此进行测试,但是一般的xml/xpath规则在这里工作,所以我希望它有效.此外,可能有一种方法可以向xmlpoke指示指定的命名空间应该是默认的,从而消除了对xpath中所有各个部分的名称空间前缀的需要.
祝好运!
| 归档时间: |
|
| 查看次数: |
1690 次 |
| 最近记录: |