You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@ant.apache.org by Dylan Farre <dy...@gmail.com> on 2009/02/27 19:30:23 UTC

How to replace a \ with  Or how do I replace anything with &

I am trying to replace a \ with the character sequence &#x1a;
Don't ask why! Im not sure I know just yet.

If I use this method:

<replace file="${dir}\${file}"
token="\" value="&#x5c;" summary="true"> </replace>

it just replaces \ with \


If I use this method:

<replaceregexp file="${dir}\${file}" match="\" replace="&#x5c;"
byline="true"/> I get this error:
Unexpected internal error near index 1

If I try to build up the sequence with multiple replaces, Ant won't let me
insert an & into the file, I get this error:
The entity name must immediately follow the '&' in the entity reference.
Or
"&#x1a" is an invalid XML character.

This is running ant on windows. Would the results be different from unix?

Would sed work from unix? what is the best sed-like app for windows?

Thanks

RE: How to replace a \ with  Or how do I replace anything with &

Posted by "Rinehart, Raleigh" <ra...@ti.com>.
> I am trying to replace a \ with the character sequence &#x1a;
> Don't ask why! Im not sure I know just yet.
> 
> If I use this method:
> 
> <replace file="${dir}\${file}"
> token="\" value="&#x5c;" summary="true"> </replace>
> 
> it just replaces \ with \
> 
> 
> If I use this method:
> 
> <replaceregexp file="${dir}\${file}" match="\" replace="&#x5c;"
> byline="true"/> I get this error:
> Unexpected internal error near index 1
> 
> If I try to build up the sequence with multiple replaces, Ant won't let me
> insert an & into the file, I get this error:
> The entity name must immediately follow the '&' in the entity reference.
> Or
> "&#x1a" is an invalid XML character.
> 
> This is running ant on windows. Would the results be different from unix?
> 
> Would sed work from unix? what is the best sed-like app for windows?
> 
> Thanks
 
Can't use & directly in XML as it is a special char.  Need to use the entity ref so the parser does what you want.


This should work for you:
<replace file="test" token="\" value="&amp;#x5c;" summary="true"/>


Hope this helps,
-raleigh

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
For additional commands, e-mail: user-help@ant.apache.org