using System; using System.Collections.Generic; using System.Xml.Serialization; namespace XSDVisualiser.Models { /// /// Root of the parsed XSD representation. /// [XmlRoot("SchemaModel")] public class SchemaModel { [XmlAttribute] public string? TargetNamespace { get; set; } [XmlArray("RootElements")] [XmlArrayItem("Element")] public List RootElements { get; set; } = new(); } /// /// Represents an element or complex content node in the schema. /// public class SchemaNode { [XmlAttribute] public string? Name { get; set; } [XmlAttribute] public string? Namespace { get; set; } [XmlAttribute] public string? TypeName { get; set; } [XmlAttribute] public string? BuiltInType { get; set; } [XmlAttribute] public bool IsNillable { get; set; } [XmlElement] public Occurs Cardinality { get; set; } = new(); [XmlElement] public ConstraintSet? Constraints { get; set; } [XmlArray("Attributes")] [XmlArrayItem("Attribute")] public List Attributes { get; set; } = new(); [XmlArray("Children")] [XmlArrayItem("Element")] public List Children { get; set; } = new(); [XmlAttribute] public string? ContentModel { get; set; } // sequence | choice | all | simple /// /// Human-readable documentation extracted from xsd:annotation/xsd:documentation. /// Prefer element-level documentation; falls back to type-level documentation. /// [XmlElement] public string? Documentation { get; set; } public override string ToString() { // Used by AutoCompleteBox to get text for filtering and matching // Prefer Name, then TypeName, and fall back to base implementation if (!string.IsNullOrEmpty(Name)) return Name!; if (!string.IsNullOrEmpty(TypeName)) return TypeName!; return base.ToString(); } } /// /// Min/Max occurrences. /// public class Occurs { [XmlAttribute] public decimal Min { get; set; } = 1; /// /// If MaxIsUnbounded is true, Max is ignored. /// [XmlAttribute] public decimal Max { get; set; } = 1; [XmlAttribute] public bool MaxIsUnbounded { get; set; } } /// /// Attribute definition extracted from XSD. /// public class AttributeInfo { [XmlAttribute] public string? Name { get; set; } [XmlAttribute] public string? Namespace { get; set; } [XmlAttribute] public string? Use { get; set; } // optional | required | prohibited [XmlAttribute] public string? TypeName { get; set; } [XmlAttribute] public string? BuiltInType { get; set; } [XmlElement] public ConstraintSet? Constraints { get; set; } } /// /// SimpleType constraints (formerly called facets). /// public class ConstraintSet { [XmlAttribute] public string? BaseTypeName { get; set; } // Generic catch-all list of constraints for dynamic display and tooling [XmlArray("Constraints")] [XmlArrayItem("Constraint")] public List Constraints { get; set; } = new(); } public class ConstraintEntry { [XmlAttribute] public string? Name { get; set; } [XmlAttribute] public string? Value { get; set; } } }