Package net.sf.saxon.om

## Class NameChecker

- java.lang.Object
- - net.sf.saxon.om.NameChecker

-     public abstract class NameChecker
      extends java.lang.Object

  The NameChecker performs validation and analysis of XML names.

  In releases prior to 9.6, there were two name checkers, one for XML 1.0 and one for XML 1.1. However, XML 1.0 fifth edition uses the same rules for XML names as XML 1.1, so they were actually checking the same rules for names (although they were different when checking for valid characters). From 9.6, the name checker no longer performs checks for valid XML characters, so only one name checker is needed, and the methods have become static.

- - ### Constructor Summary

    Constructors
    Constructor | Description
    --- | ---
    `NameChecker()` |

  - ### Method Summary

    All Methods Static Methods Concrete Methods
    Modifier and Type | Method | Description
    --- | --- | ---
    `static java.lang.String[]` | `checkQNameParts​(java.lang.CharSequence qname)` | Validate a QName, and return the prefix and local name.
    `static java.lang.String` | `getPrefix​(java.lang.String qname)` | Extract the prefix from a QName.
    `static java.lang.String[]` | `getQNameParts​(java.lang.CharSequence qname)` | Validate a QName, and return the prefix and local name.
    `static boolean` | `isNCNameChar​(int ch)` | Test whether a character can appear in an NCName
    `static boolean` | `isNCNameStartChar​(int ch)` | Test whether a character can appear at the start of an NCName
    `static boolean` | `isQName​(java.lang.String name)` | Validate whether a given string constitutes a valid QName, as defined in XML Namespaces.
    `static boolean` | `isValidNCName​(java.lang.CharSequence ncName)` | Validate whether a given string constitutes a valid NCName, as defined in XML Namespaces.
    `static boolean` | `isValidNmtoken​(java.lang.CharSequence nmtoken)` | Check to see if a string is a valid Nmtoken according to [7] in the XML 1.0 Recommendation

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Constructor Detail

    - #### NameChecker

          public NameChecker()

  - ### Method Detail

    - #### isQName

          public static boolean isQName​(java.lang.String name)

      Validate whether a given string constitutes a valid QName, as defined in XML Namespaces. Note that this does not test whether the prefix is actually declared.
      Parameters:
        `name` - the name to be tested
      Returns:
        true if the name is a lexically-valid QName

    - #### getPrefix

          public static java.lang.String getPrefix​(java.lang.String qname)

      Extract the prefix from a QName. Note, the QName is assumed to be valid.
      Parameters:
        `qname` - The lexical QName whose prefix is required
      Returns:
        the prefix, that is the part before the colon. Returns an empty string if there is no prefix

    - #### getQNameParts

          public static java.lang.String[] getQNameParts​(java.lang.CharSequence qname)
                                                  throws QNameException

      Validate a QName, and return the prefix and local name. The local name is checked to ensure it is a valid NCName. The prefix is not checked, on the theory that the caller will look up the prefix to find a URI, and if the prefix is invalid, then no URI will be found.
      Parameters:
        `qname` - the lexical QName whose parts are required. Note that leading and trailing whitespace is not permitted
      Returns:
        an array of two strings, the prefix and the local name. The first item is a zero-length string if there is no prefix.
      Throws:
        `QNameException` - if not a valid QName.

    - #### checkQNameParts

          public static java.lang.String[] checkQNameParts​(java.lang.CharSequence qname)
                                                    throws XPathException

      Validate a QName, and return the prefix and local name. Both parts are checked to ensure they are valid NCNames.

      Used from compiled code

      Parameters:
        `qname` - the lexical QName whose parts are required. Note that leading and trailing whitespace is not permitted
      Returns:
        an array of two strings, the prefix and the local name. The first item is a zero-length string if there is no prefix.
      Throws:
        `XPathException` - if not a valid QName.

    - #### isValidNCName

          public static boolean isValidNCName​(java.lang.CharSequence ncName)

      Validate whether a given string constitutes a valid NCName, as defined in XML Namespaces.
      Parameters:
        `ncName` - the name to be tested. Any whitespace trimming must have already been applied.
      Returns:
        true if the name is a lexically-valid QName

    - #### isValidNmtoken

          public static boolean isValidNmtoken​(java.lang.CharSequence nmtoken)

      Check to see if a string is a valid Nmtoken according to [7] in the XML 1.0 Recommendation
      Parameters:
        `nmtoken` - the string to be tested. Any whitespace trimming must have already been applied.
      Returns:
        true if nmtoken is a valid Nmtoken

    - #### isNCNameChar

          public static boolean isNCNameChar​(int ch)

      Test whether a character can appear in an NCName
      Parameters:
        `ch` - the character to be tested
      Returns:
        true if this is a valid character in an NCName. The rules for XML 1.0 fifth edition are the same as the XML 1.1 rules, and these are the rules that we use.

    - #### isNCNameStartChar

          public static boolean isNCNameStartChar​(int ch)

      Test whether a character can appear at the start of an NCName
      Parameters:
        `ch` - the character to be tested
      Returns:
        true if this is a valid character at the start of an NCName. The rules for XML 1.0 fifth edition are the same as the XML 1.1 rules, and these are the rules that we use.