# XML replace changes & character to &

**URL:** https://www.finalbuilder.com/forums/t/xml-replace-changes-character-to/3107
**Category:** Bugs
**Created:** [May 28, 2009, 2:35am UTC](https://www.finalbuilder.com/forums/t/xml-replace-changes-character-to/3107 "2009-05-28T02:35:41Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![deleted\_user](https://www.finalbuilder.com/forums/user_avatar/www.finalbuilder.com/deleted_user/32/937_2.png) [@deleted\_user](https://www.finalbuilder.com/forums/u/deleted_user)
#### Post date: [May 28, 2009, 2:35am UTC](https://www.finalbuilder.com/forums/t/xml-replace-changes-character-to/3107/1 "2009-05-28T02:35:41Z")

</div>

Hi,   
  
 I am trying to use the Edit XML File action to replace a password in an xml file. The password in question contains a ‘&’ character, but when I do the replace the ‘&’ character if replaced with ‘& a m p ;’.   
  
 I am using FB 6.2.0.1463   
  
 Steps to reproduce:   
  
 Create a XML file with the following content (I have replaced the less-than sign with # or the xml would disappear from the post):   
 #?xml version=“1.0”?\>   
 #configuration\>   
#key value=“myvalue”/\>   
 #/configuration\>   
  
 Run an “Edit XML File” on the file created:   
 XPath: //configuration/key   
 Attribute: value   
 New Value: valwith&in   
  
 After running the action, the xml file contains:   
 #?xml version=“1.0”?\>   
 #configuration\>   
#key value=“valwith&_a\_m\_p_;in”/\>   
 #/configuration\>   
  
 I have tried every combination of the options available on the action, but the result is still the same.   
  
 EDIT: the forum is replacing all my html escape charcters so I have to write them as &_a\_m\_p_;   
  
 Regards,   
  
 Rasmus Aaen   
 NNIT

---

<div class="post-metadata">

### Author: ![paulsamways](https://www.finalbuilder.com/forums/letter_avatar_proxy/v4/letter/p/e8c25b/32.png) [@paulsamways](https://www.finalbuilder.com/forums/u/paulsamways)
#### Post date: [May 29, 2009, 7:23am UTC](https://www.finalbuilder.com/forums/t/xml-replace-changes-character-to/3107/2 "2009-05-29T07:23:40Z")

</div>

Hi Rasmus,   
  
 This is the correct behaviour when using ampersands within an XML attribute, it is up to the XML parser which reads the value to convert the escaped characters back to the original.   
  
 Regards,   
 Paul.

---

<div class="post-metadata">

### Author: ![deleted\_user](https://www.finalbuilder.com/forums/user_avatar/www.finalbuilder.com/deleted_user/32/937_2.png) [@deleted\_user](https://www.finalbuilder.com/forums/u/deleted_user)
#### Post date: [May 29, 2009, 8:38am UTC](https://www.finalbuilder.com/forums/t/xml-replace-changes-character-to/3107/3 "2009-05-29T08:38:22Z")

</div>

Ok. But shouldn’t the “Treat the new value as text” option stop the xml parser from changing the ampersands? Or it this option used for something else?   
  
 By the way, the help file entry for the “Edit XML file” seems a bit outdated. The “Insert new value in CDATA” option is missing from the screenshot and “Treat the new value as text” is missing an explanation.   
  
 Regards,   
  
 Rasmus

---

<div class="post-metadata">

### Author: ![paulsamways](https://www.finalbuilder.com/forums/letter_avatar_proxy/v4/letter/p/e8c25b/32.png) [@paulsamways](https://www.finalbuilder.com/forums/u/paulsamways)
#### Post date: [June 1, 2009, 8:40am UTC](https://www.finalbuilder.com/forums/t/xml-replace-changes-character-to/3107/4 "2009-06-01T08:40:23Z")

</div>

Hi Rasmus,   
  
 The option ‘Treat new value as text’ does not apply when editing an attribute, the option relates to editing the inner value of an XML node and whether to insert the new value as a text node or to insert it as is, ditto with the ‘Insert new value as CDATA’. If you wish to have an unescaped & in the attribute then you will need to treat the file as text and use the ‘Text Find/Replace’ action.   
  
 \> By the way, the help file entry for the “Edit XML file” seems a bit outdated   
  
 Thanks Paul.

---

<div class="post-metadata">

### Author: ![deleted\_user](https://www.finalbuilder.com/forums/user_avatar/www.finalbuilder.com/deleted_user/32/937_2.png) [@deleted\_user](https://www.finalbuilder.com/forums/u/deleted_user)
#### Post date: [June 2, 2009, 7:51am UTC](https://www.finalbuilder.com/forums/t/xml-replace-changes-character-to/3107/5 "2009-06-02T07:51:55Z")

</div>

Ok, I’ll handle this in a special case.   
  
 /Rasmus

---

<div class="post-metadata">

### Author: ![deleted\_user](https://www.finalbuilder.com/forums/user_avatar/www.finalbuilder.com/deleted_user/32/937_2.png) [@deleted\_user](https://www.finalbuilder.com/forums/u/deleted_user)
#### Post date: [June 2, 2009, 9:32am UTC](https://www.finalbuilder.com/forums/t/xml-replace-changes-character-to/3107/6 "2009-06-02T09:32:39Z")

</div>

Hi again,   
  
 I changed my script to use the text find/replace action to replace the ampersand value, which looked all right. But when I closed the project and opened it again, the value in the Search String field had been changed from my original entry of “& a m p ; q u o t ;” to “& q u o t ;” (remove extra spaces). this happens every time I close and open the project.   
  
  
 EDIT: I will move this to a new thread to avoid mixing subjects.   
  
 Regards,   
  
 Rasmus
