Ejercicio 424
Elabora un documento XSD que permita validar la estructura del siguiente documento XML:
<svg version="1.1" width="500" height="400">
<rect x="25" y="10" width="200" height="100" fill="orange" stroke="blue" stroke-width="3" />
<rect x="225" y="25" width="50" height="85" fill="blue" stroke="red" stroke-width="8" />
<circle cx="70" cy="110" r="25" fill="green" stroke="red"/>
<circle cx="220" cy="110" r="25" fill="green" stroke="red"/>
<path fill="pink" d="M 316 9 L 396 9 L 359 46 L 359 94 C 359 94 357 100 384 102
L 384 103 L 331 103 L 331 102 C 356 100 354 94 354 94
L 354 46 L 316 9 z " />
<line stroke="green" stroke-width="8" x1="25" y1="150" x2="400" y2="150" />
<polyline fill="red" points="20, 250 85, 350 120, 350" />
<polygon fill="green" points="250,250 297, 284 279,340 220, 340 202, 284" />
<ellipse fill="blue" cx="400" cy="300" rx="72" ry="50"/>
</svg>
Solución
XML
<svg version="1.1" width="500" height="400"
xmlns:xs="http://www.w3.org/2001/XMLSchema-instance"
xs:noNamespaceSchemaLocation="424.xsd">
<rect x="25" y="10" width="200" height="100" fill="orange" stroke="blue" stroke-width="3" />
<rect x="225" y="25" width="50" height="85" fill="blue" stroke="red" stroke-width="8" />
<circle cx="70" cy="110" r="25" fill="green" stroke="red"/>
<circle cx="220" cy="110" r="25" fill="green" stroke="red"/>
<path fill="pink" d="M 316 9 L 396 9 L 359 46 L 359 94 C 359 94 357 100 384 102
L 384 103 L 331 103 L 331 102 C 356 100 354 94 354 94
L 354 46 L 316 9 z " />
<line stroke="green" stroke-width="8" x1="25" y1="150" x2="400" y2="150" />
<polyline fill="red" points="20, 250 85, 350 120, 350" />
<polygon fill="green" points="250,250 297, 284 279,340 220, 340 202, 284" />
<ellipse fill="blue" cx="400" cy="300" rx="72" ry="50"/>
</svg>
424.xsd
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<xsd:element name="svg" type="tipoSvg" />
<xsd:complexType name="tipoSvg">
<xsd:sequence>
<xs:choice minOccurs="0" maxOccurs="unbounded">
<xsd:element name="rect" type="tipoRect"/>
<xsd:element name="circle" type="tipoCircle"/>
<xsd:element name="path" type="tipoPath"/>
<xsd:element name="line" type="tipoLine"/>
<xsd:element name="polyline" type="tipoPoly"/>
<xsd:element name="polygon" type="tipoPoly" />
<xsd:element name="ellipse" type="tipoEllipse"/>
</xs:choice>
</xsd:sequence>
<xsd:attribute name="version" type="xsd:string" />
<xsd:attributeGroup ref="grupoWH" />
</xsd:complexType>
<xsd:complexType name="tipoRect">
<xsd:attributeGroup ref="grupoXY" />
<xsd:attributeGroup ref="grupoWH" />
<xsd:attributeGroup ref="grupoFill" />
<xsd:attributeGroup ref="grupoStrokeS" />
</xsd:complexType>
<xsd:complexType name="tipoCircle">
<xsd:attributeGroup ref="grupoCXCY" />
<xsd:attribute name="r" type="xsd:string" />
<xsd:attributeGroup ref="grupoFill" />
<xsd:attributeGroup ref="grupoStroke" />
</xsd:complexType>
<xsd:complexType name="tipoPath">
<xsd:attributeGroup ref="grupoFill" />
<xsd:attribute name="d" type="xsd:string" />
</xsd:complexType>
<xsd:complexType name="tipoLine">
<xsd:attributeGroup ref="grupoStrokeS" />
<xsd:attribute name="x1" type="xsd:string" />
<xsd:attribute name="x2" type="xsd:string" />
<xsd:attribute name="y1" type="xsd:string" />
<xsd:attribute name="y2" type="xsd:string" />
</xsd:complexType>
<xsd:complexType name="tipoPoly">
<xsd:attributeGroup ref="grupoFill" />
<xsd:attribute name="points" type="xsd:string" />
</xsd:complexType>
<xsd:complexType name="tipoEllipse">
<xsd:attributeGroup ref="grupoFill" />
<xsd:attribute name="cx" type="xsd:string" />
<xsd:attribute name="cy" type="xsd:string" />
<xsd:attribute name="rx" type="xsd:string" />
<xsd:attribute name="ry" type="xsd:string" />
</xsd:complexType>
<xsd:attributeGroup name="grupoWH">
<xsd:attribute name="width" type="xsd:string" />
<xsd:attribute name="height" type="xsd:string" />
</xsd:attributeGroup>
<xsd:attributeGroup name="grupoXY">
<xsd:attribute name="x" type="xsd:string" />
<xsd:attribute name="y" type="xsd:string" />
</xsd:attributeGroup>
<xsd:attributeGroup name="grupoFill">
<xsd:attribute name="fill" type="xsd:string" />
</xsd:attributeGroup>
<xsd:attributeGroup name="grupoCXCY">
<xsd:attribute name="cx" type="xsd:string" />
<xsd:attribute name="cy" type="xsd:string" />
</xsd:attributeGroup>
<xsd:attributeGroup name="grupoStroke">
<xsd:attribute name="stroke" type="xsd:string" />
</xsd:attributeGroup>
<xsd:attributeGroup name="grupoStrokeS">
<xsd:attributeGroup ref="grupoStroke" />
<xsd:attribute name="stroke-width" type="xsd:string" />
</xsd:attributeGroup>
</xsd:schema>