使用 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>
这在这种情况下不起作用。
谢谢
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您使用的示例 xpath 引用名为
add
的元素以及名为key
的属性。在您的情况下,您正在寻找具有名为name
的属性的property
元素。接下来,由于您想要更改内部文本而不是
property
元素上的@value
属性,因此您应该删除尾随属性引用。最后,由于 NHibernate xml 有一个特定的命名空间,您必须通知 xmlpoke 使用正确的命名空间。
所以任务应该是这样的:
注意:我还没有测试过这个,但是一般的 xml/xpath 规则在这里起作用,所以我希望它能起作用。另外,可能有一种方法可以向 xmlpoke 指示指定的命名空间应该是默认的,从而消除在 xpath 中的所有各个部分添加命名空间前缀的需要。
祝你好运!
The sample xpath you're using refers to elements named
add
with attributes calledkey
. In your case you are looking forproperty
elements with attributes calledname
.Next, since you want to change the inner text and not the
@value
attribute on theproperty
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:
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!