PowerGREP’s ability to search and replace using a delimited list of search terms makes it very easy to search-and-replace all reserved XML character with their named XML entities. Simply set the search type to “delimited literal text”, set the extra item delimiter to a line break, the extra pair delimiter to an equals sign, and paste in the following search text:
&=& <=< >=> '=' "="
When extracting text from an XML file, you can easily turn things around to replace the named XML entities with the characters they represent:
&=& <=< >=> '=' "="
PowerGREP’s extra processing feature makes it very straightforward to collect text from an XML file with all entities replaced with their corresponding characters.
PowerGREP will now collect all the text between <tag> and </tag> tags in your XML files. If any of the text contains named entities, they will be replaced before the text is collected. The replacements are only made to the text being collected. They’re not made to the original XML files.
You can find this action in the PowerGREP5.pgl standard library as “XML: Collect search matches with named entities replaced”.
The example “replace reserved characters in XML files” in the PowerGREP library shows how you might use the “extra processing” feature for doing the opposite: replacing reserved characters with entities.