I have this xsd
<xs:complexType name="ShapeLine">
<xs:annotation>
<xs:documentation>
ShapeLine - the line between two shapes
</xs:documentation>
</xs:annotation>
<xs:complexContent>
<xs:extension base="archimate:Line" >
<xs:attribute name="category" type="xs:string" use="required">
</xs:attribute>
<xs:attribute name="source" type="xs:IDREF" use="required" />
<xs:attribute name="target" type="xs:IDREF" use="required" />
</xs:extension>
</xs:complexContent>
</xs:complexType>
<xs:complexType name="Shape">
<xs:annotation>
<xs:documentation>
Shape object
</xs:documentation>
</xs:annotation>
<xs:complexContent>
<xs:extension base="archimate:ViewNodeType" >
<xs:attribute name="shapeId" type="xs:string" use="required">
<xs:annotation>
<xs:documentation>
shapeId contains the id of the shape
</xs:documentation>
</xs:annotation>
</xs:attribute>
<xs:attribute name="name_internal" type="xs:string" use="required">
<xs:annotation>
<xs:documentation>
name_internal contains the name_internal of the shape
</xs:documentation>
</xs:annotation>
</xs:attribute>
</xs:extension>
</xs:complexContent>
</xs:complexType>
and this is the xml that I need to validate:
<views>
<diagrams>
<view identifier="id-7b98c8ec-243a-49fb-b6b0-baa68c95badb">
<name xml:lang="EN">helloe</name>
<node xsi:type="q1:Shape" identifier="id-1d599237-
76af-4fc7-8d9a-c4356c3b2137" x="10" y="30" w="1" h="1" name_internal="BD_shapes_av_Box"
shapeId="5da9cedd0c0ba649f8cae72e" angle="0" isgroup="False" alignment="" textalign="0" size="72 72">
</node>
<node xsi:type="q2:Shape" identifier="id-76efea7a-6cf3-4cf0-bbd4-e36597c0653b" x="454" y="54" w="1" h="1" name_internal="BD_shapes_av_Two sided arrow" shapeId="5dad549f0c0ba639c4a5a3ac" angle="0" isgroup="False" alignment="" textalign="0" size="72 30,476">
</node>
<connection xsi:type="q3:ShapeLine" identifier="id-4ab26cbf-509b-4657-b066-1a676a2773eb" source="id-1d599237-76af-4fc7-8d9a-c4356c3b2137" target="id-76efea7a-6cf3-4cf0-bbd4-e36597c0653b" category="line_dottednoarrows">
<sourceAttachment x="82" y="66" />
<targetAttachment x="454" y="69" />
</connection>
</view>
</diagrams>
I need to create an xsd validation in order that a ShapeLine to be allowed only between objects of type Shape. Can be this achievable in xsd? I'm quite new to xsd-s, so any help is appreciated.
I'm not really sure that I understood the question correct. I think I'm missing required information. You are asking to create an xml schema definition that validates the xml to make sure that elements of the type shape can have child element of the type shapeline. But looking at the example xml the element of the type shapeline is a sibling of the elements of the type shape. And the q1:Shape en q2:Shape gives me the idea that there are 2 Shape types with a different namespace or the q1 and q2 namespace prefix is pointing to the same actual namespace.
Types must be assigned to elements or attributes and those elements and attributes are creating the layout of the message. you cannot create an xsd using only types to describe an xml message. you need to assign the types to elements and or attributes. The order and the structure you create with those elements and attributes will determine how the xml message will look like.
the below xml example does have both options in it. First the sibling child and then the sibling sibling
This example xml is generated from the below xsd.
This is a very simplified version of what you want to achieve, but hopefully it will help you to get started.