#[derive(Debug)]
pub enum FrameResult {
Schema(SchemaFrameResult),
Type(TypeFrameResult),
Element(ElementFrameResult),
Attribute(AttributeFrameResult),
Group(GroupFrameResult),
Notation(NotationResult),
Assert(AssertResult),
Alternative(AlternativeResult),
OpenContent(OpenContentResult),
DefaultOpenContent(DefaultOpenContentResult),
Annotation(Annotation),
AppInfo(AppInfoElement),
Documentation(DocumentationElement),
Facet(FacetResult),
Restriction(Box<RestrictionResult>),
Extension(ExtensionResult),
SimpleContent(SimpleContentDefResult),
ComplexContent(ComplexContentDefResult),
Identity(IdentityResult),
IdentityRef(IdentityRefResult),
Selector(SelectorResult),
Field(FieldResult),
Wildcard(WildcardResult),
Directive(DirectiveResult),
Particle(ParticleResult),
Skip,
None,
}
#[derive(Debug)]
pub struct SchemaFrameResult {
pub target_namespace: Option<NameId>,
pub element_form_default: Option<String>,
pub attribute_form_default: Option<String>,
pub block_default: DerivationSet,
pub default_attributes: Option<QNameRef>,
pub xpath_default_namespace: Option<String>,
pub final_default: DerivationSet,
pub version: Option<String>,
pub default_open_content: Option<DefaultOpenContentResult>,
pub xml_lang: Option<String>,
pub id: Option<String>,
pub source: Option<SourceRef>,
pub annotations: Vec<Annotation>,
pub directives: Vec<DirectiveResult>,
pub components: Vec<FrameResult>,
}
#[derive(Debug, Clone)]
pub enum TypeFrameResult {
Simple(Box<SimpleTypeResult>),
Complex(Box<ComplexTypeResult>),
}
#[derive(Debug, Clone)]
pub struct SimpleTypeResult {
pub name: Option<NameId>,
pub variety: SimpleTypeVariety,
pub base_type: Option<TypeRefResult>,
pub item_type: Option<TypeRefResult>,
pub member_types: Vec<TypeRefResult>,
pub facets: FacetSet,
pub final_derivation: Option<DerivationSet>,
pub id: Option<String>,
pub derivation_id: Option<String>,
pub annotation: Option<Annotation>,
pub source: Option<SourceRef>,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum SimpleTypeVariety {
Atomic,
List,
Union,
}
#[derive(Debug, Clone)]
pub struct ComplexTypeResult {
pub name: Option<NameId>,
pub base_type: Option<TypeRefResult>,
pub derivation_method: Option<DerivationMethod>,
pub content: ComplexContentResult,
pub attributes: Vec<AttributeUseResult>,
pub attribute_groups: Vec<QNameRef>,
pub attribute_wildcard: Option<WildcardResult>,
pub mixed: bool,
pub is_abstract: bool,
pub final_derivation: Option<DerivationSet>,
pub block: Option<DerivationSet>,
pub default_attributes_apply: bool,
pub id: Option<String>,
#[cfg(feature = "xsd11")]
pub xpath_default_namespace: Option<String>,
pub annotation: Option<Annotation>,
pub source: Option<SourceRef>,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum DerivationMethod {
Restriction,
Extension,
}
#[derive(Debug, Clone)]
pub enum ComplexContentResult {
Empty,
Simple(SimpleContentDefResult),
Complex(ComplexContentDefResult),
}
impl ComplexContentResult {
pub fn is_empty(&self) -> bool {
match self {
ComplexContentResult::Empty => true,
ComplexContentResult::Complex(def) => match &def.particle {
None => true,
Some(p) => particle_is_explicit_empty(p),
},
ComplexContentResult::Simple(_) => false,
}
}
pub fn explicit_content_type_is_empty(&self) -> bool {
match self {
ComplexContentResult::Empty => true,
ComplexContentResult::Complex(def) => {
let particle_empty = match &def.particle {
None => true,
Some(p) => particle_is_explicit_empty(p),
};
particle_empty && !def.mixed
}
ComplexContentResult::Simple(_) => false,
}
}
}
pub fn particle_is_explicit_empty(p: &ParticleResult) -> bool {
if p.max_occurs == Some(0) {
return true; }
match &p.term {
ParticleTerm::Group(group) => match group.compositor {
Some(Compositor::All) | Some(Compositor::Sequence) => group.particles.is_empty(),
Some(Compositor::Choice) => group.particles.is_empty() && group.min_occurs == 0,
None => false,
},
_ => false,
}
}
#[derive(Debug, Clone)]
pub struct SimpleContentDefResult {
pub base_type: Option<TypeRefResult>,
pub content_type: Option<Box<SimpleTypeResult>>,
pub derivation: DerivationMethod,
pub facets: FacetSet,
pub attributes: Vec<AttributeUseResult>,
pub attribute_groups: Vec<QNameRef>,
pub attribute_wildcard: Option<WildcardResult>,
pub assertions: Vec<AssertResult>,
pub id: Option<String>,
pub derivation_id: Option<String>,
pub source: Option<SourceRef>,
}
#[derive(Debug, Clone)]
pub struct ComplexContentDefResult {
pub particle: Option<ParticleResult>,
pub derivation: DerivationMethod,
pub mixed: bool,
pub mixed_explicit: bool,
pub base_type: Option<TypeRefResult>,
pub open_content: Option<OpenContentResult>,
pub attributes: Vec<AttributeUseResult>,
pub attribute_groups: Vec<QNameRef>,
pub attribute_wildcard: Option<WildcardResult>,
pub assertions: Vec<AssertResult>,
pub id: Option<String>,
pub derivation_id: Option<String>,
pub source: Option<SourceRef>,
}
#[derive(Debug, Clone)]
pub struct ElementFrameResult {
pub name: Option<NameId>,
pub ref_name: Option<QNameRef>,
pub target_namespace: Option<NameId>,
pub type_ref: Option<TypeRefResult>,
pub inline_type: Option<Box<TypeFrameResult>>,
pub substitution_group: Vec<QNameRef>,
pub default_value: Option<String>,
pub fixed_value: Option<String>,
pub nillable: bool,
pub is_abstract: bool,
pub min_occurs: u32,
pub max_occurs: Option<u32>,
pub block: Option<DerivationSet>,
pub final_derivation: Option<DerivationSet>,
pub form: Option<String>,
pub id: Option<String>,
pub alternatives: Vec<AlternativeResult>,
pub identity_constraints: Vec<IdentityResult>,
pub identity_constraint_refs: Vec<IdentityRefResult>,
pub annotation: Option<Annotation>,
pub source: Option<SourceRef>,
}
#[derive(Debug, Clone)]
pub struct AttributeFrameResult {
pub name: Option<NameId>,
pub ref_name: Option<QNameRef>,
pub target_namespace: Option<NameId>,
pub type_ref: Option<TypeRefResult>,
pub inline_type: Option<Box<SimpleTypeResult>>,
pub default_value: Option<String>,
pub fixed_value: Option<String>,
pub use_kind: Option<String>,
pub form: Option<String>,
pub inheritable: bool,
pub id: Option<String>,
pub annotation: Option<Annotation>,
pub source: Option<SourceRef>,
}
#[derive(Debug, Clone)]
pub struct AttributeUseResult {
pub attribute: AttributeFrameResult,
pub use_kind: AttributeUseKind,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
pub enum AttributeUseKind {
#[default]
Optional,
Required,
Prohibited,
}
#[derive(Debug)]
pub enum GroupFrameResult {
Model(Box<ModelGroupDefResult>),
Attribute(Box<AttributeGroupDefResult>),
}
#[derive(Debug, Clone)]
pub struct ModelGroupDefResult {
pub name: Option<NameId>,
pub ref_name: Option<QNameRef>,
pub compositor: Option<Compositor>,
pub particles: Vec<ParticleResult>,
pub min_occurs: u32,
pub max_occurs: Option<u32>,
pub id: Option<String>,
pub annotation: Option<Annotation>,
pub source: Option<SourceRef>,
}
#[derive(Debug, Clone)]
pub struct AttributeGroupDefResult {
pub name: Option<NameId>,
pub ref_name: Option<QNameRef>,
pub attributes: Vec<AttributeUseResult>,
pub attribute_groups: Vec<QNameRef>,
pub attribute_wildcard: Option<WildcardResult>,
pub id: Option<String>,
pub annotation: Option<Annotation>,
pub source: Option<SourceRef>,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum Compositor {
Sequence,
Choice,
All,
}
#[derive(Debug, Clone)]
pub struct ParticleResult {
pub term: ParticleTerm,
pub min_occurs: u32,
pub max_occurs: Option<u32>,
pub source: Option<SourceRef>,
}
#[derive(Debug, Clone)]
pub enum ParticleTerm {
Element(ElementFrameResult),
Group(ModelGroupDefResult),
Any(WildcardResult),
}
#[derive(Debug, Clone)]
pub enum TypeRefResult {
QName(QNameRef),
Inline(Box<TypeFrameResult>),
}
#[derive(Debug, Clone)]
pub struct QNameRef {
pub prefix: Option<NameId>,
pub local_name: NameId,
pub namespace: Option<NameId>,
}
#[derive(Debug, Clone)]
pub struct FacetResult {
pub kind: FacetKind,
pub value: String,
pub fixed: bool,
pub annotation: Option<Annotation>,
pub source: Option<SourceRef>,
pub xpath_default_namespace: Option<String>,
pub ns_snapshot: Option<NamespaceContextSnapshot>,
}
#[derive(Debug, Clone)]
pub struct RestrictionResult {
pub base_type: Option<TypeRefResult>,
pub inline_type: Option<SimpleTypeResult>,
pub facets: FacetSet,
pub particle: Option<ParticleResult>,
pub open_content: Option<OpenContentResult>,
pub attributes: Vec<AttributeUseResult>,
pub attribute_groups: Vec<QNameRef>,
pub attribute_wildcard: Option<WildcardResult>,
pub assertions: Vec<AssertResult>,
pub id: Option<String>,
pub annotation: Option<Annotation>,
pub source: Option<SourceRef>,
}
#[derive(Debug, Clone)]
pub struct ExtensionResult {
pub base_type: Option<TypeRefResult>,
pub particle: Option<ParticleResult>,
pub open_content: Option<OpenContentResult>,
pub attributes: Vec<AttributeUseResult>,
pub attribute_groups: Vec<QNameRef>,
pub attribute_wildcard: Option<WildcardResult>,
pub assertions: Vec<AssertResult>,
pub id: Option<String>,
pub annotation: Option<Annotation>,
pub source: Option<SourceRef>,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum FacetKind {
Enumeration,
Pattern,
MinInclusive,
MaxInclusive,
MinExclusive,
MaxExclusive,
MinLength,
MaxLength,
Length,
TotalDigits,
FractionDigits,
WhiteSpace,
Assertion,
ExplicitTimezone,
}
#[derive(Debug, Clone)]
pub struct SelectorResult {
pub xpath: String,
pub xpath_default_namespace: Option<String>,
pub ns_snapshot: NamespaceContextSnapshot,
pub id: Option<String>,
pub annotation: Option<Annotation>,
pub source: Option<SourceRef>,
}
#[derive(Debug, Clone)]
pub struct NotationResult {
pub name: Option<NameId>,
pub public: Option<String>,
pub system: Option<String>,
pub id: Option<String>,
pub annotation: Option<Annotation>,
pub source: Option<SourceRef>,
}
#[derive(Debug, Clone)]
pub struct FieldResult {
pub xpath: String,
pub xpath_default_namespace: Option<String>,
pub ns_snapshot: NamespaceContextSnapshot,
pub id: Option<String>,
pub annotation: Option<Annotation>,
pub source: Option<SourceRef>,
}
#[derive(Debug, Clone)]
pub struct AssertResult {
pub test: String,
pub xpath_default_namespace: Option<String>,
pub ns_snapshot: NamespaceContextSnapshot,
pub id: Option<String>,
pub annotation: Option<Annotation>,
pub source: Option<SourceRef>,
}
#[derive(Debug, Clone)]
pub struct AlternativeResult {
pub test: Option<String>,
pub type_ref: Option<TypeRefResult>,
pub inline_type: Option<Box<TypeFrameResult>>,
pub xpath_default_namespace: Option<String>,
pub ns_snapshot: NamespaceContextSnapshot,
pub resolved_type: Option<TypeKey>,
pub id: Option<String>,
pub annotation: Option<Annotation>,
pub source: Option<SourceRef>,
}
#[derive(Debug, Clone)]
pub struct OpenContentResult {
pub mode: OpenContentMode,
pub wildcard: Option<WildcardResult>,
pub id: Option<String>,
pub annotation: Option<Annotation>,
pub source: Option<SourceRef>,
}
#[derive(Debug, Clone)]
pub struct DefaultOpenContentResult {
pub mode: OpenContentMode,
pub applies_to_empty: bool,
pub wildcard: Option<WildcardResult>,
pub id: Option<String>,
pub annotation: Option<Annotation>,
pub source: Option<SourceRef>,
}
#[derive(Debug, Clone)]
pub struct IdentityResult {
pub kind: IdentityKind,
pub name: NameId,
pub ref_name: Option<QNameRef>,
pub refer: Option<QNameRef>,
pub selector: SelectorResult,
pub fields: Vec<FieldResult>,
pub id: Option<String>,
pub annotation: Option<Annotation>,
pub source: Option<SourceRef>,
}
#[derive(Debug, Clone)]
pub struct IdentityRefResult {
pub kind: IdentityKind,
pub ref_name: QNameRef,
pub id: Option<String>,
pub annotation: Option<Annotation>,
pub source: Option<SourceRef>,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum IdentityKind {
Key,
Keyref,
Unique,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum NamespaceToken {
Uri(NameId),
Local,
TargetNamespace,
}
impl NamespaceToken {
pub fn resolve(&self, target_namespace: Option<NameId>) -> Option<NameId> {
match self {
NamespaceToken::Uri(id) => Some(*id),
NamespaceToken::Local => None,
NamespaceToken::TargetNamespace => target_namespace,
}
}
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum NotQNameItem {
QName { namespace: Option<NameId>, local_name: NameId },
Defined,
DefinedSibling,
}
#[derive(Debug, Clone)]
pub struct WildcardResult {
pub namespace: WildcardNamespace,
pub process_contents: ProcessContents,
pub not_namespace: Vec<NamespaceToken>,
pub not_qname: Vec<NotQNameItem>,
pub id: Option<String>,
pub annotation: Option<Annotation>,
pub source: Option<SourceRef>,
}
#[derive(Debug, Clone)]
pub enum WildcardNamespace {
Any,
Other,
TargetNamespace,
Local,
List(Vec<NamespaceToken>),
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
pub enum ProcessContents {
#[default]
Strict,
Lax,
Skip,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum OpenContentMode {
None,
Interleave,
Suffix,
}
#[derive(Debug)]
pub enum DirectiveResult {
Include(IncludeResult),
Import(ImportResult),
Redefine(RedefineResult),
Override(OverrideResult),
}
#[derive(Debug)]
pub struct IncludeResult {
pub schema_location: String,
pub id: Option<String>,
pub annotation: Option<Annotation>,
pub source: Option<SourceRef>,
}
#[derive(Debug)]
pub struct ImportResult {
pub namespace: Option<String>,
pub schema_location: Option<String>,
pub id: Option<String>,
pub annotation: Option<Annotation>,
pub source: Option<SourceRef>,
}
#[derive(Debug)]
pub struct RedefineResult {
pub schema_location: String,
pub id: Option<String>,
pub annotation: Option<Annotation>,
pub components: Vec<RedefineComponent>,
pub source: Option<SourceRef>,
}
#[derive(Debug)]
pub enum RedefineComponent {
SimpleType(Box<SimpleTypeResult>),
ComplexType(Box<ComplexTypeResult>),
Group(Box<ModelGroupDefResult>),
AttributeGroup(Box<AttributeGroupDefResult>),
}
#[derive(Debug)]
pub struct OverrideResult {
pub schema_location: String,
pub id: Option<String>,
pub annotation: Option<Annotation>,
pub source: Option<SourceRef>,
pub simple_types: Vec<SimpleTypeResult>,
pub complex_types: Vec<ComplexTypeResult>,
pub elements: Vec<ElementFrameResult>,
pub attributes: Vec<AttributeFrameResult>,
pub groups: Vec<GroupFrameResult>,
pub attribute_groups: Vec<GroupFrameResult>,
pub notations: Vec<NotationResult>,
}
pub trait Frame {
fn allows(&self, local_name: &str, name_table: &NameTable) -> bool;
fn allows_attribute(&self, local_name: &str, name_table: &NameTable) -> bool;
fn validate_attributes(
&self,
attrs: &AttributeMap,
name_table: &NameTable,
) -> SchemaResult<()> {
for name_id in attrs.names() {
let local_name = match name_table.try_resolve(name_id) {
Some(name) => name,
None => continue,
};
if !self.allows_attribute(&local_name, name_table) {
return Err(SchemaError::structural(
"ct-props-correct",
format!("Attribute '{}' is not allowed here", local_name),
None,
));
}
}
Ok(())
}
fn on_child_start(&mut self, local_name: &str, name_table: &NameTable);
fn attach(&mut self, child: FrameResult) -> SchemaResult<()>;
fn finish(self: Box<Self>) -> SchemaResult<FrameResult>;
fn source(&self) -> Option<&SourceRef>;
fn set_foreign_attributes(&mut self, attrs: Vec<ForeignAttribute>);
fn is_skip_frame(&self) -> bool {
false
}
fn children_are_top_level(&self) -> bool {
false
}
fn children_inside_complex_type(&self) -> bool {
false
}
fn has_annotation(&self) -> bool {
false
}
fn on_child_end(&mut self) -> bool {
false
}
fn accepts_text(&self) -> bool {
false
}
fn accepts_foreign_children(&self) -> bool {
false
}
fn on_text(&mut self, _text: &str) {}
fn on_cdata(&mut self, _cdata: &str) {}
fn set_namespaces(&mut self, _namespaces: NamespaceContextSnapshot) {}
}