Class QNameParser

java.lang.Object
net.sf.saxon.om.QNameParser

public class QNameParser extends Object
Parser to handle QNames in either lexical QName or EQName syntax, including resolving any prefix against a URIResolver. The parser can be instantiated with various options to control the returned error code, the handling of defaults, etc. The QNameParser is immutable; its properties are set using the withProperty() fluent API style.
  • Constructor Details

  • Method Details

    • withNamespaceResolver

      public QNameParser withNamespaceResolver(NamespaceResolver resolver)
      Set the namespace resolver to be used
      Parameters:
      resolver - the namespace resolver
      Returns:
      a new QNameParser using the specified NamespaceResolver
    • withAcceptEQName

      public QNameParser withAcceptEQName(boolean acceptEQName)
      Say whether URI-qualified names in Q{uri}local format should be accepted
      Parameters:
      acceptEQName - true if extended QName syntax is accepted
      Returns:
      a new QNameParser with the requested properties
    • withErrorOnBadSyntax

      public QNameParser withErrorOnBadSyntax(String code)
      Say what error code should be thrown when the QName syntax is invalid
      Parameters:
      code - the error code to be thrown
      Returns:
      a new QNameParser with the requested properties
    • withErrorOnUnresolvedPrefix

      public QNameParser withErrorOnUnresolvedPrefix(String code)
      Say what error code should be thrown when the prefix is undeclared
      Parameters:
      code - the error code to be thrown
      Returns:
      a new QNameParser with the requested properties
    • withUnescaper

      public QNameParser withUnescaper(XQueryParser.Unescaper unescaper)
      Supply a callback used to unescape special characters appearing in the URI part of an EQName
      Parameters:
      unescaper - the callback to be used
      Returns:
      a new QNameParser with the requested properties
    • parse

      public StructuredQName parse(String lexicalName, NamespaceUri defaultNS) throws XPathException
      Make a structured QName from a lexical QName, using a supplied NamespaceResolver to resolve the prefix. The local part of the QName is checked for validity; the prefix is not checked, on the grounds that an invalid prefix will fail to resolve to a URI.
      Parameters:
      lexicalName - the QName as a lexical name (prefix:local)
      defaultNS - the default namespace to use if there is no prefix
      Returns:
      the StructuredQName object corresponding to this lexical QName
      Throws:
      XPathException - if the namespace prefix is not in scope or if the value is lexically invalid. Error code FONS0004 is set if the namespace prefix has not been declared; error code FOCA0002 is set if the name is lexically invalid. These may need to be changed on return depending on the caller's requirements.