Just a comment: if you're using the org.w3c.dom packages, then generally speaking you don't need to concern yourself with escaping those characters. For example
is perfectly legitimate and you don't need to escape that ampersand. Escaping only applies when an XML document is serialized to an external format -- i.e. a text file -- not when it is in an in internal format like that. If you stick to using only XML code in the standard API, for example using a Transformer to serialize your DOM, that escaping is taken care for you by that code. (And that's why the standard API doesn't include a method to do the escaping on a
string.) You only need to deal with escaping when you are writing serialization code, for example if you're doing something like
If you did that, then you would have to apply the escaping rules to the string in the "name" variable.