Class NameChecker
java.lang.Object
net.sf.saxon.om.NameChecker
- All Implemented Interfaces:
Serializable
- Direct Known Subclasses:
Name10Checker, Name11Checker
A NameChecker performs validation and analysis of XML names. There are two implementations
of this interface, one for XML 1.0 names and one for XML 1.1 names. The class also handles
validation of characters against the XML 1.0 or XML 1.1 rules.
- See Also:
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionfinal String[]checkQNameParts(CharSequence qname) Validate a QName, and return the prefix and local name.intfirstInvalidChar(CharSequence chars) Test whether all the characters in a CharSequence are valid XML charactersstatic StringExtract the prefix from a QName.final String[]getQNameParts(CharSequence qname) Validate a QName, and return the prefix and local name.abstract StringReturn the XML version supported by this NameCheckerabstract booleanisNCNameChar(int ch) Test whether a character can appear in an NCNameabstract booleanisNCNameStartChar(int ch) Test whether a character can appear at the start of an NCNamefinal booleanValidate whether a given string constitutes a valid QName, as defined in XML Namespaces.abstract booleanisValidChar(int ch) Test whether a character is a valid XML characterfinal booleanisValidNCName(CharSequence ncName) Validate whether a given string constitutes a valid NCName, as defined in XML Namespaces.final booleanisValidNmtoken(CharSequence nmtoken) Check to see if a string is a valid Nmtoken according to [7] in the XML 1.0 Recommendation
-
Constructor Details
-
NameChecker
public NameChecker()
-
-
Method Details
-
isQName
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
-
getQNameParts
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
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
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
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
-
isValidChar
public abstract boolean isValidChar(int ch) Test whether a character is a valid XML character- Parameters:
ch- the character to be tested- Returns:
- true if this is a valid character in the selected version of XML
-
firstInvalidChar
Test whether all the characters in a CharSequence are valid XML characters- Parameters:
chars- the character sequence to be tested- Returns:
- the codepoint of the first invalid character in the character sequence (according to the selected version of XML); or -1 if all characters in the character sequence are valid
-
isNCNameChar
public abstract 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 selected version of XML
-
isNCNameStartChar
public abstract 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 selected version of XML
-
getXMLVersion
Return the XML version supported by this NameChecker- Returns:
- "1.0" or "1.1" as a string
-