From 8fd41727615442f5cb2b6f9408d2b7f115729539 Mon Sep 17 00:00:00 2001 From: Michael Ganss Date: Tue, 26 Jul 2022 11:12:09 +0200 Subject: [PATCH] Fix #343 Add support for redefined complexTypes --- XmlSchemaClassGenerator.Tests/XmlTests.cs | 18 + .../xsd/graphml/graphml-structure.xsd | 1108 +++++++ .../xsd/graphml/graphml.xsd | 345 +++ .../xsd/graphml/portconstraints.xsd | 106 + .../xsd/graphml/xlink.xsd | 59 + .../xsd/graphml/yfeatures.xsd | 23 + .../xsd/graphml/ygraphics.xsd | 2663 +++++++++++++++++ .../xsd/graphml/ygraphml.xsd | 105 + .../xsd/graphml/yprocessors.xsd | 87 + XmlSchemaClassGenerator/ModelBuilder.cs | 86 +- XmlSchemaClassGenerator/TypeModel.cs | 4 +- 11 files changed, 4577 insertions(+), 27 deletions(-) create mode 100644 XmlSchemaClassGenerator.Tests/xsd/graphml/graphml-structure.xsd create mode 100644 XmlSchemaClassGenerator.Tests/xsd/graphml/graphml.xsd create mode 100644 XmlSchemaClassGenerator.Tests/xsd/graphml/portconstraints.xsd create mode 100644 XmlSchemaClassGenerator.Tests/xsd/graphml/xlink.xsd create mode 100644 XmlSchemaClassGenerator.Tests/xsd/graphml/yfeatures.xsd create mode 100644 XmlSchemaClassGenerator.Tests/xsd/graphml/ygraphics.xsd create mode 100644 XmlSchemaClassGenerator.Tests/xsd/graphml/ygraphml.xsd create mode 100644 XmlSchemaClassGenerator.Tests/xsd/graphml/yprocessors.xsd diff --git a/XmlSchemaClassGenerator.Tests/XmlTests.cs b/XmlSchemaClassGenerator.Tests/XmlTests.cs index d091b056..021841a3 100644 --- a/XmlSchemaClassGenerator.Tests/XmlTests.cs +++ b/XmlSchemaClassGenerator.Tests/XmlTests.cs @@ -108,6 +108,7 @@ private static IEnumerable ConvertXml(string name, string xsd, Generator const string DtsxPattern = "xsd/dtsx/dtsx2.xsd"; const string WfsPattern = "xsd/wfs/schemas.opengis.net/wfs/2.0/wfs.xsd"; const string EppPattern = "xsd/epp/*.xsd"; + const string GraphMLPattern = "xsd/graphml/ygraphml.xsd"; const string NullableReferenceAttributesPattern = "xsd/nullablereferenceattributes/nullablereference.xsd"; // IATA test takes too long to perform every time @@ -128,6 +129,23 @@ private static IEnumerable ConvertXml(string name, string xsd, Generator // SharedTestFunctions.TestSamples(Output, "Iata", IataPattern); //} + [Fact, TestPriority(1)] + [UseCulture("en-US")] + public void TestGraphML() + { + Compiler.Generate("GraphML", GraphMLPattern, new Generator + { + NamespaceProvider = new Dictionary { + { new NamespaceKey(new Uri("graphml.xsd", UriKind.RelativeOrAbsolute), "http://graphml.graphdrawing.org/xmlns"), "GraphML.Main" }, + { new NamespaceKey(new Uri("graphml-structure.xsd", UriKind.RelativeOrAbsolute), "http://graphml.graphdrawing.org/xmlns"), "GraphML.Structure" }, + { new NamespaceKey(new Uri("ygraphxml.xsd", UriKind.RelativeOrAbsolute), "http://graphml.graphdrawing.org/xmlns"), "GraphML.Y" }, + { new NamespaceKey("http://www.w3.org/1999/xlink"), "XLink" }, + { new NamespaceKey("http://www.yworks.com/xml/graphml"), "YEd" }, + }.ToNamespaceProvider(new GeneratorConfiguration { NamespacePrefix = "GraphML" }.NamespaceProvider.GenerateNamespace), + }); + SharedTestFunctions.TestSamples(Output, "GraphML", GraphMLPattern); + } + [Fact, TestPriority(1)] [UseCulture("en-US")] public void TestClient() diff --git a/XmlSchemaClassGenerator.Tests/xsd/graphml/graphml-structure.xsd b/XmlSchemaClassGenerator.Tests/xsd/graphml/graphml-structure.xsd new file mode 100644 index 00000000..0d9daec9 --- /dev/null +++ b/XmlSchemaClassGenerator.Tests/xsd/graphml/graphml-structure.xsd @@ -0,0 +1,1108 @@ + + + + + + The schema corresponding to this document defines the structural + layer of the Graph Markup Language (GraphML). + Although a DTD is provided, this schema is, together with its extensions + http://graphml.graphdrawing.org/xmlns/1.0/graphml-attributes.xsd + and + http://graphml.graphdrawing.org/xmlns/1.0/graphml-parseinfo.xsd, + the only normative reference. + + + + + + + Get access to the xlink attribute groups for the attributes + xlink:href and xlink:type of locator.type. + + + + + + + The attribute groups <element_name>.extra.attrib may be used + for adding user defined attributes to the elements + <element_name>. + The attribute group common.extra.attrib may be used for adding + user defined attributes to all elements. + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Complex type definitions for the GraphML structural layer elements: + <data>, <default>, <key>, <graphml>, <graph>, + <node>, <port>, + <edge>, <hyperedge>, <endpoint> and <locator>. + The names of the complex types are constructed corresponding + to the pattern element_name.type. + (The only remaining GraphML structural layer element + <desc> is of simple type xs:string.) + + + + + + + + Extension mechanism for the content of <data> and <default>. + The complex type data-extension.type is empty per default. + Users may redefine this type in order to add content to + the complex types data.type and default.type which are + extensions of data-extension.type. + + + + + + + + + + Complex type for the <data> element. + data.type is mixed, that is, <data> may contain #PCDATA. + Content type: extension of data-extension.type which is empty + per default. + + + + + + + refers to the id attribute of a <key>. + + + + + + identifies this <data>. + + + + + + + user defined extra attributes for <data> elements + + + + + + + + + + + + Complex type for the <default> element. + default.type is mixed, that is, data may contain #PCDATA. + Content type: extension of data-extension.type which is empty + per default. + + + + + + + + user defined extra attributes for <default> elements + + + + + + + + + + + + Simple type for the for attribute of <key>. + key.for.type is a restriction of xs:NMTOKEN + Allowed values: all, graphml, graph, node, edge, hyperedge, port and endpoint. + + + + + + + + + + + + + + + + + + + Complex type for the <key> element. + + + + + + + + + identifies this <key>. + + + + + + + describes the domain of definition for + the corresponding graph attribute. + + + + + + + user defined extra attributes for <key> elements. + + + + + + + + + + Complex type for the <graphml> element. + + + + + + + + + + + + + + + + user defined extra attributes for <graphml> elements. + + + + + + + + + + Simple type for the edgedefault attribute of <graph>. + graph.edgedefault.type is a restriction of xs:NMTOKEN + Allowed values: directed, undirected. + + + + + + + + + + + + + Complex type for the <graph> element. + + + + + + + + + + + + + + + + + + + + user defined extra attributes for <graph> elements. + + + + + + + identifies this graph . + + + + + + + describes whether edges of this graph are considered + as directed or undirected per default (unless + specified by the attribute directed of <edge>). + + + + + + + + + + Complex type for the <node> element. + + + + + + + + + + + + + + + + + + + user defined extra attributes for <node elements. + + + + + + + identifies this node. + + + + + + + + + + Complex type for the <port> element. + + + + + + + + + + + + + user defined extra attributes for <port> elements. + + + + + + + identifies this port, within the node it is contained in. + + + + + + + + + + Complex type for the <edge> element. + + + + + + + + + + + user defined extra attributes for <edge> elements. + + + + + + + identifies this edge . + + + + + + + overwrites the edgedefault attribute of <graph> . + + + + + + + points to the id attribute of the source <node>. + + + + + + + points to the id attribute of the target <node>. + + + + + + + points to the name attribute of the source <port>. + + + + + + + points to the name attribute of the target <port>. + + + + + + + + + + Complex type for the <hyperedge> element. + + + + + + + + + + + + + + user defined extra attributes for <hyperedge> elements. + + + + + + + identifies this <hyperedge> . + + + + + + + + + + Simple type for the type attribute of <endpoint>. + endpoint.type.type is a restriction of xs:NMTOKEN + Allowed values: in, out, undir. + + + + + + + + + + + + + Complex type for the <endpoint> element. + + + + + + + + + user defined extra attributes for <endpoint> elements. + + + + + + + identifies this <endpoint> . + + + + + + + points to the name of the port, to which this endpoint is + connected . + + + + + + + points to the id of the node, to which this endpoint is connected. + + + + + + + defines the direction on this endpoint (undirected per default). + + + + + + + + + + Complex type for the <locator> element. + Content type: (empty) + + + + + + user defined extra attributes for <locator> elements. + + + + + + + points to the resource of this locator. + + + + + + + + type of the hyperlink (fixed as simple). + + + + + + + + + + + Description: Provides human-readable descriptions for the GraphML + element containing this <desc> as its first child. + Occurence: <key>, <graphml>, <graph>, + <node>, <port>, <edge>, <hyperedge>, and + <endpoint>. + + + + + + + + + Description: Graphs and nodes are declared by the elements + <graph> and <node>, respectively. The optional + <locator>-child of these elements point to + their definition. (If there is no <locator>-child + the graphs/nodes are defined by their content). + Occurence: <graph>, and <node>. + + + + + + + + Description: In GraphML there may be data-functions attached + to graphs, nodes, ports, edges, hyperedges and + endpoint and to the whole collection of + graphs described by the content of <graphml>. + These functions are declared by <key> elements + (children of <graphml>) and defined by <data> + elements. + Occurence: <graphml>, <graph>, <node>, <port>, + <edge>, <hyperedge>, and <endpoint>. + + + + + + + Ensures: uniqueness of the key attributes of <data> children + of this <data> element. + + + + + + + + + + + + + Description: In GraphML there may be data-functions attached + to graphs, nodes, ports, edges, hyperedges and + endpoint and to the whole collection of + graphs described by the content of <graphml>. + These functions are declared by <key> elements + (children of <graphml>) and defined by <data> + elements. + Occurence: <graphml>. + + + + + + + + Description: In GraphML there may be data-functions attached + to graphs, nodes, ports, edges, hyperedges and + endpoint and to the whole collection of + graphs described by the content of <graphml>. + These functions are declared by <key> elements + (children of <graphml>) and defined by <data> + elements. + The (optional) <default> child of <key> gives + the default value for the corresponding function. + Occurence: <key>. + + + + + + + + Description: <graphml> is the root element of each GraphML + document. + Occurence: root. + + + + + + + Ensures: uniqueness of the key attributes of <data> children + of this <graphml> element. + + + + + + + + + + Ensures: existence and uniqueness of the id attributes of + each <key> element in this document. + + + + + + + + + + + Ensures: uniqueness of the id attributes of + each <graph> element in this document. + + + + + + + + + + Ensures: for the key attribute of each <data> in this document, + the existence of an id attribute of + <key> which matches the value of it. + + + + + + + + + + + + + + Description: Describes one graph in this document. + Occurence: <graphml>, <node>, <edge>, <hyperedge>. + + + + + + + Ensures: uniqueness of the key attributes of <data> children + of this <graph> element. + + + + + + + + + + Ensures: existence and uniqueness of the id attributes of + each <node> element in this graph. + + + + + + + + + + Ensures: uniqueness of the id attributes of + each <edge> element in this graph. + + + + + + + + + + Ensures: uniqueness of the id attributes of + each <hyperedge> element in this graph. + + + + + + + + + + Ensures: uniqueness of the id attributes of + each <endpoint> element in this graph. + + + + + + + + + + Ensures: for the source attribute of each <edge> in this graph, + the existence of an id attribute of + <node> which matches the value of it. + + + + + + + + + + Ensures: for the target attribute of each <edge> in this graph, + the existence of an id attribute of + <node> which matches the value of it. + + + + + + + + + + Ensures: for the node attribute of each <endpoint> in this graph, + the existence of an id attribute of + <node> which matches the value of it. + + + + + + + + + + + + + Description: Describes one node in the <graph> + containing this <node>. + Occurence: <graph>. + + + + + + + Ensures: existence and uniqueness of the name attributes of + each <port> element within this <node>. + + + + + + + + + + Ensures: uniqueness of the key attributes of <data> children + of this <node> element. + + + + + + + + + + + + + Description: Nodes may be structured by ports; thus edges + are not only attached to a node but to a certain + port in this node. + Occurence: <node>, <port>. + + + + + + + Ensures: uniqueness of the key attributes of <data> children + of this <port> element. + + + + + + + + + + + + + Description: Describes an edge in the <graph> which contains this + <edge>. + Occurence: <graph>. + + + + + + + Ensures: uniqueness of the key attributes of <data> children + of this <edge> element. + + + + + + + + + + + + + Description: While edges describe relations between two nodes, + a hyperedge describes a relation between an arbitrary + number of nodes. + Occurence: <graph>. + + + + + + + Ensures: uniqueness of the key attributes of <data> children + of this <hyperedge> element. + + + + + + + + + + + + + Description: The list of <endpoints> within a hyperedge + points to the nodes contained in this hyperedge. + Occurence: <hyperedge>. + + + + + + + + + diff --git a/XmlSchemaClassGenerator.Tests/xsd/graphml/graphml.xsd b/XmlSchemaClassGenerator.Tests/xsd/graphml/graphml.xsd new file mode 100644 index 00000000..2d781833 --- /dev/null +++ b/XmlSchemaClassGenerator.Tests/xsd/graphml/graphml.xsd @@ -0,0 +1,345 @@ + + + + + + + This document defines the GraphML language including GraphML attributes and GraphML parseinfo. + + + + + + + Redefinition of file graphml-structure.xsd. + Extends the attribute group key.extra.attrib (which takes + part in the attribute list of <key>) by adding the + attribute group key.attributes.attrib which is defined below. + + + + + + + + + + + Redefinition of file graphml-structure.xsd. + Extends the attribute group node.extra.attrib (which takes + part in the attribute list of <node>) by adding the + attribute group node.parseinfo.attrib which is defined below. + + + + + + + + + + + Redefinition of file graphml-structure.xsd. + Extends the attribute group graph.extra.attrib (which takes + part in the attribute list of <graph>) by adding the + attribute group graph.parseinfo.attrib which is defined below. + + + + + + + + + + + + + + + + Simple type for the attr.name attribute of <key>. + key.name.type is final, that is, it may not be extended + or restricted. + key.name.type is a restriction of xs:NMTOKEN + Allowed values: (no restriction) + + + + + + + + + + + Simple type for the attr.type attribute of <key>. + key.type.type is final, that is, it may not be extended + or restricted. + key.type.type is a restriction of xs:NMTOKEN + Allowed values: boolean, int, long, float, double, string, complex. + + + + + + + + + + + + + + + + + + Definition of the attribute group key.attributes.attrib. + This group consists of the two optional attributes + - attr.name (gives the name for the data function) + - attr.type (declares the range of values for the data function) + + + + + + + + + + + + + Simple type for the parse.order attribute of <graph>. + graph.order.type is final, that is, it may not be extended + or restricted. + graph.order.type is a restriction of xs:NMTOKEN + Allowed values: free, nodesfirst, adjacencylist. + + + + + + + + + + + + + + + Simple type for the parse.nodes attribute of <graph>. + graph.nodes.type is final, that is, it may not be extended + or restricted. + graph.nodes.type is a restriction of xs:nonNegativeInteger + Allowed values: (no restriction). + + + + + + + + + + + Simple type for the parse.edges attribute of <graph>. + graph.edges.type is final, that is, it may not be extended + or restricted. + graph.edges.type is a restriction of xs:nonNegativeInteger + Allowed values: (no restriction). + + + + + + + + + + + Simple type for the parse.maxindegree attribute of <graph>. + graph.maxindegree.type is final, that is, it may not be extended + or restricted. + graph.maxindegree.type is a restriction of xs:nonNegativeInteger + Allowed values: (no restriction). + + + + + + + + + + + Simple type for the parse.maxoutdegree attribute of <graph>. + graph.maxoutdegree.type is final, that is, it may not be extended + or restricted. + graph.maxoutdegree.type is a restriction of xs:nonNegativeInteger + Allowed values: (no restriction). + + + + + + + + + + + Simple type for the parse.nodeids attribute of <graph>. + graph.nodeids.type is final, that is, it may not be extended + or restricted. + graph.nodeids.type is a restriction of xs:string + Allowed values: (no restriction). + + + + + + + + + + + + + + Simple type for the parse.edgeids attribute of <graph>. + graph.edgeids.type is final, that is, it may not be extended + or restricted. + graph.edgeids.type is a restriction of xs:string + Allowed values: (no restriction). + + + + + + + + + + + + + + Definition of the attribute group graph.parseinfo.attrib. + This group consists of the seven attributes: +
    +
  • parse.nodeids
  • (fixed to 'canonical' meaning that the id attribute + of <node> follows the pattern 'n[number]), +
  • parse.edgeids
  • (fixed to 'canonical' meaning that the id attribute + of <edge> follows the pattern 'e[number]), +
  • parse.order
  • (required; one of the values 'nodesfirst', + 'adjacencylist' or 'free'), +
  • parse.nodes
  • (required; number of nodes in this graph), +
  • parse.edges
  • (required; number of edges in this graph), +
  • parse.maxindegree
  • (optional; maximal indegree of a node in this graph), +
  • parse.maxoutdegree
  • (optional; maximal outdegree of a node in this graph) +
+
+
+ + + + + + + + +
+ + + + + + + Simple type for the parse.indegree attribute of <node>. + node.indegree.type is final, that is, it may not be extended + or restricted. + node.indegree.type is a restriction of xs:nonNegativeInteger + Allowed values: (no restriction). + + + + + + + + + + + Simple type for the parse.outdegree attribute of <node>. + node.outdegree.type is final, that is, it may not be extended + or restricted. + node.outdegree.type is a restriction of xs:nonNegativeInteger + Allowed values: (no restriction). + + + + + + + + + + + Definition of the attribute group node.parseinfo.attrib. + This group consists of two attributes + - parse.indegree (optional; indegree of this node), + - parse.outdegree (optional; outdegree of this node). + + + + + + + +
\ No newline at end of file diff --git a/XmlSchemaClassGenerator.Tests/xsd/graphml/portconstraints.xsd b/XmlSchemaClassGenerator.Tests/xsd/graphml/portconstraints.xsd new file mode 100644 index 00000000..d8e2519b --- /dev/null +++ b/XmlSchemaClassGenerator.Tests/xsd/graphml/portconstraints.xsd @@ -0,0 +1,106 @@ + + + + + + + + + The valid endpoint types of a port constraint. +

+ Valid values are: +

    +
  • source: for a source port constraint
  • +
  • target: for a target port constraint
  • +
+

+
+
+ + + + +
+ + + + + The valid locations of a port constraint. +

+ Valid values are: +

    +
  • east: for an east location
  • +
  • west: for a west location
  • +
  • north: for a north location
  • +
  • south: for a south location
  • +
  • any: for any location
  • +
+

+
+
+ + + + + + + +
+ + + + + + Complex type definition for a portconstraint. + + + + + + The type of the constraint (source or target). + + + + + + + The location of the constraint (source or target). + + + + + + + Whether this is a strong port constraint. + + + + + + + An optional edge group id. + + + + + + + + + + PortConstraint element definition. + + + + +
diff --git a/XmlSchemaClassGenerator.Tests/xsd/graphml/xlink.xsd b/XmlSchemaClassGenerator.Tests/xsd/graphml/xlink.xsd new file mode 100644 index 00000000..4de85194 --- /dev/null +++ b/XmlSchemaClassGenerator.Tests/xsd/graphml/xlink.xsd @@ -0,0 +1,59 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/XmlSchemaClassGenerator.Tests/xsd/graphml/yfeatures.xsd b/XmlSchemaClassGenerator.Tests/xsd/graphml/yfeatures.xsd new file mode 100644 index 00000000..ece11064 --- /dev/null +++ b/XmlSchemaClassGenerator.Tests/xsd/graphml/yfeatures.xsd @@ -0,0 +1,23 @@ + + + + + + Schema definitions for yFiles GraphML graphics and + postprocessor extensions. + + + + + + + diff --git a/XmlSchemaClassGenerator.Tests/xsd/graphml/ygraphics.xsd b/XmlSchemaClassGenerator.Tests/xsd/graphml/ygraphics.xsd new file mode 100644 index 00000000..2039b64c --- /dev/null +++ b/XmlSchemaClassGenerator.Tests/xsd/graphml/ygraphics.xsd @@ -0,0 +1,2663 @@ + + + + + + + + + + + + + + The valid line types for an edge or node realizer. +

+ Valid values are: +

    +
  • + line: for a continous line +
  • +
  • + dashed: for a dashed line +
  • +
  • + dotted: for a dotted line +
  • +
  • + dashed_dotted: for a dash-dotted line +
  • +
+

+
+
+ + + + + + +
+ + + + + + The valid font types for a label. +

+ Valid values are: +

    +
  • + plain + : for a plain font +
  • +
  • + bold + : for a bold font +
  • +
  • + italic + : for an italic font +
  • +
  • + bolditalic + : for a bold and italic font +
  • +
+

+
+
+ + + + + + +
+ + + + + + + + The shape types for a ShapeNodeRealizer. +

+ Valid values are: +

    +
  • + rectangle + : for a rectangular shape +
  • +
  • + roundrectangle + : for a rectangular shape with rounded corners +
  • +
  • + ellipse + : for an elliptical shape +
  • +
  • + parallelogram + : for a parallelogram shape +
  • +
  • + hexagon + : for a hexagonal shape +
  • +
  • + octagon + : for a octagonal shape +
  • +
  • + diamond + : for a diamond shape +
  • +
  • + triangle + : for a triangular shape +
  • +
  • + trapezoid + : for a trapezoidal shape, whose upper line is half as long as its lower line +
  • +
  • + trapezoid2 + : for a trapezoidal shape, whose lower line is half as long as its upper line +
  • +
  • + rectangle3d + : for a rectangular shape with 3D-ish looks +
  • +
+

+
+
+ + + + + + + + + + + +
+
+ + + + + + The arrow types for EdgeRealizers. +

+ Valid values are: +

    +
  • standard: for the default arrow
  • +
  • delta: for a triangular arrow shape
  • +
  • white_delta: like delta, but filled white
  • +
  • diamond: for a diamond arrow shape
  • +
  • white_diamond: like diamond, but filled white
  • +
  • none: for no arrow
  • +
  • plain: for the plain arrow
  • +
  • concave: for a concave arrow
  • +
  • convex: for a convex arrow
  • +
  • circle: for a circle arrow
  • +
  • dash: for a dash arrow
  • +
  • transparent_circle: for a transparent circle arrow
  • +
  • skewed_dash: for a skewed dash arrow
  • +
  • t_shape: for a T-shaped arrow
  • +
+

+
+
+ + + + + + + + + + + + + + + + +
+ + + + + + + The valid alignemts for labels. +

+ Valid values are: +

    +
  • center: center alignment
  • +
  • left: left alignment
  • +
  • right: right alignment
  • +
+

+
+
+ + + + + +
+ + + + + + The valid label models for node labels. +

+ Valid values are: +

    +
  • free: free model
  • +
  • sides: sides model
  • +
  • corners: corners model
  • +
  • eight_pos: sides+corners model
  • +
  • sandwich: sandwich model
  • +
  • internal: internal model
  • +
  • custom: custom model
  • +
+

+
+
+ + + + + + + + + +
+ + + + + + The valid label positions for node labels. +

+ Note: + For a given node label model, the set of valid + label positions is a subset of this enumeration that depends on the + actual node label model. +

+

+ Valid values are: +

    +
  • n: north (outside)
  • +
  • nw: north west (outside)
  • +
  • ne: north east(outside)
  • +
  • w: west (outside)
  • +
  • e: east (outside)
  • +
  • sw: south west (outside)
  • +
  • s: south (outside)
  • +
  • se: south east (outside)
  • +
  • c: center (inside)
  • +
  • tl: top left (inside)
  • +
  • t: top (inside)
  • +
  • tr: top right (inside)
  • +
  • r: right (inside)
  • +
  • l: left (inside)
  • +
  • bl: bottom left (inside)
  • +
  • b: bottom (inside)
  • +
  • br: bottom right (inside)
  • +
  • anywhere: anywhere
  • +
+

+
+
+ + + + + + + + + + + + + + + + + + + + +
+ + + + + + The auto size policies for node labels. +

+ Valid values are: +

    +
  • node_width: resize to node width
  • +
  • node_height:resize to node height
  • +
  • content: resize to content size
  • +
  • none: no automatic resizing
  • +
+

+
+
+ + + + + + +
+ + + + + + The valid label models for node labels. +

+ Valid values are: +

    +
  • centered: edge center
  • +
  • center_slider: edge center, freeley movable
  • +
  • side_slider: edge side, freely movable
  • +
  • free: free model
  • +
  • two_pos: source or target only
  • +
  • three_center: three positions at edge center
  • +
  • six_pos: three positions at either source or target
  • +
  • custom: for a custom model
  • +
+

+
+
+ + + + + + + + + + +
+ + + + + + The valid label positions for edge labels. +

+ Note: + For a given edge label model, the set of valid + label positions is a subset of this enumeration that depends on the + actual edge label model. +

+

+ Valid values are: +

    +
  • center: at source on the edge segment
  • +
  • tcentr: at target on the edge segment
  • +
  • scentr: at center on the edge segment
  • +
  • stail: at source below the edge segment
  • +
  • ttail: at target below the edge segment
  • +
  • tail: at center below the edge segment
  • +
  • shead: at source above the edge segment
  • +
  • thead: at target above the edge segment
  • +
  • head: at center above the edge segment
  • +
  • anywhere: anywhere
  • +
+

+
+
+ + + + + + + + + + + + +
+ + + + + + The valid preferred label positions for edge labels. +

+ Note: + For a given edge label model, the set of valid + preferred label positions is a subset of this enumeration that depends on the + actual edge label model. This value is evaluated by automatic label layout algorithms and may differ + from the actual label position. +

+

+ Valid values are: +

    +
  • target_right: at target right from the edge segment
  • +
  • target: anywhere at the target
  • +
  • target_left: at target left from the edge segment
  • +
  • target_on_edge: at target on the edge segment
  • +
  • source_right: at source right from the edge segment
  • +
  • source: anywhere at the source
  • +
  • source_left: at source left from the edge segment
  • +
  • source_on_edge: at source on the edge segment
  • +
  • center_right: at center right from the edge segment
  • +
  • center: anywhere at the center
  • +
  • center_left: at center left from the edge segment
  • +
  • center_on_edge: at center on the edge segment
  • +
  • anywhere: anywhere
  • +
  • on_edge: anywhere on the edge
  • +
  • left: anywhere left from the edge
  • +
  • right: anywhere right from the edge
  • +
+

+
+
+ + + + + + + + + + + + + + + + + + + +
+ + + + + + The valid horizontal text vs. icon alignements for labels. +

+ Valid values are: +

    +
  • left: place text to the left of the icon
  • +
  • right: place text to the right of the icon
  • +
  • center: place text on center of the icon
  • +
  • left_aligned: align text to the left of the icon
  • +
  • right_aligned: align text to the right of the icon
  • +
+

+
+
+ + + + + + + +
+ + + + + + The valid vertical text vs. icon alignements for labels. +

+ Valid values are: +

    +
  • top: place text above the icon
  • +
  • bottom: place text below the icon
  • +
  • center: place text on center of the icon
  • +
+

+
+
+ + + + + +
+ + + + + + + + + + Attribute group that describes a two-dimensional location, specified by the x and y attribute. + + + + + + The x coordinate of the point. + + + + + + + The y coordinate of the point. + + + + + + + + + + Attribute group that describes a two-dimensional rectangle. +

+ The location is specified by the x and y attribute, the dimension by the width and height attributes. +

+
+
+ + + + The x coordinate of the rectangle. + + + + + + + The y coordinate of the rectangle. + + + + + + + The width of the rectangle. + + + + + + + The height of the rectangle. + + + +
+ + + + + + Type definition for rectangles. + + + + + + + + + + Attribute group that describes a two-dimensional rectangle, where attribtue values are optional. +

+ The location is specified by the x and y attribute, the dimension by the width and height attributes. +

+
+
+ + + + The x coordinate of the rectangle. + + + + + + + The y coordinate of the rectangle. + + + + + + + The width of the rectangle. + + + + + + + The height of the rectangle. + + + +
+ + + + + + Attribute group that describes a two-dimensional path, consisting of a point list together with optional source + and target locations. +

+ The source resp. target location is specified by the sx and sy resp. tx and ty attributes. +

+
+
+ + + + + Single control point for two dimensional paths. + + + + + + + + + + + true iff the path should be rendered in reverse order. + + + + + + + The x coordinate of the source point. + + + + + + + The y coordinate of the source point. + + + + + + + The x coordinate of the target point. + + + + + + + The y coordinate of the target point. + + + +
+ + + + + + + + + + + Simple type that encodes a color value. + + + + + + + + + + + + Complex type that describes the attributes of a line style. + + + + + + The color of the line. + + + + + + + Whether the line has a color set. If false, the line is invisible. + + + + + + + The type of the line. + + + + + + + The width of the line. + + + + + + + + + + Complex type that describes the attributes of a drop shadow. + + + + + + The color of the drop shadow. + + + + + + + The offset in x direction. + + + + + + + The offset in y direction. + + + + + + + + + + + + + + Complex type that describes the common attributes of node and edge labels. + + + + + + + The (optional) custom label model. + + + + + + + + + + + + The (optional) custom label model parameter. + + + + + + + + + + + + + + Whether the label is visible or not. + + + + + + + The alignment of the label. + + + + + + + The text color of the label. + + + + + + + The border color of the label's content rectangle. + + + + + + + Whether the label border should be painted. + + + + + + + The background color of the label's content rectangle. + + + + + + + Whether the label background should be painted. + + + + + + + Whether the label has (possibly empty) text. + + + + + + + The font family for the label text. + + + + + + + The font size for the label text. + + + + + + + The font style for the label text. + + + + + + + The rotation angle style for the label. + + + + + + + The URL of an icon for the label. + + + + + + + Reference to an embedded image resource. + + + + + + + Reference to an embedded arbitrary serializable resource. + + + + + + + Whether to underline the label text. + + + + + + + The horizontal text position wrt to an optional icon. + + + + + + + The vertical text position wrt to an optional icon. + + + + + + + The distance between the label text and an optional icon. + + + + + + + The optional configuration of the label. + + + + + + + + + + Complex type that describes the additional attributes of node labels. + + + + + + + + The label model. + + + + + + + The actual label position in the current label model. + + + + + + + The auto size policy of the label. + + + + + + + The distance of the label to the node. + + + + + + + + + + + + Complex type that describes the additional attributes of edge labels. + + + + + + + + The label model. + + + + + + + The actual label position in the current label model. + + + + + + + The preferred label position in the current label model. + + + + + + + The current label distance from the edge. + + + + + + + The current label position along the edge, expressed as ratio from source to target. + + + + + + + + + + + Complex type that describes the label model for both row and column labels in TableGroupNodes. + + + + + + The offset of the label. + + + + + + + + + Complex type that describes the common properties of the label model parameter for both row and column labels in TableGroupNodes. + + + + + + The id of the column/row for the label. + + + + + + + Whether the label lies inside or not. + + + + + + + + + Element type definition for a row label model in TableGroupNodes. + + + + + + + + Element type definition for a column label model in TableGroupNodes. + + + + + + + + Element type definition for a row label model parameter in TableGroupNodes. + + + + + + + + + The horizontal position of the label. + + + + + + + + + + + + Element type definition for a column label model parameter in TableGroupNodes. + + + + + + + + + The vertical position of the label. + + + + + + + + + + + + Complex type that describes the geometry of simple graph elements. + + + + + + + + + + + + + + Complex type that describes the common attributes of a node realizer in yFiles. + + + + + + + The location and size of the node. + + + + + + + The fill attributes of the node. + + + + + + + Whether the node has a visible fill color. + + + + + + + The first fill color. + + + + + + + The second fill color (for gradient fills). + + + + + + + Whether the node is transparent. + + + + + + + + + The LineStyle of the border. + + + + + + + The (optional) node label. + + + + + + + The (optional) node port list. + + + + + + Ensures: existence and uniqueness of the id attributes of + each <NodePort> element in this resource block. + + + + + + + + + + + Whether the node is currently selected. + + + + + + + + + + Complex type that describes the attributes of a ShapeNodeRealizer in yFiles. + + + + + + + + + The actual shape of a ShapeNodeRealizer. + + + + + + + The shape type. + + + + + + + + + The drop shadow. + + + + + + + + + + + + + Complex type that describes the attributes of an ImageNodeRealizer in yFiles. + + + + + + + + + Encodes an image for an ImageNodeRealizer. + + + + + + + The URL of an image for external image sources. + + + + + + + Whether to use alpha channel information from the image. + + + + + + + Reference to an inlined image resource. +

The refid must point to an existing inlined image resource in a toplevel graphml y:Resource + block. +

+
+
+
+
+
+
+
+
+
+ + + + + Type that can be used to describe insets in integer precision. + + + + + + The minimal inset at the top in integer precision. + + + + + + + The minimal inset at the bottom in integer precision. + + + + + + + The minimal inset at the left in integer precision. + + + + + + + The minimal inset at the right in integer precision. + + + + + + + + + Type that can be used to describe insets in double precision. + + + + + + The minimal inset at the top in double precision. + + + + + + + The minimal inset at the bottom in double precision. + + + + + + + The minimal inset at the left in double precision. + + + + + + + The minimal inset at the right in double precision. + + + + + + + + + Type that can be used to describe insets in both integer and double precision. + + + + + + + + The minimal inset at the top in double precision. + + + + + + + The minimal inset at the bottom in double precision. + + + + + + + The minimal inset at the left in double precision. + + + + + + + The minimal inset at the right in double precision. + + + + + + + + + + + + Complex type that describes the attributes of a GroupNodeRealizer in yFiles. + + + + + + + + + The actual shape of a GroupNodeRealizer. + + + + + + + The shape type. + + + + + + + + + The drop shadow. + + + + + + + The state of a GroupNodeRealizer (open/closed etc.). + + + + + + + Whether the group is currently closed. + + + + + + + Whether to display the inner graph even in closed state. + + + + + + + + + Type that can be used to describe additional data for node bounds determination. + + + + + + + Whether the size of the label should be respected for automatic bounds calculation. + + + + + + + + + The minimal insets of a GroupNodeRealizer. + + + + + + + The extra insets of a GroupNodeRealizer. + + + + + + + + + + + + + Complex type that describes the attributes of a ProxyShapeNodeRealizer in yFiles. +

This Realizer can multiplex between several different realizers for a node.

+
+
+ + + + + List of subordinate realizers for this node realizer. + + + + + + + + + + The list index of the currently active realizer (zero based). + + + + + + +
+ + + + + Type for the UserData that holds the actual state of a generic Node or Edge Realizer. + + + + + + Class name of the data holder instance. + + + + + + + String representation of the user data value. + + + + + + + + + + Complex type that describes the attributes of a GenericNodeRealizer in yFiles. + + + + + + + + + Represents the UserData that holds the actual state of this realizer instance. + + + + + + + Represents the StyleProperties of this realizer instance. + + + + + + + + The name of the configuration. This configuration must have been registered previously. + + + + + + + + + + + + Complex type that describes the attributes of a GenericGroupNodeRealizer in yFiles. + + + + + + + + + The state of a GenericGroupNodeRealizer (open/closed etc.). + + + + + + + Whether the group is currently closed. + + + + + + + Whether the group node should automatically resize itself. + + + + + + + The height of the group node in closed state. + + + + + + + The width of the group node in closed state. + + + + + + + + + The minimal insets of a GroupNodeRealizer. + + + + + + + The extra insets of a GroupNodeRealizer. + + + + + + + + + + + + + Complex type that describes the attributes of a TableGroupNodeRealizer in yFiles. + + + + + + + + + Represents the table structure of this realizer instance. + + + + + + + + + + + + + Complex type that describes the attributes of a TableNodeRealizer in yFiles. + + + + + + + The default insets for a column. + + + + + + + The default insets for a row. + + + + + + + The insets for the table. + + + + + + + List of columns for this table. + + + + + + + + A single column element + + + + + + + + + + List of rows for this table. + + + + + + + + A single row element + + + + + + + + + + + Whether to automatically resize the table. + + + + + + + The default column width of the table. + + + + + + + The default minimum column width of the table. + + + + + + + The default row height of the table. + + + + + + + The default minimum row height of the table. + + + + + + + + + Type definition for a TableNodeRealizer table column. + + + + + + + The insets of the column + + + + + + + + The unique id of the column. + + + + + + + The minimum width of the column. + + + + + + + The width of the column. + + + + + + + + + Type definition for a TableNodeRealizer table row. + + + + + + + The insets of the row. + + + + + + + + The unique id of the row. + + + + + + + The minimum height of the row. + + + + + + + The height of the row. + + + + + + + + + + ShapeNodeRealizer element definition. + + + + + + + ImageNodeRealizer element definition. + + + + + + + GroupNodeRealizer element definition. + + + + + + + GenericNodeRealizer element definition. + + + + + + + GenericGroupNodeRealizer element definition. + + + + + + + ProxyShapeNodeRealizer element definition. + + + + + + + ProxyAutoBoundsNodeRealizer element definition. + + + + + + + TableGroupNodeRealizer element definition. + + + + + + + + + + + + + Complex type that describes the common attributes of an edge realizer in yFiles. + + + + + + + The edge path. + + + + + + + The line style used to draw the edge. + + + + + + + The source and target arrows. + + + + + + + The source arrow type. + + + + + + + The target arrow type. + + + + + + + + + The edge label(s). + + + + + + + The visual edge source port. + + + + + + + The visual edge target port. + + + + + + + + Whether the edge currently is selected. + + + + + + + + + The type of a visual edge port. + + + + + + + The icon of the port. + + + + + + + + The type of the port, currently fixed to InterfacePort. + + + + + + + + + Type definition for an icon. + + + + + + The URL of an icon. + + + + + + + Reference to an embedded image resource. + + + + + + + Reference to an embedded arbitrary serializable resource. + + + + + + + + + Complex type that describes the attributes of a PolylineEdgeRealizer in yFiles. + + + + + + + + + The style used to draw the bends. + + + + + + + Whether to draw smooth instead of angular bends. + + + + + + + + + + + + + + + + The arc types for ArcEdgeRealizers. +

+ Valid values are: +

    +
  • fixedHeight: fixed height, but variable ratio
  • +
  • fixedRatio: fixed ration, but variable height
  • +
+

+
+
+ + + + +
+ + + + + + Complex type that describes the attributes of an ArcEdgeRealizer in yFiles. + + + + + + + + + The Arc. + + + + + + + The arc type. + + + + + + + The current height of the arc. + + + + + + + The current ratio of the arc. + + + + + + + + + + + + + + + Complex type that describes the attributes of a QuadCurveEdgeRealizer in yFiles. + + + + + + + + The straightness of the curve. + + + + + + + + + + + + Complex type that describes the attributes of an GenericEdgeRealizer in yFiles. + + + + + + + + + Represents the UserData that holds the actual state of this realizer instance. + + + + + + + Class name of the data holder instance. + + + + + + + String representation of the user data value. + + + + + + + + + + The name of the configuration. This configuration must have been registered previously. + + + + + + + + + + + + PolyLineEdgeRealizer element definition. + + + + + + + ArcEdgeRealizer element definition. + + + + + + + BezierEdgeRealizer element definition. + + + + + + + SplineEdgeRealizer element definition. + + + + + + + QuadCurveEdgeRealizer element definition. + + + + + + + GenericEdgeRealizer element definition. + + + + + + + + + Complex type that describes the geometry of port elements. + + + + + + + + + + + Port geometry element definition. + + + + + + + + The valid port location policies for NodeScaledPortLocationModel. +

+ Valid values are: +

    +
  • POLICY_DISCRETE
  • +
  • POLICY_BOUNDARY
  • +
  • POLICY_BOUNDARY_CENTER
  • +
  • POLICY_BOUNDARY_INSIDE
  • +
  • POLICY_FREE
  • +
+

+
+
+ + + + + + + +
+ + + + + Complex type that describes a NodeScaledPortLocationModel. + + + + + + + + + + + NodeScaledPortLocationModel element definition. + + + + + + + + Complex type that describes a list of node ports. + + + + + + + A single node port element + + + + + + + + + + Complex type that describes a NodePort. + + + + + + The id of the port. + + + + + + + + + Complex type that describes the label model for node ports. + + + + + + Whether to allow local candidates. + + + + + + + The offset of the label. + + + + + + + + + The valid parameter positions for PortLabelModelParameter. +

+ Valid values are: +

    +
  • north
  • +
  • south
  • +
  • east
  • +
  • west
  • +
  • center
  • +
+

+
+
+ + + + + + + +
+ + + + + Complex type that describes a PortLabelModelParameter. + + + + + + The id of the port for the label. + + + + + + + The position of the parameter. + + + + + + + + + PortLabelModelParameter element definition. + + + + + + + + PortLabelModel element definition. + + + + + + + + Complex type that describes the visual configuration for node ports. + + + + + + The port graphics configuration. + + + + + + + Whether the port is selected. + + + + + + + + + PortGraphics element definition. + + + + + + + + UserData element definition. + + + + + + + + + Complex type for a shared resource element inside a resource block container. + + + + + + The actual content. Note that arbitrary (wellformed) content is allowed here. + + + + + + + + The id of the shared resource. Needed to reference this resource. + + + + + + + The type of the shared resource. + + + + + + + The format of the shared resource. + + + + + + + + + Complex type for a shared resource block container. + + + + + + + A shared resource element. + + + + + + + + + + Resource block element definition. + + + + + + Ensures: existence and uniqueness of the id attributes of + each <Resource> element in this resource block. + + + + + + + + + + + Complex type definition for a single style property. + + + + + + + + + The name of the property. + + + + + + + The class name of the property. + + + + + + + The string value of the property. + + + + + + + + + Complex type definition for a set of style properties for generic node/edge realizers. + + + + + + + + + + + Element type definition for a simple style property. + + + + + + + The fill color of the style. + + + + + + + The line color of the style. + + + + + + + The line type of the style. + + + + + + + The line width of the style. + + + + + + +
diff --git a/XmlSchemaClassGenerator.Tests/xsd/graphml/ygraphml.xsd b/XmlSchemaClassGenerator.Tests/xsd/graphml/ygraphml.xsd new file mode 100644 index 00000000..0c68d28b --- /dev/null +++ b/XmlSchemaClassGenerator.Tests/xsd/graphml/ygraphml.xsd @@ -0,0 +1,105 @@ + + + + + + + + GraphML core language definitions including GraphML attributes and GraphML parseinfo. + + + + + + + + + + + + + Redefinition of file graphml-structure.xsd. +

Extends the attribute group key.extra.attrib (which takes + part in the attribute list of <key>) by adding the + attribute yfiles.type which is defined below. +

+
+
+ + + + + Custom yfiles specific attribute that allows to specify an additional data type. + + + + + + + + + + + Redefinition of file graphml-structure.xsd. +

Extends the attribute group node.extra.attrib (which takes + part in the attribute list of <node>) by adding a + yfiles specific attribute for the folder type. +

+
+
+ + + + + The foldertype for group/folder nodes. + + + + + + + + + + + + + + +
+ + + + + + The valid folder types for a folder/group node. +

Valid values are +

    +
  • folder: for folder nodes
  • +
  • group: for group nodes
  • +
  • leaf: for leaf nodes (this is the implied value)
  • +
+

+
+
+ + + + + +
+ +
+ + diff --git a/XmlSchemaClassGenerator.Tests/xsd/graphml/yprocessors.xsd b/XmlSchemaClassGenerator.Tests/xsd/graphml/yprocessors.xsd new file mode 100644 index 00000000..de565c05 --- /dev/null +++ b/XmlSchemaClassGenerator.Tests/xsd/graphml/yprocessors.xsd @@ -0,0 +1,87 @@ + + + + + + + + + + Complex type definitions for a graphml postprocessor. +

Postprocessors are executed after the graph has been loaded.

+
+
+ + + + + Type definitions for the options for a graphml postprocessor. +

These options are the same as for xml serialized YModules.

+
+
+ + + + + The name of the option. + + + + + + + The value of the option. + + + + +
+
+ + + + The class of the postprocessor. +

This must resolve to a subclass of y.option.yModule

+
+
+
+
+ + + + + + Complex type definitions for a list of graphml postprocessors. + + + + + + + Postprocessor element definition. + + + + + + + + + + + Postprocessors element definition. + + + + +
diff --git a/XmlSchemaClassGenerator/ModelBuilder.cs b/XmlSchemaClassGenerator/ModelBuilder.cs index 5f8776ff..911a2228 100644 --- a/XmlSchemaClassGenerator/ModelBuilder.cs +++ b/XmlSchemaClassGenerator/ModelBuilder.cs @@ -12,8 +12,8 @@ internal class ModelBuilder { private readonly GeneratorConfiguration _configuration; private readonly XmlSchemaSet _set; - private readonly Dictionary AttributeGroups; - private readonly Dictionary Groups; + private readonly Dictionary> AttributeGroups = new(); + private readonly Dictionary> Groups = new(); private readonly Dictionary Namespaces = new(); private readonly Dictionary Types = new(); private readonly Dictionary> SubstitutionGroups = new(); @@ -44,18 +44,40 @@ public ModelBuilder(GeneratorConfiguration configuration, XmlSchemaSet set) SetType(new XmlSchemaComplexType(), AnyType, objectModel); - AttributeGroups = set.Schemas().Cast().SelectMany(s => s.AttributeGroups.Values.Cast()) - .DistinctBy(g => g.QualifiedName.ToString()) - .ToDictionary(g => g.QualifiedName); - Groups = set.Schemas().Cast().SelectMany(s => s.Groups.Values.Cast()) - .DistinctBy(g => g.QualifiedName.ToString()) - .ToDictionary(g => g.QualifiedName); - var dependencyOrder = new List(); var seenSchemas = new HashSet(); foreach (var schema in set.Schemas().Cast()) ResolveDependencies(schema, dependencyOrder, seenSchemas); + foreach (var schema in dependencyOrder) + { + var currentAttributeGroups = schema.AttributeGroups.Values.Cast() + .DistinctBy(g => g.QualifiedName.ToString()); + + foreach (var currentAttributeGroup in currentAttributeGroups) + { + if (!AttributeGroups.ContainsKey(currentAttributeGroup.QualifiedName)) + { + AttributeGroups.Add(currentAttributeGroup.QualifiedName, new HashSet()); + } + + AttributeGroups[currentAttributeGroup.QualifiedName].Add(currentAttributeGroup); + } + + var currentSchemaGroups = schema.Groups.Values.Cast() + .DistinctBy(g => g.QualifiedName.ToString()); + + foreach (var currentSchemaGroup in currentSchemaGroups) + { + if (!Groups.ContainsKey(currentSchemaGroup.QualifiedName)) + { + Groups.Add(currentSchemaGroup.QualifiedName, new HashSet()); + } + + Groups[currentSchemaGroup.QualifiedName].Add(currentSchemaGroup); + } + } + foreach (var schema in dependencyOrder) { foreach (var globalType in set.GlobalTypes.Values.Cast().Where(s => s.GetSchema() == schema)) @@ -769,14 +791,14 @@ private SimpleModel CreateSimpleModel(XmlSchemaSimpleType simpleType, List items) { var interfaces = items.Select(i => i.XmlParticle).OfType() - .Select(i => (InterfaceModel)builder.CreateTypeModel(i.RefName, builder.Groups[i.RefName])); + .Select(i => (InterfaceModel)builder.CreateTypeModel(i.RefName, builder.Groups[i.RefName].First())); refTypeModel.AddInterfaces(interfaces); } private void AddInterfaces(ReferenceTypeModel refTypeModel, XmlSchemaObjectCollection attributes) { var interfaces = attributes.OfType() - .Select(a => (InterfaceModel)builder.CreateTypeModel(a.RefName, builder.AttributeGroups[a.RefName])); + .Select(a => (InterfaceModel)builder.CreateTypeModel(a.RefName, builder.AttributeGroups[a.RefName].First())); refTypeModel.AddInterfaces(interfaces); } } @@ -790,31 +812,43 @@ private IEnumerable CreatePropertiesForAttributes(Uri source, Typ switch (item) { case XmlSchemaAttribute attribute when attribute.Use != XmlSchemaUse.Prohibited: + properties.Add(PropertyFromAttribute(owningTypeModel, attribute)); break; - case XmlSchemaAttributeGroupRef attributeGroupRef: - if (_configuration.GenerateInterfaces) - CreateTypeModel(attributeGroupRef.RefName, AttributeGroups[attributeGroupRef.RefName]); - var attributeGroup = AttributeGroups[attributeGroupRef.RefName]; - var attributes = attributeGroup.Attributes.Cast() - .Where(a => !(a is XmlSchemaAttributeGroupRef agr && agr.RefName == attributeGroupRef.RefName)) - .ToList(); + case XmlSchemaAttributeGroupRef attributeGroupRef: - if (attributeGroup.RedefinedAttributeGroup != null) + foreach (var attributeGroup in AttributeGroups[attributeGroupRef.RefName]) { - foreach (var attr in attributeGroup.RedefinedAttributeGroup.Attributes.Cast()) + if (_configuration.GenerateInterfaces) + CreateTypeModel(attributeGroupRef.RefName, attributeGroup); + + var attributes = attributeGroup.Attributes.Cast() + .Where(a => !(a is XmlSchemaAttributeGroupRef agr && agr.RefName == attributeGroupRef.RefName)) + .ToList(); + + if (attributeGroup.RedefinedAttributeGroup != null) { - var n = attr.GetQualifiedName(); + var attrs = attributeGroup.RedefinedAttributeGroup.Attributes.Cast() + .Where(a => !(a is XmlSchemaAttributeGroupRef agr && agr.RefName == attributeGroupRef.RefName)).ToList(); - if (n != null) - attributes.RemoveAll(a => a.GetQualifiedName() == n); + if (attrs.Any(a => (a is XmlSchemaAttributeGroupRef agr && agr.RefName == attributeGroupRef.RefName))) { } - attributes.Add(attr); + foreach (var attr in attrs) + { + var n = attr.GetQualifiedName(); + + if (n != null) + attributes.RemoveAll(a => a.GetQualifiedName() == n); + + attributes.Add(attr); + } } + + var newProperties = CreatePropertiesForAttributes(source, owningTypeModel, attributes); + properties.AddRange(newProperties); } - properties.AddRange(CreatePropertiesForAttributes(source, owningTypeModel, attributes)); break; } } @@ -901,7 +935,7 @@ private IEnumerable CreatePropertiesForElements(Uri source, TypeM var group = Groups[groupRef.RefName]; if (_configuration.GenerateInterfaces) - CreateTypeModel(groupRef.RefName, group); + CreateTypeModel(groupRef.RefName, group.First()); var groupItems = GetElements(groupRef.Particle).ToList(); var groupProperties = CreatePropertiesForElements(source, owningTypeModel, item, groupItems, order: order).ToList(); diff --git a/XmlSchemaClassGenerator/TypeModel.cs b/XmlSchemaClassGenerator/TypeModel.cs index 659a88aa..cfbae63d 100644 --- a/XmlSchemaClassGenerator/TypeModel.cs +++ b/XmlSchemaClassGenerator/TypeModel.cs @@ -91,7 +91,8 @@ public virtual CodeTypeDeclaration Generate() protected void GenerateTypeAttribute(CodeTypeDeclaration typeDeclaration) { - if (XmlSchemaName == null) return; + if (XmlSchemaName == null + || (this is ClassModel cm && cm.IsRedefined)) return; var typeAttribute = AttributeDecl( new(new CodePrimitiveExpression(XmlSchemaName.Name)), @@ -210,6 +211,7 @@ public IEnumerable AllDerivedReferenceTypes(List DerivedTypes.Any(d => d.XmlSchemaType?.Parent is XmlSchemaRedefine); public bool IsAbstract { get; set; } public bool IsMixed { get; set; } public bool IsSubstitution { get; set; }