PhoenixmlDb.XQuery
ISchemaProvider
Provides schema awareness to the XQuery and XSLT engines. Public extension point β callers can substitute their own implementation (RelaxNG, Schematron-derived, in-memory, dynamic) by passing it to the constructor.
#ISchemaProvider
Namespace: PhoenixmlDb.XQuery
Provides schema awareness to the XQuery and XSLT engines. Public extension point β callers can substitute their own implementation (RelaxNG, Schematron-derived, in-memory, dynamic) by passing it to the
constructor.
The default implementation, XsdSchemaProvider, ships in this package and is registered automatically by QueryEngine. Together they provide the XQuery 3.1 "Schema-Aware Conformance" features:
-
validateexpressions (validate strict { ... }) -
schema-element()andschema-attribute()type tests -
import schemaprolog declarations -
Typed node annotations (elements/attributes annotated with their XSD type)
-
Full XSD type hierarchy for
instance ofandtreat as
Implement this interface to back schema processing with a non-XSD schema language, an in-memory schema, or a custom resolution strategy. The engine calls in at compile time (for static type checks) and at execution time (for validation and type annotation).
Passing null for schemaProvider opts out of schema features entirely β every schema-element/attribute reference becomes XPST0008 and every validate raises XQDY0027. This is rare; intended for size-constrained embedded scenarios.
#Example
// Default β XsdSchemaProvider auto-registered, no schemas loaded yet.
var engine = new QueryEngine(nodeProvider: store, documentResolver: store);
// Pre-load schemas via the default provider:
var xsd = new XsdSchemaProvider("catalog.xsd");
var engine2 = new QueryEngine(nodeProvider: store, documentResolver: store, schemaProvider: xsd);
// Custom implementation:
var engine3 = new QueryEngine(nodeProvider: store, documentResolver: store, schemaProvider: new MyRelaxNgProvider());
#Methods
#GetAttributeType(PhoenixmlDb.Xdm.XdmQName)
Returns the declared type name for a global attribute declaration.
Parameters:
-
nameβ The attribute QName.
Returns: The XSD type name, or null if the attribute is not declared.
#GetAttributeType(String,String)
String-URI overload of
.
#GetElementType(PhoenixmlDb.Xdm.XdmQName)
Returns the declared type name for a global element declaration.
Parameters:
-
nameβ The element QName.
Returns: The XSD type name, or null if the element is not declared.
#GetElementType(String,String)
String-URI overload of
.
#HasAttributeDeclaration(PhoenixmlDb.Xdm.XdmQName)
Checks whether a global attribute declaration exists in the in-scope schema definitions, corresponding to the
schema-attribute(Name)
type test.
Parameters:
-
nameβ The attribute QName to look up.
Returns: true if the attribute is declared in a loaded schema.
#HasAttributeDeclaration(String,String)
String-URI overload of
.
#HasElementDeclaration(PhoenixmlDb.Xdm.XdmQName)
Checks whether a global element declaration exists in the in-scope schema definitions, corresponding to the
schema-element(Name)
type test.
Parameters:
-
nameβ The element QName to look up.
Returns: true if the element is declared in a loaded schema.
#HasElementDeclaration(String,String)
String-URI overload of
. Preferred when the caller has the namespace URI directly (rather than going through a
), since
is not always reversible to a URI.
#ImportSchema(String,Collections.Generic.IReadOnlyList<String>)
Imports a schema namespace, corresponding to the XQuery
import schema
declaration.
Parameters:
-
targetNamespaceβ The target namespace of the schema to import. An empty string represents the no-namespace schema. -
locationHintsβ Optional location hints (URIs) for the schema document(s), from theatclause.
Exceptions:
-
SchemaExceptionβ Thrown if the schema cannot be loaded or contains errors (maps to XQST0059).
#IsSubtypeOf(PhoenixmlDb.Xdm.XdmTypeName,PhoenixmlDb.Xdm.XdmTypeName)
Determines whether
is a subtype of
in the XSD type derivation hierarchy.
Parameters:
-
actualTypeβ The type to check. -
requiredTypeβ The type to check against.
Returns: true if actualType is equal to or derived from requiredType.
This is the core type subsumption check used by
instance of
,
treat as
, and function argument coercion. The implementation must cover the full XSD 1.1 type hierarchy including built-in types, restriction, extension, union, and list derivation.
#MatchesSchemaAttribute(PhoenixmlDb.Xdm.Nodes.XdmAttribute,PhoenixmlDb.Xdm.XdmQName)
Checks whether an attribute matches a
schema-attribute(Name)
test. An attribute matches if it has the declared name and its type annotation is the declared type or a subtype.
Parameters:
-
attributeβ The attribute node to test. -
declarationNameβ The attribute declaration name from the schema-attribute() test.
Returns: true if the attribute matches the schema-attribute() test.
#MatchesSchemaAttribute(PhoenixmlDb.Xdm.Nodes.XdmAttribute,String,String)
String-URI overload of
.
#MatchesSchemaElement(PhoenixmlDb.Xdm.Nodes.XdmElement,PhoenixmlDb.Xdm.XdmQName)
Checks whether an element matches a
schema-element(Name)
test. An element matches if it has the same name as the declaration (or a name in its substitution group) and its type annotation is the declared type or a subtype.
Parameters:
-
elementβ The element node to test. -
declarationNameβ The element declaration name from the schema-element() test.
Returns: true if the element matches the schema-element() test.
#MatchesSchemaElement(PhoenixmlDb.Xdm.Nodes.XdmElement,String,String)
String-URI overload of
.
#TryCastToSchemaSimpleType(String,String,String)
Casts a lexical value to a SCHEMA-DEFINED simple type, for
cast as
/
castable as
against a type an imported schema declares rather than a built-in XSD type.
Returns: true if the schema declares localName in namespaceUri as a simple type AND the lexical value satisfies it (including every facet β pattern, enumeration, length, bounds). false if the value does not satisfy the type. Throws only if the TYPE ITSELF is unusable β absent, or complex rather than simple β because "no such type" is a static error (XPST0051) while "value does not match" is an ordinary castable=false.
Kept on the provider rather than in the engine because facet validation is precisely what an XSD implementation already does; the engine has no facet machinery and should not grow one.
#Validate(PhoenixmlDb.Xdm.Nodes.XdmNode,PhoenixmlDb.XQuery.ValidationMode,String,String)
Validates a node tree against the loaded schemas, corresponding to the
validate
expression.
Parameters:
-
nodeβ The document or element node to validate. -
modeβ The validation mode (strict, lax, or type). -
typeNamespaceUriβ ForValidationMode.Type, the namespace URI of the target type. Null for strict and lax modes. -
typeLocalNameβ ForValidationMode.Type, the local name of the target type. Null for strict and lax modes.
Returns: A validated copy of the node tree with type annotations applied.
Exceptions:
-
SchemaValidationExceptionβ Thrown if validation fails (maps to XQDY0027 for strict/lax, XQDY0027 for type).
Returns a deep copy of the input node tree with XdmElement.TypeAnnotation and XdmAttribute.TypeAnnotation populated from the schema. The original node tree is not modified.
The validation mode determines behavior:
-
ValidationMode.Strictβ the element must have a global declaration. -
ValidationMode.Laxβ validate if a declaration exists, pass through if not. -
ValidationMode.Typeβ validate against a specific named type.
#ValidateAndAnnotate(String,PhoenixmlDb.XQuery.INodeBuilder,PhoenixmlDb.XQuery.ValidationMode,String,String)
Validates an XML string against the loaded schemas AND returns a freshly built XDM tree whose elements and attributes carry
/
populated from the schema.
Parameters:
-
xmlContentβ The XML markup to validate and annotate. -
builderβ Node store / ID allocator the resulting tree is registered in. -
modeβ Validation mode (strict, lax, or type). -
typeNamespaceUriβ Optional namespace URI for type-mode validation. -
typeLocalNameβ Optional local name for type-mode validation.
Returns: The annotated document node, or null if annotation is unsupported.
Exceptions:
-
SchemaValidationExceptionβ Thrown if validation fails (XQDY0027).
The new tree is registered in builder so it participates in the caller's node store and namespace interning. Returns null when the provider doesn't support an annotating parse β the caller should then fall back to the unannotated original node from the validate expression body.
The default implementation returns null. Built-in providers (e.g. XsdSchemaProvider) override to drive a schema-validating XmlReader through XmlDocumentParser.Parse(reader, uri, schemas), which populates XdmElement.TypeAnnotation from SchemaInfo.SchemaType.
#ValidateXml(String,PhoenixmlDb.XQuery.ValidationMode,String,String)
Validates already-serialized XML content against the loaded schemas. Convenience overload for callers (notably
xsl:result-document
) that have a string in hand rather than an in-memory XDM tree. Throws
(XQDY0027) on validation failure. Default implementation parses the content and delegates to the node-based
via a minimal XdmNode adapter; implementations are encouraged to override with a more direct path.
#ValidateXmlFragment(String,PhoenixmlDb.XQuery.ValidationMode,String,String,Collections.Generic.IReadOnlyDictionary<String,String>)
Fragment-mode counterpart of
. Validates an XML fragment (single element or sequence of nodes β not a complete document) against the loaded schemas. Used by XSLT for per-element / per-attribute / per-copy validation where no surrounding document declaration exists. Default falls back to
.
Parameters:
-
xmlFragmentβ The XML fragment to validate. -
modeβ Validation mode. -
typeNamespaceUriβ Optional namespace URI for type-mode validation. -
typeLocalNameβ Optional local name for type-mode validation. -
inScopeNamespacesβ Optional prefixβURI bindings that should be visible to the fragment without being explicitly declared inside it. Required when the fragment uses prefixed names whose declarations live on an enclosing element that the caller cannot include in the fragment text.
#See also
-
QueryEngine