XML replace changes & character to &

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

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.

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

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.

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

/Rasmus

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