Loading
XMLStringValidator

Java Quick Notes

Refresh Your Java - Before Java Interview

We are Agile, believe in less Documentation - Only Quick notes (Java Interview Questions) of Java/J2ee Read more....


Not Included Yet
Not Included Yet
Not Included Yet
Not Included Yet
Not Included Yet
Not Included Yet
Not Included Yet
Not Included Yet
Not Included Yet
Not Included Yet
Not Included Yet
Not Included Yet
Not Included Yet
Not Included Yet
Not Included Yet
Not Included Yet
Not Included Yet
Not Included Yet
Not Included Yet
Not Included Yet

Go to SiteMap

Q)  XML Invalid Chars Replacer


Ans)

This is Util Class that Replaces the invalid XML characters such as  "&", ">", "<" appropriate
values such as  "&amp;", "&gt;", "&lt;"

public class XMLStringValidator {

  private final String [] specialCharacters = { "&", ">", "<", "\'", "\"" };
  private final String [] replacements = { "&amp;", "&gt;", "&lt;", "&apos;", "&quot;" };

 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



Back to top

------------------------- We hope you got necessary Info On -----------------------------------------

XMLStringValidator


XMLStringValidator

-------------------------------------------------------------------------------------------------------



Face Book
Request for a Mock Interview/Training

Get a PDF

Face Book
Same look (Read) on any device, this is Ads free