net.sf.saxon.om
Class NameChecker
java.lang.Object
net.sf.saxon.om.NameChecker
public abstract class NameChecker
extends java.lang.Object
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.
String[] | checkQNameParts(CharSequence qname) - Validate a QName, and return the prefix and local name.
|
static String | getPrefix(String qname) - Extract the prefix from a QName.
|
String[] | getQNameParts(CharSequence qname) - Validate a QName, and return the prefix and local name.
|
abstract String | getXMLVersion() - Return the XML version supported by this NameChecker
|
abstract boolean | isNCNameChar(int ch) - Test whether a character can appear in an NCName
|
abstract boolean | isNCNameStartChar(int ch) - Test whether a character can appear at the start of an NCName
|
boolean | isQName(String name) - Validate whether a given string constitutes a valid QName, as defined in XML Namespaces.
|
abstract boolean | isValidChar(int ch) - Test whether a character is a valid XML character
|
boolean | isValidNCName(CharSequence ncName) - Validate whether a given string constitutes a valid NCName, as defined in XML Namespaces.
|
boolean | isValidNmtoken(CharSequence nmtoken) - Check to see if a string is a valid Nmtoken according to [7]
in the XML 1.0 Recommendation
|
checkQNameParts
public final String[] checkQNameParts(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
qname
- the lexical QName whose parts are required. Note that leading and trailing
whitespace is not permitted
- an array of two strings, the prefix and the local name. The first
item is a zero-length string if there is no prefix.
getPrefix
public static String getPrefix(String qname)
Extract the prefix from a QName. Note, the QName is assumed to be valid.
qname
- The lexical QName whose prefix is required
- the prefix, that is the part before the colon. Returns an empty
string if there is no prefix
getQNameParts
public final String[] getQNameParts(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.
qname
- the lexical QName whose parts are required. Note that leading and trailing
whitespace is not permitted
- an array of two strings, the prefix and the local name. The first
item is a zero-length string if there is no prefix.
getXMLVersion
public abstract String getXMLVersion()
Return the XML version supported by this NameChecker
- "1.0" or "1.1" as a string
isNCNameChar
public abstract boolean isNCNameChar(int ch)
Test whether a character can appear in an NCName
ch
- the character to be tested
- 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
ch
- the character to be tested
- true if this is a valid character at the start of an NCName the selected version of XML
isQName
public final boolean isQName(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.
name
- the name to be tested
- true if the name is a lexically-valid QName
isValidChar
public abstract boolean isValidChar(int ch)
Test whether a character is a valid XML character
ch
- the character to be tested
- true if this is a valid character in the selected version of XML
isValidNCName
public final boolean isValidNCName(CharSequence ncName)
Validate whether a given string constitutes a valid NCName, as defined in XML Namespaces.
ncName
- the name to be tested
- true if the name is a lexically-valid QName
isValidNmtoken
public final boolean isValidNmtoken(CharSequence nmtoken)
Check to see if a string is a valid Nmtoken according to [7]
in the XML 1.0 Recommendation
nmtoken
- string to check
- true if nmtoken is a valid Nmtoken