Fixed export kinda for choice / group elements

This commit is contained in:
Frederik Jacobsen 2025-10-18 23:52:46 +02:00
parent ba960e9a64
commit e8c30e8a05

View File

@ -370,9 +370,15 @@ public partial class LeftTreeView : UserControl
await writer.FlushAsync(); await writer.FlushAsync();
} }
private static string SanitizeXmlLocalName(string? name, string fallback)
{
var candidate = string.IsNullOrWhiteSpace(name) ? fallback : name!;
return XmlConvert.EncodeLocalName(candidate);
}
private static void WriteElementRecursive(XmlWriter writer, SchemaNode node) private static void WriteElementRecursive(XmlWriter writer, SchemaNode node)
{ {
var localName = string.IsNullOrWhiteSpace(node.Name) ? "Element" : node.Name!; var localName = SanitizeXmlLocalName(node.Name, "Element");
if (!string.IsNullOrEmpty(node.Namespace)) if (!string.IsNullOrEmpty(node.Namespace))
writer.WriteStartElement(localName, node.Namespace); writer.WriteStartElement(localName, node.Namespace);
else else
@ -381,7 +387,7 @@ public partial class LeftTreeView : UserControl
// Write attributes if any (use type + constraints as placeholder value) // Write attributes if any (use type + constraints as placeholder value)
foreach (var attr in node.Attributes) foreach (var attr in node.Attributes)
{ {
var attrName = string.IsNullOrWhiteSpace(attr.Name) ? "attr" : attr.Name!; var attrName = SanitizeXmlLocalName(attr.Name, "attr");
var value = BuildTypeAndConstraintText(attr.BuiltInType ?? attr.TypeName, attr.Constraints); var value = BuildTypeAndConstraintText(attr.BuiltInType ?? attr.TypeName, attr.Constraints);
if (!string.IsNullOrEmpty(attr.Namespace)) if (!string.IsNullOrEmpty(attr.Namespace))
writer.WriteAttributeString(attrName, attr.Namespace, value); writer.WriteAttributeString(attrName, attr.Namespace, value);