给出以下xml:
<rootnode>
<childnode arg="a">Content A</childnode>
<childnode arg="b">Content A</childnode>
</rootnode>
Run Code Online (Sandbox Code Playgroud)
将XMLPoke与以下XPath一起使用:
rootnode/childnode[arg='b']
Run Code Online (Sandbox Code Playgroud)
结果(如果替换字符串为空)是:
<rootnode>
<childnode arg="a">Content A</childnode>
<childnode arg="b"></childnode>
</rootnode>
Run Code Online (Sandbox Code Playgroud)
当我们真正想要移除childnode本身时,已删除了childnode的内容.期望的结果是:
<rootnode>
<childnode arg="a">Content A</childnode>
</rootnode>
Run Code Online (Sandbox Code Playgroud)
必须根据childnode参数选择子节点.
有没有办法使用以空格结尾的值作为XmlPoke值?当我执行任务时,值被替换但最后没有空格.
再生产:
test.targets:
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Target Name="Build">
<Copy SourceFiles="test.xml" DestinationFiles="output.xml"/>
<XmlPoke Query="/root/element/@attr[.='replaceme']|/root/replaceme" Value="X " XmlInputPath="output.xml"/>
</Target>
</Project>
Run Code Online (Sandbox Code Playgroud)
的test.xml:
<root>
<element attr="replaceme" />
<replaceme/>
</root>
Run Code Online (Sandbox Code Playgroud)
当我跑:
MSBuild /v:detailed test.targets
Run Code Online (Sandbox Code Playgroud)
我得到output.xml没有空格:
<root>
<element attr="X" />
<replaceme>X</replaceme>
</root>
Run Code Online (Sandbox Code Playgroud)
有没有办法强制XmlPoke设置正确的值(末尾有空格)?
有没有办法使用 nant 将属性添加到 xml 节点(我有 xpath)?尝试过 xmlpoke 但它看起来只能更新现有属性。
谢谢。
我正在尝试使用xmlpoke任务来更新VS项目文件(这是XML).在Project根目录中,有多个PropertyGroup节点,我试图选择第一个节点.XML看起来像这样
<Project>
<PropertyGroup>
</PropertyGroup>
<PropertyGroup>
</PropertyGroup>
<PropertyGroup>
</PropertyGroup>
</Project>
Run Code Online (Sandbox Code Playgroud)
我使用xpath //Project/PropertyGroup[1]来获取第一个PropertyGroup,但是我收到错误:"给定的非唯一xpath // Project/PropertyGroup [1]".
编辑:对不起,我认为它不重要(但确实如此),Project有一个命名空间.我把正确的XML和正确的xmlpoke作为未来搜索者的答案.
您好我在我的Nant构建脚本中使用Xpath来更改开发和我的其他环境之间的一些配置变量.
我从这个例子中采用了语法:
示例如下所示:
<xmlpoke
file="config01/app.config"
xpath="/configuration/appSettings/add[@key='AppName']/@value"
value="TradeMonster">
</xmlpoke>
Run Code Online (Sandbox Code Playgroud)
我想要的是类似于搜索我的连接字符串并查找"localhost\SqlExpress"的所有实例,并将它们更改为"localhost"
这可能吗?
我无法弄清楚如何使用Cake中的XmlPoke来更改XML节点的内部文本值.我一直得到的错误是Error: Expression must evaluate to a node-set.
我的XML看起来像这样
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<WebPublishMethod>FileSystem</WebPublishMethod>
<LastUsedBuildConfiguration>Release</LastUsedBuildConfiguration>
<LastUsedPlatform>Any CPU</LastUsedPlatform>
<SiteUrlToLaunchAfterPublish />
<LaunchSiteAfterPublish>True</LaunchSiteAfterPublish>
<ExcludeApp_Data>False</ExcludeApp_Data>
<publishUrl>This value must be set to your local path</publishUrl>
<DeleteExistingFiles>False</DeleteExistingFiles>
</PropertyGroup>
</Project>
Run Code Online (Sandbox Code Playgroud)
我build.cake看起来像这样
// Update the publish path in the pubxml
XmlPoke(publishProfile, "/Project/PropertyGroup/publishUrl/", buildPaths.PublishDirectory);
// The publishProfile is just the location of the XML file
// The buildPaths.PublishDirectory is the value I'm trying to set the inner text to
Run Code Online (Sandbox Code Playgroud) 我在目标项目中有一个.config,我需要通过MSBuild任务以编程方式添加一行.
Pseduo运营如:
$ TargetProjectDir\Config\packages.config中的.config文件:
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="ABC" version="1.1.0.4" />
<package id="XYZ" version="2.0.0.0" />
</packages>
Run Code Online (Sandbox Code Playgroud)
之后需要看起来像这样:
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="ABC" version="1.1.0.4" />
<package id="XYZ" version="2.0.0.0" />
<package id="CarDataWidget" version="3.0.0.0" />
</packages>
Run Code Online (Sandbox Code Playgroud)
到目前为止,我已经考虑过使用"内联任务","执行"任务和"XmlPoke"任务,但还没有设法让任何一个工作.
这是我对XmlPoke和XmlPeek的尝试:
我使用以下文章作为如何将节点添加到packages.config文件的灵感:http: //weblogs.asp.net/bsimser/appending-nodes-in-xml-files-with-xmlpeek-and-xmlpoke-使用-恶性
<Target Name="AfterBuild" DependsOnTargets="AddPackage">
</Target>
<Target Name="AddPackage">
<!-- Load existing nodes into a Property -->
<XmlPeek XmlInputPath="config/packages.config" Query="/packages/package" >
<Output TaskParameter="Result" PropertyName="Peeked" />
</XmlPeek>
<Message Text="From Peek: $(Peeked)"></Message>
<!-- Load new node into Property -->
<PropertyGroup> …Run Code Online (Sandbox Code Playgroud) 如何使用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)
这在这种情况下不起作用.
谢谢
我有一个试图在我的web.config中更改URL值的nant脚本但是Nant一直在抛出这个错误:
'=' is an unexpected token. The expected token is ';'. Line 1, position 80.
Run Code Online (Sandbox Code Playgroud)
我将其追溯到nant脚本的URL中的分号.我首先在URL中使用分号的原因是因为web.config不喜欢&符号(&).所以我不得不替换和&.这是我的web.config值:
<appSettings>
<add key="myUrl" value="http://www.google.com/whatever?id=myId&fullScreen=1"/>
</appSettings>
Run Code Online (Sandbox Code Playgroud)
我能够在web.config中xmlpo所有其他"添加键"但是这个,所以它不是一个xpath问题.这是nant脚本:
<property name="myUrl" value="http://www.google.com/whatever?id=123456&fullScreen=2"/>
<xmlpoke
file="${config.file}"
xpath="/configuration/appSettings/add[@key = 'myUrl']/@value"
value="${myUrl}">
</xmlpoke>
Run Code Online (Sandbox Code Playgroud)
所以问题不在于web.config中的分号,而是在nant脚本中使用分号.我想我需要以某种方式逃避nant脚本中的分号.任何人都知道如何做到这一点或其他什么来让它工作?
xmlpoke ×9
nant ×6
msbuild ×3
xml ×3
xpath ×3
c# ×2
msbuild-task ×2
ant ×1
asp.net ×1
cakebuild ×1
nhibernate ×1
web-config ×1