Package net.sf.saxon.om
Class NameChecker
java.lang.Object
net.sf.saxon.om.NameChecker
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 -
Method Summary
Modifier and TypeMethodDescriptionstatic String[]
checkQNameParts
(String qname) Validate a QName, and return the prefix and local name.static String
Extract the prefix from a QName.static String[]
getQNameParts
(String qname) static boolean
isNCNameChar
(int ch) Test whether a character can appear in an NCNamestatic boolean
isNCNameStartChar
(int ch) Test whether a character can appear at the start of an NCNamestatic boolean
isQName
(IntIterator codePoints) Validate whether a given string constitutes a valid QName, as defined in XML Namespaces.static boolean
isValidNCName
(String str) static boolean
isValidNCName
(IntIterator codePoints) Validate whether a given string constitutes a valid NCName, as defined in XML Namespaces.static boolean
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:
codePoints
- the name to be tested, supplied as a codepoint iterator- Returns:
- true if the name is a lexically-valid QName
-
getPrefix
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
- Throws:
QNameException
-
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:
codePoints
- the name to be tested, as a codepoint iterator. Any whitespace trimming must have already been applied.- Returns:
- true if the name is a lexically-valid QName
-
isValidNCName
-
isValidNmtoken
Check to see if a string is a valid Nmtoken according to [7] in the XML 1.0 Recommendation- Parameters:
in
- 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.
-