public static boolean isValidXMLName ( String s ) { // Catch the empty string or null. if ( s == null || "" . equals ( s ) ) { return false ; } // Since the string isn't empty, check that the first character is a // valid starting character. if ( ! isXMLNameStart ( s . codePointAt ( 0 ) ) ) { return false ; } // Loop through the string by UNICODE codepoints. This is NOT equivalent // to looping through the characters because some UNICODE codepoints can // occupy more than one character. int length = s . length ( ) ; int index = 1 ; while ( index < length ) { int codePoint = s . codePointAt ( index ) ; if ( ! isXMLNamePart ( codePoint ) ) { return false ; } index += Character . charCount ( codePoint ) ; } // Names that begin with "xml" with letters in any case are reserved by // the XML specification. if ( s . toLowerCase ( ) . startsWith ( "xml" ) ) { return false ; } // If we get here then all of the characters have been checked and are // valid. Unfortunately the usual case takes the longest to verify. return true ; }
Determine if the given string is a valid XML name .