165 lines
4.2 KiB
C#
165 lines
4.2 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Xml.Serialization;
|
|
|
|
namespace XSDVisualiser.Models
|
|
{
|
|
/// <summary>
|
|
/// Root of the parsed XSD representation.
|
|
/// </summary>
|
|
[XmlRoot("SchemaModel")]
|
|
public class SchemaModel
|
|
{
|
|
[XmlAttribute]
|
|
public string? TargetNamespace { get; set; }
|
|
|
|
[XmlArray("RootElements")]
|
|
[XmlArrayItem("Element")]
|
|
public List<SchemaNode> RootElements { get; set; } = new();
|
|
}
|
|
|
|
/// <summary>
|
|
/// Represents an element or complex content node in the schema.
|
|
/// </summary>
|
|
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<AttributeInfo> Attributes { get; set; } = new();
|
|
|
|
[XmlArray("Children")]
|
|
[XmlArrayItem("Element")]
|
|
public List<SchemaNode> Children { get; set; } = new();
|
|
|
|
[XmlAttribute]
|
|
public string? ContentModel { get; set; } // sequence | choice | all | simple
|
|
|
|
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();
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Min/Max occurrences.
|
|
/// </summary>
|
|
public class Occurs
|
|
{
|
|
[XmlAttribute]
|
|
public decimal Min { get; set; } = 1;
|
|
|
|
/// <summary>
|
|
/// If MaxIsUnbounded is true, Max is ignored.
|
|
/// </summary>
|
|
[XmlAttribute]
|
|
public decimal Max { get; set; } = 1;
|
|
|
|
[XmlAttribute]
|
|
public bool MaxIsUnbounded { get; set; }
|
|
}
|
|
|
|
/// <summary>
|
|
/// Attribute definition extracted from XSD.
|
|
/// </summary>
|
|
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; }
|
|
}
|
|
|
|
/// <summary>
|
|
/// SimpleType constraints (facets).
|
|
/// </summary>
|
|
public class ConstraintSet
|
|
{
|
|
[XmlAttribute]
|
|
public string? BaseTypeName { get; set; }
|
|
|
|
[XmlArray("Enumerations")]
|
|
[XmlArrayItem("Value")]
|
|
public List<string> Enumerations { get; set; } = new();
|
|
|
|
[XmlArray("Patterns")]
|
|
[XmlArrayItem("Regex")]
|
|
public List<string> Patterns { get; set; } = new();
|
|
|
|
[XmlElement]
|
|
public NumericBounds? Numeric { get; set; }
|
|
|
|
[XmlElement]
|
|
public LengthBounds? Length { get; set; }
|
|
}
|
|
|
|
public class NumericBounds
|
|
{
|
|
[XmlAttribute]
|
|
public string? MinInclusive { get; set; }
|
|
[XmlAttribute]
|
|
public string? MaxInclusive { get; set; }
|
|
[XmlAttribute]
|
|
public string? MinExclusive { get; set; }
|
|
[XmlAttribute]
|
|
public string? MaxExclusive { get; set; }
|
|
}
|
|
|
|
public class LengthBounds
|
|
{
|
|
[XmlAttribute]
|
|
public int Length { get; set; }
|
|
[XmlIgnore]
|
|
public bool LengthSpecified { get; set; }
|
|
|
|
[XmlAttribute]
|
|
public int MinLength { get; set; }
|
|
[XmlIgnore]
|
|
public bool MinLengthSpecified { get; set; }
|
|
|
|
[XmlAttribute]
|
|
public int MaxLength { get; set; }
|
|
[XmlIgnore]
|
|
public bool MaxLengthSpecified { get; set; }
|
|
}
|
|
}
|