读取字符串中的分号时,在nant脚本中使用xmlpoke时出现问题

时间:2010-09-16 18:08:21

标签: asp.net ant web-config nant xmlpoke

我有一个试图在web.config中更改URL值的nant脚本但是Nant一直在抛出这个错误:

'=' is an unexpected token. The expected token is ';'. Line 1, position 80.

我将其追溯到nant脚本的URL中的分号。我首先在URL中使用分号的原因是因为web.config不喜欢&符号(&)。所以我不得不更换&与&。这是我的web.config值:

<appSettings>
    <add key="myUrl" value="http://www.google.com/whatever?id=myId&amp;fullScreen=1"/>
</appSettings>

我能够在web.config中xmlpo所有其他“添加键”但是这个,所以它不是xpath问题。 这是nant脚本:

<property name="myUrl" value="http://www.google.com/whatever?id=123456&amp;fullScreen=2"/>

<xmlpoke 
   file="${config.file}"
   xpath="/configuration/appSettings/add[@key = 'myUrl']/@value"
   value="${myUrl}">    
</xmlpoke>

所以问题不在于web.config中的分号,而是在nant脚本中使用分号。我想我需要以某种方式逃避nant脚本中的分号。任何人都知道如何做到这一点或其他什么来让它工作?

1 个答案:

答案 0 :(得分:5)

已经过了16个小时而且没有人偷看。幸运的是,经过几个小时的谷歌搜索,我找到了解决方案。

解决方案是使用&amp;amp;。我不知道为什么额外的amp;但是它有效。 所以现在我的nant脚本看起来像这样:

<property name="myUrl" value="http://www.google.com/whatever?id=123456&amp;amp;fullScreen=2"/>

信用额转到Gary from the nant-users mailing list,我刚刚订阅了它:)