Nant 中的 xmlpoke - 如何更新找到的字符串的所有实例
您好,我在 Nant 构建脚本中使用 Xpath 来更改开发环境和其他环境之间的一些配置变量。
我从这个例子中获取了语法:
这个例子看起来像这样:
<xmlpoke
file="config01/app.config"
xpath="/configuration/appSettings/add[@key='AppName']/@value"
value="TradeMonster">
</xmlpoke>
我想要的是与此类似的东西来搜索我的连接字符串并找到“localhost\SqlExpress”的所有实例,然后将它们更改为“localhost”
是这样的可能的?
Hi I am using Xpath in my Nant build script to change some config variables between development and my other environments.
I have taken the syntax from this example:
The example looks like this:
<xmlpoke
file="config01/app.config"
xpath="/configuration/appSettings/add[@key='AppName']/@value"
value="TradeMonster">
</xmlpoke>
What I would like is something similar to this to search my connection strings and find all instances of "localhost\SqlExpress" and just change them to just "localhost"
Is this possible?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
在这里玩弄一个快速而肮脏的脚本......
如果您确定每个文件中只有一个连接字符串元素,您可以使用
xmlpeek
和xmlpoke
的组合来完成此操作代码>.使用某些 C# 可以更轻松地修改字符串,因此使用脚本任务来执行正则表达式搜索和替换:Toying with a quick'n dirty script here....
If you're sure there is only one connectionstring element in each file you can accomplish this with a combination of
xmlpeek
andxmlpoke
. Modifying the string is easier done with some C#, therefore using a script task to do a regex search and replace:XPath 只能选择节点,不能更改节点。
完成所需更改的一种方法是对 XML 文档执行 XSLT 转换。
为了实现这一点,您必须提供 XML 文档并准确指定要更改其文本节点。
XPath only selects nodes, it cannot change nodes.
One way to accomplish the needed changes is to perform an XSLT transformation on the XML document.
In order to make this happen, you have to provide the XML document and to specify exactly which of its text nodes are to be changed.