Refresh Your Java - Before Java Interview
We are Agile, believe in less Documentation - Only Quick notes (Java Interview Questions) of Java/J2ee Read more....
This is Util Class that Replaces the invalid XML
characters such as "&",
">", "<"
appropriate
values such as
"&",
">",
"<"
public class XMLStringValidator {
private final
String [] specialCharacters = { "&",
">", "<",
"\'", "\""
};
private final String [] replacements = {
"&",
">",
"<",
"'",
""" };
public XMLStringValidator() {
}
/**
* validate()
* @author
Geoff Shotts
*
* Make
sure there aren't any &, <, >,
', or " characters: these are handled
* specially in XML parsers. Convert them to
their escape code equivalents.
*
* Note: ampersand replacement *MUST BE FIRST*.
*
**/
public
String validate( String input )
{
if ( input == null || input ==
"" )
return input;
String result = input;
for ( int i = 0; i <
specialCharacters.length; ++i ) {
result =
result.replaceAll( specialCharacters[i], replacements[i] );
}
return result;
}
} // XMLStringValidator
This Portal is intended to put all Java/J2ee related topics at one single place for quick referance, not only Technical , but also the Project Management Related thing such as Development Process methodoogies build process, unit testing etc.,
This Portal has More than 500 Java Interview Questions (also could be Considered as Quick Notes) very neatly separated topic by topic with simple diagrams which makes you easily understandable. Importantly these are from our Realtime expericance.