Friday, 16 February 2007

xml string fixer

If you encounter the following error;

"The entity name must immediately follow the ‘&’ in the entity reference"

you may filter the string, which you want to convert to xml document, with the following code.


private String xmlFixer(String xmlString) {
xmlString = xmlString.replaceAll("&([^; ]*);", "||VALIDXMLTAG||$1;");
xmlString = xmlString.replaceAll("&","&");
xmlString = xmlString.replaceAll("\\|\\|VALIDXMLTAG\\|\\|([^; ]*);", "&$1;");
return (xmlString);
}

0 comments: