Cleaned up the code

This commit is contained in:
Frederik Jacobsen 2025-10-18 22:28:24 +02:00
parent 5f1d7ef530
commit f8fb0a431f
43 changed files with 1132 additions and 1187 deletions

View File

@ -1,12 +1,12 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net9.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<Compile Include="..\XSDVisualiser\Models\**\*.cs" Link="Models\%(RecursiveDir)%(Filename)%(Extension)" />
<Compile Include="..\XSDVisualiser\Parsing\**\*.cs" Link="Parsing\%(RecursiveDir)%(Filename)%(Extension)" />
<Compile Include="..\XSDVisualiser\Utils\**\*.cs" Link="Utils\%(RecursiveDir)%(Filename)%(Extension)" />
</ItemGroup>
<PropertyGroup>
<TargetFramework>net9.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<Compile Include="..\XSDVisualiser\Models\**\*.cs" Link="Models\%(RecursiveDir)%(Filename)%(Extension)"/>
<Compile Include="..\XSDVisualiser\Parsing\**\*.cs" Link="Parsing\%(RecursiveDir)%(Filename)%(Extension)"/>
<Compile Include="..\XSDVisualiser\Utils\**\*.cs" Link="Utils\%(RecursiveDir)%(Filename)%(Extension)"/>
</ItemGroup>
</Project>

View File

@ -4,32 +4,32 @@
xmlns:conv="clr-namespace:XSDVisualiser.Desktop.Converters"
x:Class="XSDVisualiser.Desktop.App"
RequestedThemeVariant="Light">
<Application.Resources>
<!-- App-level resource brushes for consistent, accessible colors -->
<SolidColorBrush x:Key="AccentBrush" Color="#2563EB"/>
<SolidColorBrush x:Key="AccentBrushLight" Color="#DBEAFE"/>
<SolidColorBrush x:Key="PanelBackgroundBrush" Color="#FFFFFFFF"/>
<SolidColorBrush x:Key="PanelBorderBrush" Color="#E5E7EB"/>
<SolidColorBrush x:Key="SubtleTextBrush" Color="#475569"/>
<SolidColorBrush x:Key="MutedTextBrush" Color="#64748B"/>
<SolidColorBrush x:Key="SeparatorBrush" Color="#E2E8F0"/>
<SolidColorBrush x:Key="BadgeBackgroundBrush" Color="#F1F5F9"/>
<Application.Resources>
<!-- App-level resource brushes for consistent, accessible colors -->
<SolidColorBrush x:Key="AccentBrush" Color="#2563EB" />
<SolidColorBrush x:Key="AccentBrushLight" Color="#DBEAFE" />
<SolidColorBrush x:Key="PanelBackgroundBrush" Color="#FFFFFFFF" />
<SolidColorBrush x:Key="PanelBorderBrush" Color="#E5E7EB" />
<SolidColorBrush x:Key="SubtleTextBrush" Color="#475569" />
<SolidColorBrush x:Key="MutedTextBrush" Color="#64748B" />
<SolidColorBrush x:Key="SeparatorBrush" Color="#E2E8F0" />
<SolidColorBrush x:Key="BadgeBackgroundBrush" Color="#F1F5F9" />
<!-- Global converters -->
<conv:CardinalityToLabelConverter x:Key="CardinalityToLabel"/>
<conv:OptionalToBorderBrushConverter x:Key="OptionalToBrush"/>
<conv:OptionalToThicknessConverter x:Key="OptionalToThickness"/>
<conv:CollectionHasItemsConverter x:Key="HasItems"/>
</Application.Resources>
<!-- Global converters -->
<conv:CardinalityToLabelConverter x:Key="CardinalityToLabel" />
<conv:OptionalToBorderBrushConverter x:Key="OptionalToBrush" />
<conv:OptionalToThicknessConverter x:Key="OptionalToThickness" />
<conv:CollectionHasItemsConverter x:Key="HasItems" />
</Application.Resources>
<Application.Styles>
<!-- Use Fluent theme for consistent UI controls -->
<fluent:FluentTheme/>
<Application.Styles>
<!-- Use Fluent theme for consistent UI controls -->
<fluent:FluentTheme />
<!-- Default TextBlock accessibility improvements -->
<Style Selector="TextBlock">
<Setter Property="TextWrapping" Value="Wrap"/>
<Setter Property="TextTrimming" Value="CharacterEllipsis"/>
</Style>
</Application.Styles>
<!-- Default TextBlock accessibility improvements -->
<Style Selector="TextBlock">
<Setter Property="TextWrapping" Value="Wrap" />
<Setter Property="TextTrimming" Value="CharacterEllipsis" />
</Style>
</Application.Styles>
</Application>

View File

@ -2,22 +2,19 @@ using Avalonia;
using Avalonia.Controls.ApplicationLifetimes;
using Avalonia.Markup.Xaml;
namespace XSDVisualiser.Desktop
{
public partial class App : Application
{
public override void Initialize()
{
AvaloniaXamlLoader.Load(this);
}
namespace XSDVisualiser.Desktop;
public override void OnFrameworkInitializationCompleted()
{
if (ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktop)
{
desktop.MainWindow = new MainWindow();
}
base.OnFrameworkInitializationCompleted();
}
public class App : Application
{
public override void Initialize()
{
AvaloniaXamlLoader.Load(this);
}
public override void OnFrameworkInitializationCompleted()
{
if (ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktop)
desktop.MainWindow = new MainWindow();
base.OnFrameworkInitializationCompleted();
}
}

View File

@ -1,22 +1,22 @@
using System;
using System.Globalization;
using Avalonia.Data.Converters;
using XSDVisualiser.Models;
using XSDVisualiser.Core;
namespace XSDVisualiser.Desktop.Converters
namespace XSDVisualiser.Desktop.Converters;
public class CardinalityToLabelConverter : IValueConverter
{
public class CardinalityToLabelConverter : IValueConverter
public object? Convert(object? value, Type targetType, object? parameter, CultureInfo culture)
{
public object? Convert(object? value, Type targetType, object? parameter, CultureInfo culture)
{
if (value is not Occurs occ) return null;
if (value is not Occurs occ) return null;
var min = occ.Min;
var max = occ.MaxIsUnbounded ? "*" : occ.Max.ToString(culture);
return $"[{min}..{max}]";
}
var min = occ.Min;
var max = occ.MaxIsUnbounded ? "*" : occ.Max.ToString(culture);
return $"[{min}..{max}]";
}
public object? ConvertBack(object? value, Type targetType, object? parameter, CultureInfo culture)
=> throw new NotSupportedException();
public object? ConvertBack(object? value, Type targetType, object? parameter, CultureInfo culture)
{
throw new NotSupportedException();
}
}

View File

@ -1,37 +1,37 @@
using System;
using System.Collections;
using System.Globalization;
using Avalonia.Data.Converters;
namespace XSDVisualiser.Desktop.Converters
{
/// <summary>
/// Returns true if the bound value is a collection with at least one item. Supports IEnumerable and ICollection.
/// Optional parameter "Invert" to invert the boolean result.
/// </summary>
public sealed class CollectionHasItemsConverter : IValueConverter
{
public object? Convert(object? value, Type targetType, object? parameter, CultureInfo culture)
{
var hasItems = false;
switch (value)
{
case ICollection coll:
hasItems = coll.Count > 0;
break;
case IEnumerable enumerable:
{
var enumerator = enumerable.GetEnumerator();
hasItems = enumerator.MoveNext();
break;
}
}
namespace XSDVisualiser.Desktop.Converters;
var invert = parameter is string s && s.Equals("Invert", StringComparison.OrdinalIgnoreCase);
return invert ? !hasItems : hasItems;
/// <summary>
/// Returns true if the bound value is a collection with at least one item. Supports IEnumerable and ICollection.
/// Optional parameter "Invert" to invert the boolean result.
/// </summary>
public sealed class CollectionHasItemsConverter : IValueConverter
{
public object? Convert(object? value, Type targetType, object? parameter, CultureInfo culture)
{
var hasItems = false;
switch (value)
{
case ICollection coll:
hasItems = coll.Count > 0;
break;
case IEnumerable enumerable:
{
var enumerator = enumerable.GetEnumerator();
hasItems = enumerator.MoveNext();
break;
}
}
public object? ConvertBack(object? value, Type targetType, object? parameter, CultureInfo culture)
=> throw new NotSupportedException();
var invert = parameter is string s && s.Equals("Invert", StringComparison.OrdinalIgnoreCase);
return invert ? !hasItems : hasItems;
}
public object? ConvertBack(object? value, Type targetType, object? parameter, CultureInfo culture)
{
throw new NotSupportedException();
}
}

View File

@ -1,27 +1,25 @@
using System;
using System.Globalization;
using Avalonia.Data.Converters;
using Avalonia.Media;
using XSDVisualiser.Models;
using XSDVisualiser.Core;
namespace XSDVisualiser.Desktop.Converters
namespace XSDVisualiser.Desktop.Converters;
public class OptionalToBorderBrushConverter : IValueConverter
{
public class OptionalToBorderBrushConverter : IValueConverter
private static readonly IBrush RequiredBrush = new SolidColorBrush(Color.FromRgb(0x33, 0x99, 0x33));
private static readonly IBrush OptionalBrush = new SolidColorBrush(Color.FromRgb(0xCC, 0x66, 0x33));
public object? Convert(object? value, Type targetType, object? parameter, CultureInfo culture)
{
private static readonly IBrush RequiredBrush = new SolidColorBrush(Color.FromRgb(0x33, 0x99, 0x33));
private static readonly IBrush OptionalBrush = new SolidColorBrush(Color.FromRgb(0xCC, 0x66, 0x33));
if (value is Occurs occ)
// Optional if minOccurs == 0
return occ.Min == 0 ? OptionalBrush : RequiredBrush;
return RequiredBrush;
}
public object? Convert(object? value, Type targetType, object? parameter, CultureInfo culture)
{
if (value is Occurs occ)
{
// Optional if minOccurs == 0
return occ.Min == 0 ? OptionalBrush : RequiredBrush;
}
return RequiredBrush;
}
public object? ConvertBack(object? value, Type targetType, object? parameter, CultureInfo culture)
=> throw new NotSupportedException();
public object? ConvertBack(object? value, Type targetType, object? parameter, CultureInfo culture)
{
throw new NotSupportedException();
}
}

View File

@ -1,27 +1,25 @@
using System;
using System.Globalization;
using Avalonia;
using Avalonia.Data.Converters;
using XSDVisualiser.Models;
using XSDVisualiser.Core;
namespace XSDVisualiser.Desktop.Converters
namespace XSDVisualiser.Desktop.Converters;
public class OptionalToThicknessConverter : IValueConverter
{
public class OptionalToThicknessConverter : IValueConverter
private static readonly Thickness Required = new(2);
private static readonly Thickness Optional = new(2);
public object? Convert(object? value, Type targetType, object? parameter, CultureInfo culture)
{
private static readonly Thickness Required = new Thickness(2);
private static readonly Thickness Optional = new Thickness(2);
if (value is Occurs occ)
// We could vary thickness; for now same thickness regardless, reserved for future styling.
return occ.Min == 0 ? Optional : Required;
return Required;
}
public object? Convert(object? value, Type targetType, object? parameter, CultureInfo culture)
{
if (value is Occurs occ)
{
// We could vary thickness; for now same thickness regardless, reserved for future styling.
return occ.Min == 0 ? Optional : Required;
}
return Required;
}
public object? ConvertBack(object? value, Type targetType, object? parameter, CultureInfo culture)
=> throw new NotSupportedException();
public object? ConvertBack(object? value, Type targetType, object? parameter, CultureInfo culture)
{
throw new NotSupportedException();
}
}

View File

@ -10,7 +10,8 @@
<Grid Grid.Row="1" ColumnDefinitions="2*,Auto,*" RowDefinitions="*">
<views:LeftTreeView Grid.Column="0" />
<GridSplitter Grid.Column="1" Width="6" Margin="4,8" Background="{DynamicResource PanelBorderBrush}" ShowsPreview="True"/>
<GridSplitter Grid.Column="1" Width="6" Margin="4,8" Background="{DynamicResource PanelBorderBrush}"
ShowsPreview="True" />
<views:RightDetailsView Grid.Column="2" />
</Grid>
</Grid>

View File

@ -1,12 +1,11 @@
using Avalonia.Controls;
namespace XSDVisualiser.Desktop
namespace XSDVisualiser.Desktop;
public partial class MainWindow : Window
{
public partial class MainWindow : Window
public MainWindow()
{
public MainWindow()
{
InitializeComponent();
}
InitializeComponent();
}
}

View File

@ -1,21 +1,21 @@
using System;
using Avalonia;
using Avalonia.ReactiveUI;
namespace XSDVisualiser.Desktop
{
internal static class Program
{
[STAThread]
public static void Main(string[] args)
{
BuildAvaloniaApp().StartWithClassicDesktopLifetime(args);
}
namespace XSDVisualiser.Desktop;
private static AppBuilder BuildAvaloniaApp() =>
AppBuilder.Configure<App>()
.UsePlatformDetect()
.LogToTrace()
.UseReactiveUI();
internal static class Program
{
[STAThread]
public static void Main(string[] args)
{
BuildAvaloniaApp().StartWithClassicDesktopLifetime(args);
}
private static AppBuilder BuildAvaloniaApp()
{
return AppBuilder.Configure<App>()
.UsePlatformDetect()
.LogToTrace()
.UseReactiveUI();
}
}

View File

@ -1,80 +1,80 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Runtime.CompilerServices;
using XSDVisualiser.Models;
using XSDVisualiser.Core;
namespace XSDVisualiser.Desktop.ViewModels
namespace XSDVisualiser.Desktop.ViewModels;
public class MainWindowViewModel(SchemaModel model) : INotifyPropertyChanged
{
public class MainWindowViewModel(SchemaModel model) : INotifyPropertyChanged
private string? _currentFilePath;
private SchemaModel _model = model ?? throw new ArgumentNullException(nameof(model));
private SchemaNode? _selectedNode;
private SchemaNode? _selectedRootElement;
public SchemaModel Model
{
private SchemaModel _model = model ?? throw new ArgumentNullException(nameof(model));
private SchemaNode? _selectedRootElement;
private SchemaNode? _selectedNode;
public event PropertyChangedEventHandler? PropertyChanged;
private void OnPropertyChanged([CallerMemberName] string? name = null)
get => _model;
set
{
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(name));
if (ReferenceEquals(_model, value)) return;
_model = value ?? throw new ArgumentNullException(nameof(value));
OnPropertyChanged();
OnPropertyChanged(nameof(RootElements));
OnPropertyChanged(nameof(VisibleRootElements));
}
}
public SchemaModel Model
public IEnumerable<SchemaNode> RootElements => _model?.RootElements ?? Enumerable.Empty<SchemaNode>();
public SchemaNode? SelectedRootElement
{
get => _selectedRootElement;
set
{
get => _model;
set
{
if (ReferenceEquals(_model, value)) return;
_model = value ?? throw new ArgumentNullException(nameof(value));
OnPropertyChanged();
OnPropertyChanged(nameof(RootElements));
OnPropertyChanged(nameof(VisibleRootElements));
}
if (EqualityComparer<SchemaNode?>.Default.Equals(_selectedRootElement, value)) return;
_selectedRootElement = value;
OnPropertyChanged();
OnPropertyChanged(nameof(VisibleRootElements));
}
}
public IEnumerable<SchemaNode> RootElements => _model?.RootElements ?? Enumerable.Empty<SchemaNode>();
public SchemaNode? SelectedRootElement
public SchemaNode? SelectedNode
{
get => _selectedNode;
set
{
get => _selectedRootElement;
set
{
if (EqualityComparer<SchemaNode?>.Default.Equals(_selectedRootElement, value)) return;
_selectedRootElement = value;
OnPropertyChanged();
OnPropertyChanged(nameof(VisibleRootElements));
}
if (EqualityComparer<SchemaNode?>.Default.Equals(_selectedNode, value)) return;
_selectedNode = value;
OnPropertyChanged();
}
}
public SchemaNode? SelectedNode
public IEnumerable<SchemaNode> VisibleRootElements =>
SelectedRootElement != null ? [SelectedRootElement] : RootElements;
public string? CurrentFilePath
{
get => _currentFilePath;
set
{
get => _selectedNode;
set
{
if (EqualityComparer<SchemaNode?>.Default.Equals(_selectedNode, value)) return;
_selectedNode = value;
OnPropertyChanged();
}
if (string.Equals(_currentFilePath, value, StringComparison.Ordinal)) return;
_currentFilePath = value;
OnPropertyChanged();
OnPropertyChanged(nameof(CurrentFileName));
OnPropertyChanged(nameof(CurrentDirectory));
}
}
public IEnumerable<SchemaNode> VisibleRootElements => SelectedRootElement != null ? [SelectedRootElement] : RootElements;
public string? CurrentFileName =>
string.IsNullOrEmpty(_currentFilePath) ? null : Path.GetFileName(_currentFilePath);
private string? _currentFilePath;
public string? CurrentFilePath
{
get => _currentFilePath;
set
{
if (string.Equals(_currentFilePath, value, StringComparison.Ordinal)) return;
_currentFilePath = value;
OnPropertyChanged();
OnPropertyChanged(nameof(CurrentFileName));
OnPropertyChanged(nameof(CurrentDirectory));
}
}
public string? CurrentDirectory =>
string.IsNullOrEmpty(_currentFilePath) ? null : Path.GetDirectoryName(_currentFilePath);
public string? CurrentFileName => string.IsNullOrEmpty(_currentFilePath) ? null : System.IO.Path.GetFileName(_currentFilePath);
public string? CurrentDirectory => string.IsNullOrEmpty(_currentFilePath) ? null : System.IO.Path.GetDirectoryName(_currentFilePath);
public event PropertyChangedEventHandler? PropertyChanged;
private void OnPropertyChanged([CallerMemberName] string? name = null)
{
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(name));
}
}

View File

@ -8,23 +8,23 @@
FontSize="20"
FontWeight="SemiBold"
Margin="0,0,12,0"
VerticalAlignment="Center"/>
VerticalAlignment="Center" />
<AutoCompleteBox Grid.Column="1"
Margin="0,0,12,0"
Watermark="Search and choose a root element"
ItemsSource="{Binding RootElements}"
FilterMode="Contains"
MinimumPrefixLength="0"
HorizontalAlignment="Stretch"
VerticalAlignment="Center">
Margin="0,0,12,0"
Watermark="Search and choose a root element"
ItemsSource="{Binding RootElements}"
FilterMode="Contains"
MinimumPrefixLength="0"
HorizontalAlignment="Stretch"
VerticalAlignment="Center">
<AutoCompleteBox.ItemTemplate>
<DataTemplate>
<TextBlock Text="{Binding .}"/>
<TextBlock Text="{Binding .}" />
</DataTemplate>
</AutoCompleteBox.ItemTemplate>
<AutoCompleteBox.SelectedItem>
<Binding Path="SelectedRootElement" Mode="TwoWay"/>
<Binding Path="SelectedRootElement" Mode="TwoWay" />
</AutoCompleteBox.SelectedItem>
</AutoCompleteBox>
@ -32,7 +32,7 @@
Content="Open XSD and parse"
x:Name="OpenBtn"
Width="220"
VerticalAlignment="Center"/>
VerticalAlignment="Center" />
<Border Grid.Column="3"
Background="{DynamicResource PanelBackgroundBrush}"
@ -46,15 +46,16 @@
ToolTip.Tip="{Binding CurrentFilePath}">
<Border.ContextMenu>
<ContextMenu>
<MenuItem Header="Copy path" Click="OnCopyPathClick"/>
<MenuItem Header="Open containing folder" Click="OnOpenContainingFolderClick"/>
<MenuItem Header="Copy path" Click="OnCopyPathClick" />
<MenuItem Header="Open containing folder" Click="OnOpenContainingFolderClick" />
</ContextMenu>
</Border.ContextMenu>
<StackPanel Orientation="Horizontal" Spacing="8">
<TextBlock Text="File:" Foreground="{DynamicResource SubtleTextBrush}"/>
<TextBlock Text="File:" Foreground="{DynamicResource SubtleTextBrush}" />
<StackPanel MaxWidth="520">
<TextBlock Text="{Binding CurrentFileName}" FontWeight="SemiBold" TextTrimming="CharacterEllipsis"/>
<TextBlock Text="{Binding CurrentDirectory}" Foreground="{DynamicResource SubtleTextBrush}" TextTrimming="CharacterEllipsis"/>
<TextBlock Text="{Binding CurrentFileName}" FontWeight="SemiBold" TextTrimming="CharacterEllipsis" />
<TextBlock Text="{Binding CurrentDirectory}" Foreground="{DynamicResource SubtleTextBrush}"
TextTrimming="CharacterEllipsis" />
</StackPanel>
</StackPanel>
</Border>

View File

@ -1,12 +1,9 @@
using System;
using System.Threading.Tasks;
using Avalonia;
using System.Diagnostics;
using Avalonia.Controls;
using Avalonia.Interactivity;
using Avalonia.Threading;
using Avalonia.Platform.Storage;
using Avalonia.Threading;
using XSDVisualiser.Core;
using XSDVisualiser.Models;
using XSDVisualiser.Desktop.ViewModels;
namespace XSDVisualiser.Desktop.Views;
@ -19,10 +16,7 @@ public partial class HeaderView : UserControl
{
InitializeComponent();
_openBtn = this.FindControl<Button>("OpenBtn");
if (_openBtn != null)
{
_openBtn.Click += OpenBtn_Click;
}
if (_openBtn != null) _openBtn.Click += OpenBtn_Click;
}
private async void OpenBtn_Click(object? sender, RoutedEventArgs e)
@ -49,13 +43,10 @@ public partial class HeaderView : UserControl
var file = results[0];
var path = file.TryGetLocalPath();
if (!string.IsNullOrEmpty(path))
{
await ParseAndShowAsync(path!, topLevel);
}
else
{
Dispatcher.UIThread.Post(() => topLevel.DataContext = new MainWindowViewModel(new SchemaModel { TargetNamespace = "Selected file is not a local file. Please choose a local .xsd." }));
}
Dispatcher.UIThread.Post(() => topLevel.DataContext = new MainWindowViewModel(new SchemaModel
{ TargetNamespace = "Selected file is not a local file. Please choose a local .xsd." }));
}
private Task ParseAndShowAsync(string path, Window hostWindow)
@ -77,7 +68,8 @@ public partial class HeaderView : UserControl
}
catch (Exception ex)
{
Dispatcher.UIThread.Post(() => hostWindow.DataContext = new MainWindowViewModel(new SchemaModel { TargetNamespace = ex.Message }));
Dispatcher.UIThread.Post(() =>
hostWindow.DataContext = new MainWindowViewModel(new SchemaModel { TargetNamespace = ex.Message }));
}
});
}
@ -89,10 +81,7 @@ public partial class HeaderView : UserControl
if (string.IsNullOrWhiteSpace(path)) return;
var topLevel = TopLevel.GetTopLevel(this);
if (topLevel?.Clipboard != null)
{
await topLevel.Clipboard.SetTextAsync(path);
}
if (topLevel?.Clipboard != null) await topLevel.Clipboard.SetTextAsync(path);
}
private void OnOpenContainingFolderClick(object? sender, RoutedEventArgs e)
@ -100,8 +89,8 @@ public partial class HeaderView : UserControl
var vm = DataContext as MainWindowViewModel;
var path = vm?.CurrentFilePath;
if (string.IsNullOrWhiteSpace(path)) return;
var dir = System.IO.Path.GetDirectoryName(path);
if (string.IsNullOrWhiteSpace(dir) || !System.IO.Directory.Exists(dir)) return;
var dir = Path.GetDirectoryName(path);
if (string.IsNullOrWhiteSpace(dir) || !Directory.Exists(dir)) return;
TryOpenFolder(dir);
}
@ -111,32 +100,32 @@ public partial class HeaderView : UserControl
{
if (OperatingSystem.IsWindows())
{
var psi = new System.Diagnostics.ProcessStartInfo("explorer.exe", dir)
var psi = new ProcessStartInfo("explorer.exe", dir)
{
UseShellExecute = true
};
System.Diagnostics.Process.Start(psi);
Process.Start(psi);
}
else if (OperatingSystem.IsMacOS())
{
System.Diagnostics.Process.Start("open", dir);
Process.Start("open", dir);
}
else
{
// Linux
System.Diagnostics.Process.Start("xdg-open", dir);
Process.Start("xdg-open", dir);
}
}
catch
{
try
{
var psi = new System.Diagnostics.ProcessStartInfo
var psi = new ProcessStartInfo
{
FileName = dir,
UseShellExecute = true
};
System.Diagnostics.Process.Start(psi);
Process.Start(psi);
}
catch
{

View File

@ -1,65 +1,70 @@
<UserControl xmlns="https://github.com/avaloniaui"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:m="clr-namespace:XSDVisualiser.Models;assembly=XSDVisualiser.Core"
xmlns:m="clr-namespace:XSDVisualiser.Core;assembly=XSDVisualiser.Core"
x:Class="XSDVisualiser.Desktop.Views.LeftTreeView"
x:CompileBindings="False">
<Border Background="{DynamicResource PanelBackgroundBrush}"
BorderBrush="{DynamicResource PanelBorderBrush}"
BorderThickness="1" CornerRadius="6" Margin="0,8,8,0">
<ScrollViewer>
<TreeView x:Name="SchemaTree" ItemsSource="{Binding VisibleRootElements}" SelectedItem="{Binding SelectedNode, Mode=TwoWay}">
<TreeView.DataTemplates>
<TreeDataTemplate DataType="{x:Type m:SchemaNode}" ItemsSource="{Binding Children}">
<StackPanel>
<!-- Connector line from parent to this node (hidden for roots where ContentModel is null) -->
<Grid Margin="0,8,8,2" IsVisible="{Binding ContentModel, Converter={x:Static ObjectConverters.IsNotNull}}"
ColumnDefinitions="16,*">
<!-- leading small elbow -->
<Rectangle Grid.Column="0" Width="16" Height="2" Fill="{DynamicResource SeparatorBrush}" VerticalAlignment="Center"/>
<Grid Grid.Column="1">
<Rectangle Height="2" Fill="{DynamicResource SeparatorBrush}" VerticalAlignment="Center"/>
<TextBlock Text="{Binding Cardinality, Converter={StaticResource CardinalityToLabel}}"
Background="{DynamicResource BadgeBackgroundBrush}" Padding="6,0"
Foreground="{DynamicResource SubtleTextBrush}"
HorizontalAlignment="Center"/>
</Grid>
</Grid>
<Border Background="{DynamicResource PanelBackgroundBrush}"
BorderBrush="{DynamicResource PanelBorderBrush}"
BorderThickness="1" CornerRadius="6" Margin="0,8,8,0">
<ScrollViewer>
<TreeView x:Name="SchemaTree" ItemsSource="{Binding VisibleRootElements}"
SelectedItem="{Binding SelectedNode, Mode=TwoWay}">
<TreeView.DataTemplates>
<TreeDataTemplate DataType="{x:Type m:SchemaNode}" ItemsSource="{Binding Children}">
<StackPanel>
<!-- Connector line from parent to this node (hidden for roots where ContentModel is null) -->
<Grid Margin="0,8,8,2"
IsVisible="{Binding ContentModel, Converter={x:Static ObjectConverters.IsNotNull}}"
ColumnDefinitions="16,*">
<!-- leading small elbow -->
<Rectangle Grid.Column="0" Width="16" Height="2"
Fill="{DynamicResource SeparatorBrush}" VerticalAlignment="Center" />
<Grid Grid.Column="1">
<Rectangle Height="2" Fill="{DynamicResource SeparatorBrush}"
VerticalAlignment="Center" />
<TextBlock
Text="{Binding Cardinality, Converter={StaticResource CardinalityToLabel}}"
Background="{DynamicResource BadgeBackgroundBrush}" Padding="6,0"
Foreground="{DynamicResource SubtleTextBrush}"
HorizontalAlignment="Center" />
</Grid>
</Grid>
<!-- Node content -->
<Border CornerRadius="4"
BorderBrush="{Binding Cardinality, Converter={StaticResource OptionalToBrush}}"
BorderThickness="{Binding Cardinality, Converter={StaticResource OptionalToThickness}}"
Padding="8" Margin="0,0,8,6" Background="{DynamicResource PanelBackgroundBrush}">
<Border.ContextMenu>
<ContextMenu>
<MenuItem Header="Copy as TSV" Click="OnCopyAsTsvClick"/>
</ContextMenu>
</Border.ContextMenu>
<StackPanel Orientation="Vertical" Spacing="2">
<!-- Name on its own line, prominent -->
<TextBlock Text="{Binding Name}" FontWeight="SemiBold"/>
<!-- Node content -->
<Border CornerRadius="4"
BorderBrush="{Binding Cardinality, Converter={StaticResource OptionalToBrush}}"
BorderThickness="{Binding Cardinality, Converter={StaticResource OptionalToThickness}}"
Padding="8" Margin="0,0,8,6" Background="{DynamicResource PanelBackgroundBrush}">
<Border.ContextMenu>
<ContextMenu>
<MenuItem Header="Copy as TSV" Click="OnCopyAsTsvClick" />
</ContextMenu>
</Border.ContextMenu>
<StackPanel Orientation="Vertical" Spacing="2">
<!-- Name on its own line, prominent -->
<TextBlock Text="{Binding Name}" FontWeight="SemiBold" />
<!-- Path/Namespace on its own line -->
<TextBlock Text="{Binding Namespace, StringFormat=Namespace: {0}}"
Foreground="{DynamicResource SubtleTextBrush}"/>
<!-- Path/Namespace on its own line -->
<TextBlock Text="{Binding Namespace, StringFormat=Namespace: {0}}"
Foreground="{DynamicResource SubtleTextBrush}" />
<!-- Type info on its own line (TypeName with fallback to BuiltInType) -->
<StackPanel Orientation="Horizontal" Spacing="6">
<TextBlock Text="Type:" FontWeight="Medium"/>
<TextBlock Text="{Binding TypeName}"/>
<TextBlock Text="{Binding BuiltInType, StringFormat=({0})}"
Foreground="{DynamicResource MutedTextBrush}"/>
</StackPanel>
<!-- Type info on its own line (TypeName with fallback to BuiltInType) -->
<StackPanel Orientation="Horizontal" Spacing="6">
<TextBlock Text="Type:" FontWeight="Medium" />
<TextBlock Text="{Binding TypeName}" />
<TextBlock Text="{Binding BuiltInType, StringFormat=({0})}"
Foreground="{DynamicResource MutedTextBrush}" />
</StackPanel>
<!-- Optional: show content model as a subtle hint -->
<TextBlock Text="{Binding ContentModel, StringFormat=Model: {0}}"
Foreground="{DynamicResource SubtleTextBrush}" FontWeight="SemiBold"/>
</StackPanel>
</Border>
</StackPanel>
</TreeDataTemplate>
</TreeView.DataTemplates>
</TreeView>
</ScrollViewer>
</Border>
<!-- Optional: show content model as a subtle hint -->
<TextBlock Text="{Binding ContentModel, StringFormat=Model: {0}}"
Foreground="{DynamicResource SubtleTextBrush}" FontWeight="SemiBold" />
</StackPanel>
</Border>
</StackPanel>
</TreeDataTemplate>
</TreeView.DataTemplates>
</TreeView>
</ScrollViewer>
</Border>
</UserControl>

View File

@ -1,117 +1,115 @@
using System.Globalization;
using System.Text;
using Avalonia;
using Avalonia.Controls;
using Avalonia.Interactivity;
using Avalonia.VisualTree;
using XSDVisualiser.Models;
using XSDVisualiser.Core;
namespace XSDVisualiser.Desktop.Views
namespace XSDVisualiser.Desktop.Views;
public partial class LeftTreeView : UserControl
{
public partial class LeftTreeView : UserControl
public LeftTreeView()
{
public LeftTreeView()
InitializeComponent();
}
private async void OnCopyAsTsvClick(object? sender, RoutedEventArgs e)
{
// Determine the node from the menu item's DataContext
var node = (sender as MenuItem)?.DataContext as SchemaNode;
if (node == null)
node =
(sender as Control)?.GetVisualAncestors().OfType<Control>().FirstOrDefault()?.DataContext as SchemaNode;
if (node == null)
return;
var tsv = BuildTsv(node);
var topLevel = TopLevel.GetTopLevel(this);
if (topLevel?.Clipboard != null) await topLevel.Clipboard.SetTextAsync(tsv);
}
private static string BuildTsv(SchemaNode root)
{
var sb = new StringBuilder();
// Header
sb.AppendLine(
"Depth\tPath\tName\tNamespace\tTypeName\tBuiltInType\tMinOccurs\tMaxOccurs\tContentModel\tConstraints\tIsNillable");
var initialPath = root.Name ?? string.Empty;
AppendNode(sb, root, 0, initialPath);
return sb.ToString();
}
private static void AppendNode(StringBuilder sb, SchemaNode node, int depth, string path)
{
string San(string? s)
{
InitializeComponent();
if (string.IsNullOrEmpty(s)) return string.Empty;
return s.Replace("\t", " ").Replace("\r", " ").Replace("\n", " ");
}
private async void OnCopyAsTsvClick(object? sender, RoutedEventArgs e)
var min = node.Cardinality?.Min.ToString(CultureInfo.InvariantCulture) ?? string.Empty;
string max;
if (node.Cardinality?.MaxIsUnbounded == true)
max = "unbounded";
else
max = node.Cardinality != null ? node.Cardinality.Max.ToString(CultureInfo.InvariantCulture) : string.Empty;
var line = string.Join("\t", new[]
{
// Determine the node from the menu item's DataContext
var node = (sender as MenuItem)?.DataContext as SchemaNode;
if (node == null)
node = (sender as Control)?.GetVisualAncestors().OfType<Control>().FirstOrDefault()?.DataContext as SchemaNode;
if (node == null)
return;
depth.ToString(CultureInfo.InvariantCulture),
San(path),
San(node.Name),
San(node.Namespace),
San(node.TypeName),
San(node.BuiltInType),
min,
max,
San(node.ContentModel),
San(FormatConstraints(node)),
node.IsNillable ? "true" : "false"
});
sb.AppendLine(line);
var tsv = BuildTsv(node);
var topLevel = TopLevel.GetTopLevel(this);
if (topLevel?.Clipboard != null)
if (node.Children != null)
foreach (var child in node.Children)
{
await topLevel.Clipboard.SetTextAsync(tsv);
var nextPathSegment = child.Name ?? string.Empty;
var childPath = string.IsNullOrEmpty(San(path)) ? nextPathSegment : $"{path}/{nextPathSegment}";
AppendNode(sb, child, depth + 1, childPath);
}
}
private static string FormatConstraints(SchemaNode node)
{
var cons = node.Constraints?.Constraints;
if (cons == null || cons.Count == 0) return string.Empty;
var dict = new SortedDictionary<string, SortedSet<string>>(StringComparer.Ordinal);
foreach (var c in cons)
{
var name = c.Name;
var value = c.Value;
if (string.IsNullOrEmpty(name) || string.IsNullOrEmpty(value)) continue;
if (!dict.TryGetValue(name, out var set))
{
set = new SortedSet<string>(StringComparer.Ordinal);
dict[name] = set;
}
set.Add(value);
}
private static string BuildTsv(SchemaNode root)
if (dict.Count == 0) return string.Empty;
var parts = new List<string>(dict.Count);
foreach (var kvp in dict)
{
var sb = new StringBuilder();
// Header
sb.AppendLine("Depth\tPath\tName\tNamespace\tTypeName\tBuiltInType\tMinOccurs\tMaxOccurs\tContentModel\tConstraints\tIsNillable");
var initialPath = root.Name ?? string.Empty;
AppendNode(sb, root, 0, initialPath);
return sb.ToString();
var joinedValues = string.Join(",", kvp.Value);
parts.Add($"{kvp.Key}={joinedValues}");
}
private static void AppendNode(StringBuilder sb, SchemaNode node, int depth, string path)
{
string San(string? s)
{
if (string.IsNullOrEmpty(s)) return string.Empty;
return s.Replace("\t", " ").Replace("\r", " ").Replace("\n", " ");
}
var min = node.Cardinality?.Min.ToString(CultureInfo.InvariantCulture) ?? string.Empty;
string max;
if (node.Cardinality?.MaxIsUnbounded == true)
max = "unbounded";
else
max = node.Cardinality != null ? node.Cardinality.Max.ToString(CultureInfo.InvariantCulture) : string.Empty;
var line = string.Join("\t", new[]
{
depth.ToString(CultureInfo.InvariantCulture),
San(path),
San(node.Name),
San(node.Namespace),
San(node.TypeName),
San(node.BuiltInType),
min,
max,
San(node.ContentModel),
San(FormatConstraints(node)),
node.IsNillable ? "true" : "false"
});
sb.AppendLine(line);
if (node.Children != null)
{
foreach (var child in node.Children)
{
var nextPathSegment = child.Name ?? string.Empty;
var childPath = string.IsNullOrEmpty(San(path)) ? nextPathSegment : $"{path}/{nextPathSegment}";
AppendNode(sb, child, depth + 1, childPath);
}
}
}
private static string FormatConstraints(SchemaNode node)
{
var cons = node.Constraints?.Constraints;
if (cons == null || cons.Count == 0) return string.Empty;
var dict = new System.Collections.Generic.SortedDictionary<string, System.Collections.Generic.SortedSet<string>>(System.StringComparer.Ordinal);
foreach (var c in cons)
{
var name = c.Name;
var value = c.Value;
if (string.IsNullOrEmpty(name) || string.IsNullOrEmpty(value)) continue;
if (!dict.TryGetValue(name, out var set))
{
set = new System.Collections.Generic.SortedSet<string>(System.StringComparer.Ordinal);
dict[name] = set;
}
set.Add(value);
}
if (dict.Count == 0) return string.Empty;
var parts = new System.Collections.Generic.List<string>(dict.Count);
foreach (var kvp in dict)
{
var joinedValues = string.Join(",", kvp.Value);
parts.Add($"{kvp.Key}={joinedValues}");
}
return string.Join(";", parts);
}
return string.Join(";", parts);
}
}

View File

@ -1,86 +1,94 @@
<UserControl xmlns="https://github.com/avaloniaui"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:m="clr-namespace:XSDVisualiser.Models;assembly=XSDVisualiser.Core"
xmlns:core="clr-namespace:XSDVisualiser.Core;assembly=XSDVisualiser.Core"
x:Class="XSDVisualiser.Desktop.Views.RightDetailsView"
x:CompileBindings="False">
<Border Background="{DynamicResource PanelBackgroundBrush}"
BorderBrush="{DynamicResource PanelBorderBrush}"
BorderThickness="1" CornerRadius="6" Margin="8,8,0,0">
<ScrollViewer>
<ContentControl Content="{Binding SelectedNode}">
<ContentControl.DataTemplates>
<DataTemplate DataType="{x:Type m:SchemaNode}">
<StackPanel Margin="12" Spacing="12">
<TextBlock Text="Details" FontSize="16" FontWeight="SemiBold"/>
<Border Background="{DynamicResource PanelBackgroundBrush}"
BorderBrush="{DynamicResource PanelBorderBrush}"
BorderThickness="1" CornerRadius="6" Margin="8,8,0,0">
<ScrollViewer>
<ContentControl Content="{Binding SelectedNode}">
<ContentControl.DataTemplates>
<DataTemplate DataType="{x:Type core:SchemaNode}">
<StackPanel Margin="12" Spacing="12">
<TextBlock Text="Details" FontSize="16" FontWeight="SemiBold" />
<!-- General info -->
<Border BorderBrush="{DynamicResource PanelBorderBrush}" BorderThickness="1" CornerRadius="4" Padding="10">
<Grid ColumnDefinitions="Auto,*" RowDefinitions="Auto,Auto,Auto,Auto,Auto,Auto,*">
<TextBlock Grid.Row="0" Grid.Column="0" Text="Name:" FontWeight="Bold"/>
<TextBlock Grid.Row="0" Grid.Column="1" Margin="8,0,0,0" Text="{Binding Name}"/>
<!-- General info -->
<Border BorderBrush="{DynamicResource PanelBorderBrush}" BorderThickness="1"
CornerRadius="4" Padding="10">
<Grid ColumnDefinitions="Auto,*" RowDefinitions="Auto,Auto,Auto,Auto,Auto,Auto,*">
<TextBlock Grid.Row="0" Grid.Column="0" Text="Name:" FontWeight="Bold" />
<TextBlock Grid.Row="0" Grid.Column="1" Margin="8,0,0,0" Text="{Binding Name}" />
<TextBlock Grid.Row="1" Grid.Column="0" Text="Built-in:" FontWeight="Bold"/>
<TextBlock Grid.Row="1" Grid.Column="1" Margin="8,0,0,0" Text="{Binding BuiltInType}" FontWeight="Bold"/>
<TextBlock Grid.Row="1" Grid.Column="0" Text="Built-in:" FontWeight="Bold" />
<TextBlock Grid.Row="1" Grid.Column="1" Margin="8,0,0,0"
Text="{Binding BuiltInType}" FontWeight="Bold" />
<TextBlock Grid.Row="2" Grid.Column="0" Text="Model:" FontWeight="Bold"/>
<TextBlock Grid.Row="2" Grid.Column="1" Margin="8,0,0,0" Text="{Binding ContentModel}"/>
<TextBlock Grid.Row="2" Grid.Column="0" Text="Model:" FontWeight="Bold" />
<TextBlock Grid.Row="2" Grid.Column="1" Margin="8,0,0,0"
Text="{Binding ContentModel}" />
<TextBlock Grid.Row="3" Grid.Column="0" Text="Namespace:" FontWeight="Bold"/>
<TextBlock Grid.Row="3" Grid.Column="1" Margin="8,0,0,0" Text="{Binding Namespace}"/>
<TextBlock Grid.Row="3" Grid.Column="0" Text="Namespace:" FontWeight="Bold" />
<TextBlock Grid.Row="3" Grid.Column="1" Margin="8,0,0,0" Text="{Binding Namespace}" />
<TextBlock Grid.Row="4" Grid.Column="0" Text="Cardinality:" FontWeight="Bold"/>
<TextBlock Grid.Row="4" Grid.Column="1" Margin="8,0,0,0" Text="{Binding Cardinality, Converter={StaticResource CardinalityToLabel}}"/>
<TextBlock Grid.Row="4" Grid.Column="0" Text="Cardinality:" FontWeight="Bold" />
<TextBlock Grid.Row="4" Grid.Column="1" Margin="8,0,0,0"
Text="{Binding Cardinality, Converter={StaticResource CardinalityToLabel}}" />
<TextBlock Grid.Row="5" Grid.Column="0" Text="Nillable:" FontWeight="Bold"/>
<TextBlock Grid.Row="5" Grid.Column="1" Margin="8,0,0,0" Text="{Binding IsNillable}"/>
<TextBlock Grid.Row="5" Grid.Column="0" Text="Nillable:" FontWeight="Bold" />
<TextBlock Grid.Row="5" Grid.Column="1" Margin="8,0,0,0"
Text="{Binding IsNillable}" />
<TextBlock Grid.Row="6" Grid.Column="0" Text="Type:" FontWeight="Bold"/>
<TextBlock Grid.Row="6" Grid.Column="1" Margin="8,0,0,0" Text="{Binding TypeName}"/>
</Grid>
</Border>
<TextBlock Grid.Row="6" Grid.Column="0" Text="Type:" FontWeight="Bold" />
<TextBlock Grid.Row="6" Grid.Column="1" Margin="8,0,0,0" Text="{Binding TypeName}" />
</Grid>
</Border>
<!-- Documentation -->
<StackPanel IsVisible="{Binding Documentation, Converter={x:Static ObjectConverters.IsNotNull}}">
<TextBlock Text="Documentation" FontWeight="SemiBold"/>
<Border BorderBrush="{DynamicResource PanelBorderBrush}" BorderThickness="1" CornerRadius="4" Padding="10">
<TextBlock Text="{Binding Documentation}" TextWrapping="Wrap"/>
</Border>
</StackPanel>
<!-- Documentation -->
<StackPanel
IsVisible="{Binding Documentation, Converter={x:Static ObjectConverters.IsNotNull}}">
<TextBlock Text="Documentation" FontWeight="SemiBold" />
<Border BorderBrush="{DynamicResource PanelBorderBrush}" BorderThickness="1"
CornerRadius="4" Padding="10">
<TextBlock Text="{Binding Documentation}" TextWrapping="Wrap" />
</Border>
</StackPanel>
<!-- Constraints -->
<StackPanel>
<TextBlock Text="Constraints" FontWeight="SemiBold"/>
<ContentControl Content="{Binding Constraints}">
<ContentControl.DataTemplates>
<DataTemplate x:DataType="m:ConstraintSet">
<StackPanel Spacing="8">
<TextBlock Text="Base Type:" FontWeight="Bold"/>
<TextBlock Text="{Binding BaseTypeName}"/>
<!-- Constraints -->
<StackPanel>
<TextBlock Text="Constraints" FontWeight="SemiBold" />
<ContentControl Content="{Binding Constraints}">
<ContentControl.DataTemplates>
<DataTemplate x:DataType="core:ConstraintSet">
<StackPanel Spacing="8">
<TextBlock Text="Base Type:" FontWeight="Bold" />
<TextBlock Text="{Binding BaseTypeName}" />
<StackPanel>
<TextBlock Text="Constraints" FontWeight="SemiBold"/>
<ItemsControl ItemsSource="{Binding Constraints}" IsVisible="{Binding Constraints, Converter={StaticResource HasItems}}">
<ItemsControl.ItemTemplate>
<DataTemplate x:DataType="m:ConstraintEntry">
<TextBlock>
<Run Text="• "/>
<Run Text="{Binding Name}"/>
<Run Text=": "/>
<Run Text="{Binding Value}"/>
</TextBlock>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
<StackPanel>
<TextBlock Text="Constraints" FontWeight="SemiBold" />
<ItemsControl ItemsSource="{Binding Constraints}"
IsVisible="{Binding Constraints, Converter={StaticResource HasItems}}">
<ItemsControl.ItemTemplate>
<DataTemplate x:DataType="core:ConstraintEntry">
<TextBlock>
<Run Text="• " />
<Run Text="{Binding Name}" />
<Run Text=": " />
<Run Text="{Binding Value}" />
</TextBlock>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
</StackPanel>
</StackPanel>
</DataTemplate>
</ContentControl.DataTemplates>
</ContentControl>
</StackPanel>
</StackPanel>
</StackPanel>
</DataTemplate>
</ContentControl.DataTemplates>
</ContentControl>
</StackPanel>
</StackPanel>
</DataTemplate>
</ContentControl.DataTemplates>
</ContentControl>
</ScrollViewer>
</Border>
</ContentControl.DataTemplates>
</ContentControl>
</ScrollViewer>
</Border>
</UserControl>

View File

@ -1,12 +1,11 @@
using Avalonia.Controls;
namespace XSDVisualiser.Desktop.Views
namespace XSDVisualiser.Desktop.Views;
public partial class RightDetailsView : UserControl
{
public partial class RightDetailsView : UserControl
public RightDetailsView()
{
public RightDetailsView()
{
InitializeComponent();
}
InitializeComponent();
}
}

View File

@ -1,19 +1,19 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>WinExe</OutputType>
<TargetFramework>net9.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<AvaloniaUseCompiledBindingsByDefault>true</AvaloniaUseCompiledBindingsByDefault>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Avalonia" Version="11.1.3" />
<PackageReference Include="Avalonia.Desktop" Version="11.1.3" />
<PackageReference Include="Avalonia.Controls.DataGrid" Version="11.1.3" />
<PackageReference Include="Avalonia.Themes.Fluent" Version="11.1.3" />
<PackageReference Include="Avalonia.ReactiveUI" Version="11.1.3" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\XSDVisualiser.Core\XSDVisualiser.Core.csproj" />
</ItemGroup>
<PropertyGroup>
<OutputType>WinExe</OutputType>
<TargetFramework>net9.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<AvaloniaUseCompiledBindingsByDefault>true</AvaloniaUseCompiledBindingsByDefault>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Avalonia" Version="11.1.3"/>
<PackageReference Include="Avalonia.Desktop" Version="11.1.3"/>
<PackageReference Include="Avalonia.Controls.DataGrid" Version="11.1.3"/>
<PackageReference Include="Avalonia.Themes.Fluent" Version="11.1.3"/>
<PackageReference Include="Avalonia.ReactiveUI" Version="11.1.3"/>
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\XSDVisualiser.Core\XSDVisualiser.Core.csproj"/>
</ItemGroup>
</Project>

View File

@ -0,0 +1,21 @@
using System.Xml.Serialization;
namespace XSDVisualiser.Core;
/// <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; }
}

View File

@ -0,0 +1,10 @@
using System.Xml.Serialization;
namespace XSDVisualiser.Core;
public class ConstraintEntry
{
[XmlAttribute] public string? Name { get; set; }
[XmlAttribute] public string? Value { get; set; }
}

View File

@ -0,0 +1,16 @@
using System.Xml.Serialization;
namespace XSDVisualiser.Core;
/// <summary>
/// SimpleType constraints (formerly called facets).
/// </summary>
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<ConstraintEntry> Constraints { get; set; } = new();
}

View File

@ -0,0 +1,19 @@
using System.Xml.Serialization;
namespace XSDVisualiser.Core;
/// <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; }
}

View File

@ -0,0 +1,16 @@
using System.Xml.Serialization;
namespace XSDVisualiser.Core;
/// <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();
}

View File

@ -0,0 +1,51 @@
using System.Xml.Serialization;
namespace XSDVisualiser.Core;
/// <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
/// <summary>
/// Human-readable documentation extracted from xsd:annotation/xsd:documentation.
/// Prefer element-level documentation; falls back to type-level documentation.
/// </summary>
[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();
}
}

View File

@ -1,140 +0,0 @@
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
/// <summary>
/// Human-readable documentation extracted from xsd:annotation/xsd:documentation.
/// Prefer element-level documentation; falls back to type-level documentation.
/// </summary>
[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();
}
}
/// <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 (formerly called facets).
/// </summary>
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<ConstraintEntry> Constraints { get; set; } = new();
}
public class ConstraintEntry
{
[XmlAttribute]
public string? Name { get; set; }
[XmlAttribute]
public string? Value { get; set; }
}
}

View File

@ -1,448 +1,396 @@
using System.Text;
using System.Xml;
using System.Xml.Schema;
using System.Text;
using XSDVisualiser.Models;
namespace XSDVisualiser.Core
namespace XSDVisualiser.Core;
public class XsdSchemaParser
{
public class XsdSchemaParser
private readonly XmlSchemaSet _set = new();
public SchemaModel Parse(string xsdPath)
{
private readonly XmlSchemaSet _set = new();
_set.XmlResolver = new XmlUrlResolver();
using var reader = XmlReader.Create(xsdPath, new XmlReaderSettings { DtdProcessing = DtdProcessing.Ignore });
var schema = XmlSchema.Read(reader, ValidationCallback);
_set.Add(schema!);
_set.CompilationSettings = new XmlSchemaCompilationSettings { EnableUpaCheck = true };
_set.Compile();
public SchemaModel Parse(string xsdPath)
var model = new SchemaModel
{
_set.XmlResolver = new XmlUrlResolver();
using var reader = XmlReader.Create(xsdPath, new XmlReaderSettings { DtdProcessing = DtdProcessing.Ignore });
var schema = XmlSchema.Read(reader, ValidationCallback);
_set.Add(schema!);
_set.CompilationSettings = new XmlSchemaCompilationSettings { EnableUpaCheck = true };
_set.Compile();
TargetNamespace = schema!.TargetNamespace
};
var model = new SchemaModel
{
TargetNamespace = schema!.TargetNamespace
};
foreach (var globalEl in _set.Schemas().Cast<XmlSchema>()
.SelectMany(s => s.Elements.Values.Cast<XmlSchemaElement>()))
{
var node = BuildNodeForElement(globalEl, parentContentModel: null);
model.RootElements.Add(node);
}
return model;
foreach (var globalEl in _set.Schemas().Cast<XmlSchema>()
.SelectMany(s => s.Elements.Values.Cast<XmlSchemaElement>()))
{
var node = BuildNodeForElement(globalEl, null);
model.RootElements.Add(node);
}
private void ValidationCallback(object? sender, ValidationEventArgs e)
return model;
}
private void ValidationCallback(object? sender, ValidationEventArgs e)
{
// For now, we do not throw; we capture compiled info best-effort.
// Console.Error.WriteLine($"[XSD Validation {e.Severity}] {e.Message}");
}
private SchemaNode BuildNodeForElement(XmlSchemaElement element, string? parentContentModel)
{
var node = new SchemaNode
{
// For now, we do not throw; we capture compiled info best-effort.
// Console.Error.WriteLine($"[XSD Validation {e.Severity}] {e.Message}");
}
private SchemaNode BuildNodeForElement(XmlSchemaElement element, string? parentContentModel)
{
var node = new SchemaNode
Name = element.Name ?? element.RefName.Name,
Namespace = (element.QualifiedName.IsEmpty ? element.RefName : element.QualifiedName).Namespace,
IsNillable = element.IsNillable,
Cardinality = new Occurs
{
Name = element.Name ?? element.RefName.Name,
Namespace = (element.QualifiedName.IsEmpty ? element.RefName : element.QualifiedName).Namespace,
IsNillable = element.IsNillable,
Cardinality = new Occurs
{
Min = element.MinOccurs,
Max = element.MaxOccurs,
MaxIsUnbounded = element.MaxOccursString == "unbounded"
},
ContentModel = parentContentModel
};
Min = element.MinOccurs,
Max = element.MaxOccurs,
MaxIsUnbounded = element.MaxOccursString == "unbounded"
},
ContentModel = parentContentModel
};
// Prefer element-level documentation
node.Documentation = ExtractDocumentation(element);
// Prefer element-level documentation
node.Documentation = ExtractDocumentation(element);
var type = ResolveElementType(element);
if (type == null) return node;
node.TypeName = GetQualifiedTypeName(type);
if (type.Datatype != null)
{
node.BuiltInType = type.Datatype.TypeCode.ToString();
}
// Fallback to type-level documentation if none on element
if (string.IsNullOrWhiteSpace(node.Documentation))
{
switch (type)
{
case XmlSchemaComplexType ctDoc:
node.Documentation = ExtractDocumentation(ctDoc);
break;
case XmlSchemaSimpleType stDoc:
node.Documentation = ExtractDocumentation(stDoc);
break;
}
}
var type = ResolveElementType(element);
if (type == null) return node;
node.TypeName = GetQualifiedTypeName(type);
if (type.Datatype != null) node.BuiltInType = type.Datatype.TypeCode.ToString();
// Fallback to type-level documentation if none on element
if (string.IsNullOrWhiteSpace(node.Documentation))
switch (type)
{
case XmlSchemaComplexType ct:
HandleComplexType(node, ct);
case XmlSchemaComplexType ctDoc:
node.Documentation = ExtractDocumentation(ctDoc);
break;
case XmlSchemaSimpleType st:
node.ContentModel = "simple";
node.Constraints = ExtractConstraints(st);
case XmlSchemaSimpleType stDoc:
node.Documentation = ExtractDocumentation(stDoc);
break;
}
return node;
}
private static string? GetQualifiedTypeName(XmlSchemaType type)
switch (type)
{
if (!type.QualifiedName.IsEmpty) return type.QualifiedName.ToString();
return type.BaseXmlSchemaType is { QualifiedName.IsEmpty: false }
? type.BaseXmlSchemaType.QualifiedName.ToString()
: type.Name;
}
private XmlSchemaType? ResolveElementType(XmlSchemaElement el)
{
if (el.ElementSchemaType != null) return el.ElementSchemaType;
if (!el.SchemaTypeName.IsEmpty)
{
return _set.GlobalTypes[el.SchemaTypeName] as XmlSchemaType;
}
return el.SchemaType;
}
private void HandleComplexType(SchemaNode node, XmlSchemaComplexType ct)
{
// Collect attributes (ensure uniqueness)
var seenAttrKeys = new HashSet<string>(StringComparer.Ordinal);
// 1) Compiled attribute uses (includes inherited/group attributes after Compile)
foreach (var attr in ct.AttributeUses.Values.OfType<XmlSchemaAttribute>())
{
var qn = attr.QualifiedName.IsEmpty ? attr.RefName : attr.QualifiedName;
var key = qn.ToString();
if (seenAttrKeys.Add(key))
{
node.Attributes.Add(ExtractAttribute(attr));
}
}
// 2) Uncompiled attributes directly on the type (fallback)
foreach (var a in ct.Attributes.OfType<XmlSchemaAttribute>())
{
var qn = a.QualifiedName.IsEmpty ? a.RefName : a.QualifiedName;
var key = qn.ToString();
if (seenAttrKeys.Add(key))
{
node.Attributes.Add(ExtractAttribute(a));
}
}
// 3) Attributes from complexContent extension/restriction
if (ct.ContentModel is XmlSchemaComplexContent cc)
{
switch (cc.Content)
{
case XmlSchemaComplexContentExtension cext:
{
foreach (var a in cext.Attributes.OfType<XmlSchemaAttribute>())
{
var qn = a.QualifiedName.IsEmpty ? a.RefName : a.QualifiedName;
var key = qn.ToString();
if (seenAttrKeys.Add(key))
{
node.Attributes.Add(ExtractAttribute(a));
}
}
break;
}
case XmlSchemaComplexContentRestriction cres:
{
foreach (var a in cres.Attributes.OfType<XmlSchemaAttribute>())
{
var qn = a.QualifiedName.IsEmpty ? a.RefName : a.QualifiedName;
var key = qn.ToString();
if (seenAttrKeys.Add(key))
{
node.Attributes.Add(ExtractAttribute(a));
}
}
break;
}
}
}
// Content model
if (ct.ContentTypeParticle is XmlSchemaGroupBase group)
{
var content = group switch
{
XmlSchemaSequence => "sequence",
XmlSchemaChoice => "choice",
XmlSchemaAll => "all",
_ => "group"
};
node.ContentModel = content;
foreach (var item in group.Items)
{
switch (item)
{
case XmlSchemaElement childEl:
node.Children.Add(BuildNodeForElement(childEl, content));
break;
case XmlSchemaGroupBase nestedGroup:
// Flatten nested groups by introducing synthetic nodes
var synthetic = new SchemaNode
{
Name = "(group)",
Namespace = node.Namespace,
ContentModel = nestedGroup switch
{
XmlSchemaSequence => "sequence",
XmlSchemaChoice => "choice",
XmlSchemaAll => "all",
_ => "group"
},
Cardinality = new Occurs { Min = nestedGroup.MinOccurs, Max = nestedGroup.MaxOccurs, MaxIsUnbounded = nestedGroup.MaxOccursString == "unbounded" }
};
foreach (var nestedItem in nestedGroup.Items)
{
if (nestedItem is XmlSchemaElement ngChild)
{
synthetic.Children.Add(BuildNodeForElement(ngChild, synthetic.ContentModel));
}
}
node.Children.Add(synthetic);
break;
// Skip other particles for now
}
}
}
else if (ct.ContentType == XmlSchemaContentType.TextOnly && ct.ContentModel is XmlSchemaSimpleContent simpleContent)
{
case XmlSchemaComplexType ct:
HandleComplexType(node, ct);
break;
case XmlSchemaSimpleType st:
node.ContentModel = "simple";
switch (simpleContent.Content)
node.Constraints = ExtractConstraints(st);
break;
}
return node;
}
private static string? GetQualifiedTypeName(XmlSchemaType type)
{
if (!type.QualifiedName.IsEmpty) return type.QualifiedName.ToString();
return type.BaseXmlSchemaType is { QualifiedName.IsEmpty: false }
? type.BaseXmlSchemaType.QualifiedName.ToString()
: type.Name;
}
private XmlSchemaType? ResolveElementType(XmlSchemaElement el)
{
if (el.ElementSchemaType != null) return el.ElementSchemaType;
if (!el.SchemaTypeName.IsEmpty) return _set.GlobalTypes[el.SchemaTypeName] as XmlSchemaType;
return el.SchemaType;
}
private void HandleComplexType(SchemaNode node, XmlSchemaComplexType ct)
{
// Collect attributes (ensure uniqueness)
var seenAttrKeys = new HashSet<string>(StringComparer.Ordinal);
// 1) Compiled attribute uses (includes inherited/group attributes after Compile)
foreach (var attr in ct.AttributeUses.Values.OfType<XmlSchemaAttribute>())
{
var qn = attr.QualifiedName.IsEmpty ? attr.RefName : attr.QualifiedName;
var key = qn.ToString();
if (seenAttrKeys.Add(key)) node.Attributes.Add(ExtractAttribute(attr));
}
// 2) Uncompiled attributes directly on the type (fallback)
foreach (var a in ct.Attributes.OfType<XmlSchemaAttribute>())
{
var qn = a.QualifiedName.IsEmpty ? a.RefName : a.QualifiedName;
var key = qn.ToString();
if (seenAttrKeys.Add(key)) node.Attributes.Add(ExtractAttribute(a));
}
// 3) Attributes from complexContent extension/restriction
if (ct.ContentModel is XmlSchemaComplexContent cc)
switch (cc.Content)
{
case XmlSchemaComplexContentExtension cext:
{
case XmlSchemaSimpleContentExtension ext:
foreach (var a in cext.Attributes.OfType<XmlSchemaAttribute>())
{
var baseType = ResolveType(ext.BaseTypeName);
if (baseType is XmlSchemaSimpleType st)
{
node.Constraints = ExtractConstraints(st);
node.TypeName ??= GetQualifiedTypeName(st);
node.BuiltInType ??= st.Datatype?.TypeCode.ToString();
}
foreach (var attr in ext.Attributes.OfType<XmlSchemaAttribute>())
{
var qn = attr.QualifiedName.IsEmpty ? attr.RefName : attr.QualifiedName;
var key = qn.ToString();
if (seenAttrKeys.Add(key))
{
node.Attributes.Add(ExtractAttribute(attr));
}
}
break;
var qn = a.QualifiedName.IsEmpty ? a.RefName : a.QualifiedName;
var key = qn.ToString();
if (seenAttrKeys.Add(key)) node.Attributes.Add(ExtractAttribute(a));
}
case XmlSchemaSimpleContentRestriction res:
break;
}
case XmlSchemaComplexContentRestriction cres:
{
foreach (var a in cres.Attributes.OfType<XmlSchemaAttribute>())
{
var baseType = ResolveType(res.BaseTypeName);
if (baseType is XmlSchemaSimpleType st)
{
var cons = ExtractConstraints(st);
MergeFacets(cons, res.Facets);
node.Constraints = cons;
node.TypeName ??= GetQualifiedTypeName(st);
node.BuiltInType ??= st.Datatype?.TypeCode.ToString();
}
break;
var qn = a.QualifiedName.IsEmpty ? a.RefName : a.QualifiedName;
var key = qn.ToString();
if (seenAttrKeys.Add(key)) node.Attributes.Add(ExtractAttribute(a));
}
break;
}
}
}
private XmlSchemaType? ResolveType(XmlQualifiedName qname)
// Content model
if (ct.ContentTypeParticle is XmlSchemaGroupBase group)
{
if (qname.IsEmpty) return null;
return _set.GlobalTypes[qname] as XmlSchemaType;
}
private AttributeInfo ExtractAttribute(XmlSchemaAttribute attr)
{
var info = new AttributeInfo
var content = group switch
{
Name = attr.Name ?? attr.RefName.Name,
Namespace = (attr.QualifiedName.IsEmpty ? attr.RefName : attr.QualifiedName).Namespace,
Use = attr.Use.ToString()
XmlSchemaSequence => "sequence",
XmlSchemaChoice => "choice",
XmlSchemaAll => "all",
_ => "group"
};
node.ContentModel = content;
XmlSchemaSimpleType? st = null;
if (attr.AttributeSchemaType != null) st = attr.AttributeSchemaType as XmlSchemaSimpleType;
else if (!attr.SchemaTypeName.IsEmpty) st = ResolveType(attr.SchemaTypeName) as XmlSchemaSimpleType;
else if (attr.SchemaType != null) st = attr.SchemaType;
if (st == null) return info;
info.TypeName = GetQualifiedTypeName(st);
info.BuiltInType = st.Datatype?.TypeCode.ToString();
info.Constraints = ExtractConstraints(st);
return info;
}
private ConstraintSet? ExtractConstraints(XmlSchemaSimpleType st)
{
var cons = new ConstraintSet
{
BaseTypeName = GetQualifiedTypeName(st.BaseXmlSchemaType)
};
switch (st.Content)
{
case XmlSchemaSimpleTypeRestriction restr:
MergeFacets(cons, restr.Facets);
break;
case XmlSchemaSimpleTypeList list:
foreach (var item in group.Items)
switch (item)
{
if (!list.ItemTypeName.IsEmpty)
{
var baseType = ResolveType(list.ItemTypeName);
if (baseType is XmlSchemaSimpleType itemSt)
case XmlSchemaElement childEl:
node.Children.Add(BuildNodeForElement(childEl, content));
break;
case XmlSchemaGroupBase nestedGroup:
// Flatten nested groups by introducing synthetic nodes
var synthetic = new SchemaNode
{
var sub = ExtractConstraints(itemSt);
Merge(cons, sub);
}
}
break;
}
case XmlSchemaSimpleTypeUnion union:
{
foreach (var memberType in union.BaseMemberTypes)
{
if (memberType is { } mst)
{
var sub = ExtractConstraints(mst);
Merge(cons, sub);
}
}
break;
}
}
return cons;
}
private static void Merge(ConstraintSet target, ConstraintSet? source)
{
if (source == null) return;
// Merge generic constraints (name + value de-duplication)
if (source.Constraints != null)
{
foreach (var sc in source.Constraints)
{
var exists = false;
foreach (var tc in target.Constraints)
{
if (string.Equals(tc.Name, sc.Name, StringComparison.Ordinal) && string.Equals(tc.Value, sc.Value, StringComparison.Ordinal))
{
exists = true; break;
}
}
if (!exists)
{
target.Constraints.Add(new ConstraintEntry { Name = sc.Name, Value = sc.Value });
}
}
}
}
private static void MergeFacets(ConstraintSet cons, XmlSchemaObjectCollection facets)
{
foreach (var f in facets)
{
// Capture all constraints generically for dynamic display
if (f is XmlSchemaFacet baseFacet)
{
var name = GetFacetName(f);
var value = baseFacet.Value;
if (!string.IsNullOrEmpty(name) && !string.IsNullOrEmpty(value))
{
var exists = false;
foreach (var entry in cons.Constraints)
{
if (string.Equals(entry.Name, name, StringComparison.Ordinal) && string.Equals(entry.Value, value, StringComparison.Ordinal))
Name = "(group)",
Namespace = node.Namespace,
ContentModel = nestedGroup switch
{
exists = true; break;
}
}
if (!exists)
{
cons.Constraints.Add(new ConstraintEntry { Name = name, Value = value });
}
}
}
}
}
private static string GetFacetName(XmlSchemaObject facet)
{
var typeName = facet.GetType().Name; // e.g., XmlSchemaMinInclusiveFacet
if (typeName.StartsWith("XmlSchema", StringComparison.Ordinal))
typeName = typeName.Substring("XmlSchema".Length);
if (typeName.EndsWith("Facet", StringComparison.Ordinal))
typeName = typeName.Substring(0, typeName.Length - "Facet".Length);
if (typeName.Length == 0) return typeName;
return char.ToLowerInvariant(typeName[0]) + typeName.Substring(1);
}
private static string? ExtractDocumentation(XmlSchemaAnnotated? annotated)
{
if (annotated?.Annotation == null) return null;
var sb = new StringBuilder();
foreach (var item in annotated.Annotation.Items)
{
if (item is not XmlSchemaDocumentation doc) continue;
if (doc.Markup is { Length: > 0 })
{
var pieceBuilder = new StringBuilder();
foreach (var node in doc.Markup)
{
try
{
var text = node?.InnerText;
if (!string.IsNullOrWhiteSpace(text))
XmlSchemaSequence => "sequence",
XmlSchemaChoice => "choice",
XmlSchemaAll => "all",
_ => "group"
},
Cardinality = new Occurs
{
pieceBuilder.Append(text);
Min = nestedGroup.MinOccurs, Max = nestedGroup.MaxOccurs,
MaxIsUnbounded = nestedGroup.MaxOccursString == "unbounded"
}
}
catch
{
// ignore malformed nodes
}
};
foreach (var nestedItem in nestedGroup.Items)
if (nestedItem is XmlSchemaElement ngChild)
synthetic.Children.Add(BuildNodeForElement(ngChild, synthetic.ContentModel));
node.Children.Add(synthetic);
break;
// Skip other particles for now
}
}
else if (ct is
{
ContentType: XmlSchemaContentType.TextOnly, ContentModel: XmlSchemaSimpleContent simpleContent
})
{
node.ContentModel = "simple";
switch (simpleContent.Content)
{
case XmlSchemaSimpleContentExtension ext:
{
var baseType = ResolveType(ext.BaseTypeName);
if (baseType is XmlSchemaSimpleType st)
{
node.Constraints = ExtractConstraints(st);
node.TypeName ??= GetQualifiedTypeName(st);
node.BuiltInType ??= st.Datatype?.TypeCode.ToString();
}
var piece = pieceBuilder.ToString().Trim();
if (string.IsNullOrWhiteSpace(piece)) continue;
foreach (var attr in ext.Attributes.OfType<XmlSchemaAttribute>())
{
var qn = attr.QualifiedName.IsEmpty ? attr.RefName : attr.QualifiedName;
var key = qn.ToString();
if (seenAttrKeys.Add(key)) node.Attributes.Add(ExtractAttribute(attr));
}
if (sb.Length > 0) sb.AppendLine().AppendLine();
sb.Append(piece);
break;
}
else if (!string.IsNullOrWhiteSpace(doc.Source))
case XmlSchemaSimpleContentRestriction res:
{
// If there is a source but no markup, skip; we only render text.
var baseType = ResolveType(res.BaseTypeName);
if (baseType is XmlSchemaSimpleType st)
{
var cons = ExtractConstraints(st);
MergeFacets(cons, res.Facets);
node.Constraints = cons;
node.TypeName ??= GetQualifiedTypeName(st);
node.BuiltInType ??= st.Datatype?.TypeCode.ToString();
}
break;
}
}
return sb.Length == 0 ? null : sb.ToString();
}
}
private XmlSchemaType? ResolveType(XmlQualifiedName qname)
{
if (qname.IsEmpty) return null;
return _set.GlobalTypes[qname] as XmlSchemaType;
}
private AttributeInfo ExtractAttribute(XmlSchemaAttribute attr)
{
var info = new AttributeInfo
{
Name = attr.Name ?? attr.RefName.Name,
Namespace = (attr.QualifiedName.IsEmpty ? attr.RefName : attr.QualifiedName).Namespace,
Use = attr.Use.ToString()
};
XmlSchemaSimpleType? st = null;
if (attr.AttributeSchemaType != null) st = attr.AttributeSchemaType;
else if (!attr.SchemaTypeName.IsEmpty) st = ResolveType(attr.SchemaTypeName) as XmlSchemaSimpleType;
else if (attr.SchemaType != null) st = attr.SchemaType;
if (st == null) return info;
info.TypeName = GetQualifiedTypeName(st);
info.BuiltInType = st.Datatype?.TypeCode.ToString();
info.Constraints = ExtractConstraints(st);
return info;
}
private ConstraintSet? ExtractConstraints(XmlSchemaSimpleType st)
{
var cons = new ConstraintSet
{
BaseTypeName = GetQualifiedTypeName(st.BaseXmlSchemaType)
};
switch (st.Content)
{
case XmlSchemaSimpleTypeRestriction restr:
MergeFacets(cons, restr.Facets);
break;
case XmlSchemaSimpleTypeList list:
{
if (!list.ItemTypeName.IsEmpty)
{
var baseType = ResolveType(list.ItemTypeName);
if (baseType is XmlSchemaSimpleType itemSt)
{
var sub = ExtractConstraints(itemSt);
Merge(cons, sub);
}
}
break;
}
case XmlSchemaSimpleTypeUnion union:
{
foreach (var memberType in union.BaseMemberTypes)
{
if (memberType is not { } mst) continue;
var sub = ExtractConstraints(mst);
Merge(cons, sub);
}
break;
}
}
return cons;
}
private static void Merge(ConstraintSet target, ConstraintSet? source)
{
// Merge generic constraints (name + value de-duplication)
if (source?.Constraints == null) return;
foreach (var sc in source.Constraints)
{
var exists = target.Constraints.Any(tc =>
string.Equals(tc.Name, sc.Name, StringComparison.Ordinal) &&
string.Equals(tc.Value, sc.Value, StringComparison.Ordinal));
if (!exists) target.Constraints.Add(new ConstraintEntry { Name = sc.Name, Value = sc.Value });
}
}
private static void MergeFacets(ConstraintSet cons, XmlSchemaObjectCollection facets)
{
foreach (var f in facets)
{
// Capture all constraints generically for dynamic display
if (f is not XmlSchemaFacet baseFacet) continue;
var name = GetFacetName(f);
var value = baseFacet.Value;
if (string.IsNullOrEmpty(name) || string.IsNullOrEmpty(value)) continue;
var exists = cons.Constraints.Any(entry =>
string.Equals(entry.Name, name, StringComparison.Ordinal) &&
string.Equals(entry.Value, value, StringComparison.Ordinal));
if (!exists) cons.Constraints.Add(new ConstraintEntry { Name = name, Value = value });
}
}
private static string GetFacetName(XmlSchemaObject facet)
{
var typeName = facet.GetType().Name; // e.g., XmlSchemaMinInclusiveFacet
if (typeName.StartsWith("XmlSchema", StringComparison.Ordinal))
typeName = typeName.Substring("XmlSchema".Length);
if (typeName.EndsWith("Facet", StringComparison.Ordinal))
typeName = typeName.Substring(0, typeName.Length - "Facet".Length);
if (typeName.Length == 0) return typeName;
return char.ToLowerInvariant(typeName[0]) + typeName.Substring(1);
}
private static string? ExtractDocumentation(XmlSchemaAnnotated? annotated)
{
if (annotated?.Annotation == null) return null;
var sb = new StringBuilder();
foreach (var item in annotated.Annotation.Items)
{
if (item is not XmlSchemaDocumentation doc) continue;
if (doc.Markup is { Length: > 0 })
{
var pieceBuilder = new StringBuilder();
foreach (var node in doc.Markup)
try
{
var text = node?.InnerText;
if (!string.IsNullOrWhiteSpace(text)) pieceBuilder.Append(text);
}
catch
{
// ignore malformed nodes
}
var piece = pieceBuilder.ToString().Trim();
if (string.IsNullOrWhiteSpace(piece)) continue;
if (sb.Length > 0) sb.AppendLine().AppendLine();
sb.Append(piece);
}
else if (!string.IsNullOrWhiteSpace(doc.Source))
{
// If there is a source but no markup, skip; we only render text.
}
}
return sb.Length == 0 ? null : sb.ToString();
}
}

View File

@ -10,7 +10,8 @@ if (args.Length == 0 || args[0] is "-h" or "--help")
var inputPath = args[0];
*/
const string inputPath = "/home/frederik/Work/XSDVisualiser/XSDVisualiser/Rescources/SF2900/SF2900_EP_MS1-2/DistributionServiceMsgV2.xsd";
const string inputPath =
"/home/frederik/Work/XSDVisualiser/XSDVisualiser/Rescources/SF2900/SF2900_EP_MS1-2/DistributionServiceMsgV2.xsd";
if (!File.Exists(inputPath))
{
@ -20,8 +21,7 @@ if (!File.Exists(inputPath))
var format = "json";
string? outPath = null;
for (int i = 1; i < args.Length; i++)
{
for (var i = 1; i < args.Length; i++)
switch (args[i])
{
case "--format":
@ -34,6 +34,7 @@ for (int i = 1; i < args.Length; i++)
Console.Error.WriteLine("--format requires a value: xml or json");
Environment.Exit(2);
}
break;
case "--out":
if (i + 1 < args.Length)
@ -45,16 +46,16 @@ for (int i = 1; i < args.Length; i++)
Console.Error.WriteLine("--out requires a file path");
Environment.Exit(2);
}
break;
}
}
try
{
var parser = new XsdSchemaParser();
var model = parser.Parse(inputPath);
string output = format switch
var output = format switch
{
"json" => Serialization.ToJson(model),
_ => Serialization.ToXml(model)
@ -72,11 +73,8 @@ try
}
catch (Exception ex)
{
Console.Error.WriteLine("Error: " + ex.ToString());
if (ex.InnerException != null)
{
Console.Error.WriteLine("Inner: " + ex.InnerException.ToString());
}
Console.Error.WriteLine("Error: " + ex);
if (ex.InnerException != null) Console.Error.WriteLine("Inner: " + ex.InnerException);
Environment.Exit(3);
}
@ -84,7 +82,8 @@ return;
static void PrintHelp()
{
Console.WriteLine("XSDVisualiser - Parse an XSD and emit a structural model with types, constraints, and cardinality");
Console.WriteLine(
"XSDVisualiser - Parse an XSD and emit a structural model with types, constraints, and cardinality");
Console.WriteLine("Usage: XSDVisualiser <schema.xsd> [--format xml|json] [--out outputFile]");
Console.WriteLine("Default format is xml; if --out is omitted the output is printed to stdout.");
}

View File

@ -1,10 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?>
<xsd:schema xmlns:tns="http://serviceplatformen.dk/xml/wsdl/soap11/DistributionService/3/types"
targetNamespace="http://serviceplatformen.dk/xml/wsdl/soap11/DistributionService/3/types"
xmlns:callctx="http://serviceplatformen.dk/xml/schemas/CallContext/1/"
xmlns:authctx="http://serviceplatformen.dk/xml/schemas/AuthorityContext/1/"
xmlns:dsv2="http://serviceplatformen.dk/xml/wsdl/soap11/DistributionService/2/types"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
targetNamespace="http://serviceplatformen.dk/xml/wsdl/soap11/DistributionService/3/types"
elementFormDefault="qualified"
version="1.0">
@ -39,7 +39,8 @@
<xsd:complexType name="FordelingsobjektAfsendResponseType">
<xsd:sequence>
<xsd:element name="ForretningsKvittering" type="dsv2:ForretningskvitteringType" minOccurs="1" maxOccurs="1"/>
<xsd:element name="ForretningsKvittering" type="dsv2:ForretningskvitteringType" minOccurs="1"
maxOccurs="1"/>
<xsd:element name="DistributionContext" type="dsv2:DistributionContextType" minOccurs="1" maxOccurs="1"/>
</xsd:sequence>
</xsd:complexType>
@ -48,7 +49,8 @@
<xsd:sequence>
<xsd:element ref="callctx:CallContext" minOccurs="0" maxOccurs="1"/>
<xsd:element ref="authctx:AuthorityContext" minOccurs="0" maxOccurs="1"/>
<xsd:element name="Forretningskvittering" type="dsv2:ForretningskvitteringType" minOccurs="1" maxOccurs="1"/>
<xsd:element name="Forretningskvittering" type="dsv2:ForretningskvitteringType" minOccurs="1"
maxOccurs="1"/>
<xsd:element name="DistributionContext" type="dsv2:DistributionContextType" minOccurs="1" maxOccurs="1"/>
</xsd:sequence>
</xsd:complexType>

View File

@ -1,11 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<definitions xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
xmlns:tns="http://serviceplatformen.dk/xml/wsdl/soap11/DistributionService/2/port"
targetNamespace="http://serviceplatformen.dk/xml/wsdl/soap11/DistributionService/2/port"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:types="http://serviceplatformen.dk/xml/wsdl/soap11/DistributionService/2/types"
targetNamespace="http://serviceplatformen.dk/xml/wsdl/soap11/DistributionService/2/port"
xmlns="http://schemas.xmlsoap.org/wsdl/"
name="DistributionServiceAnvender"
xmlns:types="http://serviceplatformen.dk/xml/wsdl/soap11/DistributionService/2/types">
name="DistributionServiceAnvender">
<types>
<xsd:schema targetNamespace="http://serviceplatformen.dk/xml/wsdl/soap11/DistributionService/2/types">

View File

@ -1,11 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<definitions xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
xmlns:tns="http://serviceplatformen.dk/xml/wsdl/soap11/DistributionService/2/port"
targetNamespace="http://serviceplatformen.dk/xml/wsdl/soap11/DistributionService/2/port"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:types="http://serviceplatformen.dk/xml/wsdl/soap11/DistributionService/2/types"
targetNamespace="http://serviceplatformen.dk/xml/wsdl/soap11/DistributionService/2/port"
xmlns="http://schemas.xmlsoap.org/wsdl/"
name="DistributionServiceModtager"
xmlns:types="http://serviceplatformen.dk/xml/wsdl/soap11/DistributionService/2/types">
name="DistributionServiceModtager">
<types>
<xsd:schema targetNamespace="http://serviceplatformen.dk/xml/wsdl/soap11/DistributionService/2/types">

View File

@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<xsd:schema xmlns:tns="http://serviceplatformen.dk/xml/wsdl/soap11/DistributionService/2/types"
targetNamespace="http://serviceplatformen.dk/xml/wsdl/soap11/DistributionService/2/types"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
targetNamespace="http://serviceplatformen.dk/xml/wsdl/soap11/DistributionService/2/types"
elementFormDefault="qualified"
version="1.0">

View File

@ -1,15 +1,16 @@
<?xml version="1.0" encoding="UTF-8"?>
<schema xmlns="http://www.w3.org/2001/XMLSchema"
xmlns:tns="http://serviceplatformen.dk/xml/wsdl/soap11/DistributionService/2/types"
<schema xmlns:tns="http://serviceplatformen.dk/xml/wsdl/soap11/DistributionService/2/types"
xmlns:oio="urn:oio:definitions:1.0.0"
xmlns="http://www.w3.org/2001/XMLSchema"
targetNamespace="http://serviceplatformen.dk/xml/wsdl/soap11/DistributionService/2/types"
elementFormDefault="qualified"
xmlns:oio="urn:oio:definitions:1.0.0"
oio:mapping="urn:oio:sagdok:MPD:3.0.0"
attributeFormDefault="unqualified">
<simpleType name="URN">
<restriction base="string">
<pattern value="[uU][rR][nN]:[a-zA-Z0-9][a-zA-Z0-9-]{0,30}[a-zA-Z0-9]:[a-zA-Z0-9\(\)+,\\\-.:=@;$_!*'%/?#]+"/>
<pattern
value="[uU][rR][nN]:[a-zA-Z0-9][a-zA-Z0-9-]{0,30}[a-zA-Z0-9]:[a-zA-Z0-9\(\)+,\\\-.:=@;$_!*'%/?#]+"/>
</restriction>
</simpleType>

View File

@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<xsd:schema targetNamespace="http://serviceplatformen.dk/xml/schemas/kvittering/1/"
xmlns:tns="http://serviceplatformen.dk/xml/schemas/kvittering/1/"
<xsd:schema xmlns:tns="http://serviceplatformen.dk/xml/schemas/kvittering/1/"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
targetNamespace="http://serviceplatformen.dk/xml/schemas/kvittering/1/"
elementFormDefault="qualified"
version="1.0">

View File

@ -1,9 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>
<wsdl:definitions name="ServiceplatformFaultMessage"
targetNamespace="http://serviceplatformen.dk/xml/schemas/ServiceplatformFault/1/"
xmlns:tns="http://serviceplatformen.dk/xml/schemas/ServiceplatformFault/1/"
<wsdl:definitions xmlns:tns="http://serviceplatformen.dk/xml/schemas/ServiceplatformFault/1/"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/">
xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
name="ServiceplatformFaultMessage"
targetNamespace="http://serviceplatformen.dk/xml/schemas/ServiceplatformFault/1/">
<wsdl:types>
<xsd:schema targetNamespace="http://serviceplatformen.dk/xml/schemas/ServiceplatformFault/1/">

View File

@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<xsd:schema xmlns:tns="http://serviceplatformen.dk/xml/schemas/ServiceplatformFault/1/"
targetNamespace="http://serviceplatformen.dk/xml/schemas/ServiceplatformFault/1/"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
targetNamespace="http://serviceplatformen.dk/xml/schemas/ServiceplatformFault/1/"
elementFormDefault="qualified"
version="1.0">

View File

@ -1,9 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>
<wsdl:definitions name="ServiceplatformFaultMessage"
targetNamespace="http://serviceplatformen.dk/xml/schemas/kvittering/1/"
xmlns:tns="http://serviceplatformen.dk/xml/schemas/kvittering/1/"
<wsdl:definitions xmlns:tns="http://serviceplatformen.dk/xml/schemas/kvittering/1/"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/">
xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
name="ServiceplatformFaultMessage"
targetNamespace="http://serviceplatformen.dk/xml/schemas/kvittering/1/">
<wsdl:types>
<xsd:schema targetNamespace="http://serviceplatformen.dk/xml/schemas/kvittering/1/">

View File

@ -1,12 +1,12 @@
<?xml version="1.0" encoding="UTF-8"?>
<definitions xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
xmlns:tns="http://serviceplatformen.dk/xml/wsdl/soap11/DistributionService/3/port"
targetNamespace="http://serviceplatformen.dk/xml/wsdl/soap11/DistributionService/3/port"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns="http://schemas.xmlsoap.org/wsdl/"
name="DistributionService"
xmlns:types="http://serviceplatformen.dk/xml/wsdl/soap11/DistributionService/3/types"
xmlns:wsp="http://www.w3.org/ns/ws-policy">
xmlns:wsp="http://www.w3.org/ns/ws-policy"
targetNamespace="http://serviceplatformen.dk/xml/wsdl/soap11/DistributionService/3/port"
xmlns="http://schemas.xmlsoap.org/wsdl/"
name="DistributionService">
<import namespace="http://serviceplatformen.dk/xml/wsdl/soap11/Security/Policy" location="policies.wsdl"/>
@ -73,7 +73,8 @@
<soap:binding transport="http://schemas.xmlsoap.org/soap/http" style="document"/>
<operation name="FordelingsobjektAfsend">
<soap:operation soapAction="http://serviceplatformen.dk/xml/wsdl/soap11/DistributionService/3/port/FordelingsobjektAfsend"/>
<soap:operation
soapAction="http://serviceplatformen.dk/xml/wsdl/soap11/DistributionService/3/port/FordelingsobjektAfsend"/>
<input>
<soap:body use="literal"/>
</input>
@ -86,7 +87,8 @@
</operation>
<operation name="FordelingskvitteringModtag">
<soap:operation soapAction="http://serviceplatformen.dk/xml/wsdl/soap11/DistributionService/3/port/FordelingskvitteringModtag"/>
<soap:operation
soapAction="http://serviceplatformen.dk/xml/wsdl/soap11/DistributionService/3/port/FordelingskvitteringModtag"/>
<input>
<soap:body use="literal"/>
</input>
@ -114,7 +116,8 @@
</operation>
<operation name="FordelingsmodtagerValider">
<soap:operation soapAction="http://serviceplatformen.dk/xml/wsdl/soap11/DistributionService/3/port/FordelingsmodtagerValider"/>
<soap:operation
soapAction="http://serviceplatformen.dk/xml/wsdl/soap11/DistributionService/3/port/FordelingsmodtagerValider"/>
<input>
<soap:body use="literal"/>
</input>

View File

@ -1,9 +1,9 @@
<?xml version="1.0" encoding="UTF-8" ?>
<wsdl:definitions targetNamespace="http://serviceplatformen.dk/xml/wsdl/soap11/Security/Policy"
xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
<wsdl:definitions xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
xmlns:wsp="http://schemas.xmlsoap.org/ws/2004/09/policy"
xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd"
xmlns:sp="http://docs.oasis-open.org/ws-sx/ws-securitypolicy/200702">
xmlns:sp="http://docs.oasis-open.org/ws-sx/ws-securitypolicy/200702"
targetNamespace="http://serviceplatformen.dk/xml/wsdl/soap11/Security/Policy">
<wsp:Policy Name="policies.wsdl#ServiceplatformBindingPolicy">
<wsp:ExactlyOne>

View File

@ -1,12 +1,12 @@
<?xml version="1.0" encoding="UTF-8"?>
<definitions xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
xmlns:tns="http://serviceplatformen.dk/xml/wsdl/soap11/DistributionService/3/port"
targetNamespace="http://serviceplatformen.dk/xml/wsdl/soap11/DistributionService/3/port"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns="http://schemas.xmlsoap.org/wsdl/"
name="DistributionService"
xmlns:types="http://serviceplatformen.dk/xml/wsdl/soap11/DistributionService/3/types"
xmlns:wsp="http://www.w3.org/ns/ws-policy">
xmlns:wsp="http://www.w3.org/ns/ws-policy"
targetNamespace="http://serviceplatformen.dk/xml/wsdl/soap11/DistributionService/3/port"
xmlns="http://schemas.xmlsoap.org/wsdl/"
name="DistributionService">
<import namespace="http://serviceplatformen.dk/xml/wsdl/soap11/Security/Policy" location="policies.wsdl"/>
@ -73,7 +73,8 @@
<soap:binding transport="http://schemas.xmlsoap.org/soap/http" style="document"/>
<operation name="FordelingsobjektAfsend">
<soap:operation soapAction="http://serviceplatformen.dk/xml/wsdl/soap11/DistributionService/3/port/FordelingsobjektAfsend"/>
<soap:operation
soapAction="http://serviceplatformen.dk/xml/wsdl/soap11/DistributionService/3/port/FordelingsobjektAfsend"/>
<input>
<soap:body use="literal"/>
</input>
@ -86,7 +87,8 @@
</operation>
<operation name="FordelingskvitteringModtag">
<soap:operation soapAction="http://serviceplatformen.dk/xml/wsdl/soap11/DistributionService/3/port/FordelingskvitteringModtag"/>
<soap:operation
soapAction="http://serviceplatformen.dk/xml/wsdl/soap11/DistributionService/3/port/FordelingskvitteringModtag"/>
<input>
<soap:body use="literal"/>
</input>
@ -114,7 +116,8 @@
</operation>
<operation name="FordelingsmodtagerValider">
<soap:operation soapAction="http://serviceplatformen.dk/xml/wsdl/soap11/DistributionService/3/port/FordelingsmodtagerValider"/>
<soap:operation
soapAction="http://serviceplatformen.dk/xml/wsdl/soap11/DistributionService/3/port/FordelingsmodtagerValider"/>
<input>
<soap:body use="literal"/>
</input>

View File

@ -1,10 +1,10 @@
<?xml version="1.0" encoding="UTF-8" ?>
<wsdl:definitions targetNamespace="http://serviceplatformen.dk/xml/wsdl/soap11/Security/Policy"
xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
<wsdl:definitions xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
xmlns:wsp="http://schemas.xmlsoap.org/ws/2004/09/policy"
xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd"
xmlns:wsam="http://www.w3.org/2007/05/addressing/metadata"
xmlns:sp="http://docs.oasis-open.org/ws-sx/ws-securitypolicy/200702">
xmlns:sp="http://docs.oasis-open.org/ws-sx/ws-securitypolicy/200702"
targetNamespace="http://serviceplatformen.dk/xml/wsdl/soap11/Security/Policy">
<wsp:Policy Name="policies.wsdl#ServiceplatformBindingPolicy">
<wsp:ExactlyOne>
@ -37,7 +37,8 @@
<wsp:Policy>
<sp:InitiatorToken>
<wsp:Policy>
<sp:SamlToken sp:IncludeToken="http://docs.oasis-open.org/ws-sx/ws-securitypolicy/200702/IncludeToken/Never">
<sp:SamlToken
sp:IncludeToken="http://docs.oasis-open.org/ws-sx/ws-securitypolicy/200702/IncludeToken/Never">
<wsp:Policy>
<sp:WssSamlV20Token11/>
</wsp:Policy>
@ -46,7 +47,8 @@
</sp:InitiatorToken>
<sp:RecipientToken>
<wsp:Policy>
<sp:X509Token sp:IncludeToken="http://docs.oasis-open.org/ws-sx/ws-securitypolicy/200702/IncludeToken/AlwaysToInitiator">
<sp:X509Token
sp:IncludeToken="http://docs.oasis-open.org/ws-sx/ws-securitypolicy/200702/IncludeToken/AlwaysToInitiator">
<wsp:Policy>
<sp:WssX509V3Token10/>
</wsp:Policy>
@ -70,7 +72,8 @@
</sp:AsymmetricBinding>
<sp:SignedSupportingTokens>
<wsp:Policy>
<sp:IssuedToken sp:IncludeToken="http://docs.oasis-open.org/ws-sx/ws-securitypolicy/200702/IncludeToken/AlwaysToRecipient">
<sp:IssuedToken
sp:IncludeToken="http://docs.oasis-open.org/ws-sx/ws-securitypolicy/200702/IncludeToken/AlwaysToRecipient">
<sp:RequestSecurityTokenTemplate/>
<wsp:Policy>
<sp:WssSamlV20Token11/>

View File

@ -1,11 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<xsd:schema xmlns:tns="http://serviceplatformen.dk/xml/wsdl/soap11/DistributionService/3/types"
targetNamespace="http://serviceplatformen.dk/xml/wsdl/soap11/DistributionService/3/types"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
targetNamespace="http://serviceplatformen.dk/xml/wsdl/soap11/DistributionService/3/types"
elementFormDefault="qualified"
version="1.0">
<xsd:element name="TransportKvittering" type="tns:TransportkvitteringType" />
<xsd:element name="TransportKvittering" type="tns:TransportkvitteringType"/>
<xsd:simpleType name="TransportValideringsKodeType">
<xsd:restriction base="xsd:string">
<xsd:enumeration value="OK"/>
@ -16,7 +16,8 @@
<xsd:complexType name="TransportkvitteringType">
<xsd:sequence>
<xsd:element name="TransportValideringsKode" type="tns:TransportValideringsKodeType" minOccurs="1" maxOccurs="1"/>
<xsd:element name="TransportValideringsKode" type="tns:TransportValideringsKodeType" minOccurs="1"
maxOccurs="1"/>
<xsd:element name="Begrundelse" type="xsd:string" minOccurs="0" maxOccurs="1"/>
<xsd:element name="FejlListe" type="tns:FejlListeType" minOccurs="0" maxOccurs="1"/>
</xsd:sequence>
@ -55,7 +56,8 @@
<xsd:complexType name="ForretningskvitteringType">
<xsd:sequence>
<xsd:element name="ForretningsValideringsKode" type="tns:ForretningsValideringsKodeType" minOccurs="1" maxOccurs="1"/>
<xsd:element name="ForretningsValideringsKode" type="tns:ForretningsValideringsKodeType" minOccurs="1"
maxOccurs="1"/>
<xsd:element name="Kvitteringstype" type="tns:KvitteringstypeType" minOccurs="1" maxOccurs="1"/>
<xsd:element name="Begrundelse" type="xsd:string" minOccurs="0" maxOccurs="1"/>
<xsd:element name="FejlListe" type="tns:FejlListeType" minOccurs="0" maxOccurs="1"/>

View File

@ -1,37 +1,35 @@
using System;
using System.IO;
using System.Text;
using System.Text.Json;
using System.Text.Json.Serialization;
using System.Xml.Serialization;
namespace XSDVisualiser.Utils
namespace XSDVisualiser.Utils;
public static class Serialization
{
public static class Serialization
private static readonly JsonSerializerOptions JsonOptions = new()
{
private static readonly JsonSerializerOptions JsonOptions = new()
{
WriteIndented = true,
DefaultIgnoreCondition = System.Text.Json.Serialization.JsonIgnoreCondition.WhenWritingNull
};
WriteIndented = true,
DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingNull
};
public static string ToXml<T>(T obj)
{
var serializer = new XmlSerializer(typeof(T));
var ns = new XmlSerializerNamespaces();
ns.Add(string.Empty, string.Empty);
using var sw = new Utf8StringWriter();
serializer.Serialize(sw, obj, ns);
return sw.ToString();
}
public static string ToXml<T>(T obj)
{
var serializer = new XmlSerializer(typeof(T));
var ns = new XmlSerializerNamespaces();
ns.Add(string.Empty, string.Empty);
using var sw = new Utf8StringWriter();
serializer.Serialize(sw, obj, ns);
return sw.ToString();
}
public static string ToJson<T>(T obj)
{
return JsonSerializer.Serialize(obj, JsonOptions);
}
public static string ToJson<T>(T obj)
{
return JsonSerializer.Serialize(obj, JsonOptions);
}
private sealed class Utf8StringWriter : StringWriter
{
public override Encoding Encoding => Encoding.UTF8;
}
private sealed class Utf8StringWriter : StringWriter
{
public override Encoding Encoding => Encoding.UTF8;
}
}

View File

@ -1,16 +1,16 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net9.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<Compile Remove="Models\**\*.cs" />
<Compile Remove="Parsing\**\*.cs" />
<Compile Remove="Utils\**\*.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\XSDVisualiser.Core\XSDVisualiser.Core.csproj" />
</ItemGroup>
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net9.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<Compile Remove="Models\**\*.cs"/>
<Compile Remove="Parsing\**\*.cs"/>
<Compile Remove="Utils\**\*.cs"/>
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\XSDVisualiser.Core\XSDVisualiser.Core.csproj"/>
</ItemGroup>
</Project>