...">

Xsd Multiplies Multiple Use Attribute

I am not sure how to deduct this XSD fragment:

<xs:attribute name="status" use="required"> <xs:simpleType> <xs:restriction base="xs:token"> <xs:enumeration value="not run"/> <xs:enumeration value="passed"/> <xs:enumeration value="failed"/> </xs:restriction> </xs:simpleType> </xs:attribute> 

which is necessary for the tags <test> and <step> :

 <?xml version="1.0" encoding="UTF-16"?> <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" targetNamespace="FlowBi:Emis:FeatureTests" xmlns="FlowBi:Emis:FeatureTests" elementFormDefault="qualified" attributeFormDefault="unqualified"> <xs:element name="featureTests"> <xs:complexType> <xs:sequence> <xs:element name="test" minOccurs="1" maxOccurs="unbounded"> <xs:complexType> <xs:sequence> <xs:element name="summary" type="xs:string"/> <xs:sequence> <xs:element name="step" minOccurs="0" maxOccurs="unbounded"> <xs:complexType> <xs:simpleContent> <xs:extension base="xs:string"> <xs:attribute name="status" use="required"> <xs:simpleType> <xs:restriction base="xs:token"> <xs:enumeration value="not run"/> <xs:enumeration value="passed"/> <xs:enumeration value="failed"/> </xs:restriction> </xs:simpleType> </xs:attribute> </xs:extension> </xs:simpleContent> </xs:complexType> </xs:element> </xs:sequence> </xs:sequence> <xs:attribute name="status" use="required"> <xs:simpleType> <xs:restriction base="xs:token"> <xs:enumeration value="not run"/> <xs:enumeration value="passed"/> <xs:enumeration value="failed"/> </xs:restriction> </xs:simpleType> </xs:attribute> </xs:complexType> </xs:element> </xs:sequence> </xs:complexType> </xs:element> </xs:schema> 

It would be nice to split up a repeating section and just reference it in every place where it is used, but I'm not sure how to do this for attribute types.

+1
source share
2 answers

It should do it

 <?xml version="1.0" encoding="utf-16"?> <!--Created with Liquid XML Studio 2012 Developer Edition 10.1.2.4113 (http://www.liquid-technologies.com)--> <xs:schema xmlns="FlowBi:Emis:FeatureTests" attributeFormDefault="unqualified" elementFormDefault="qualified" targetNamespace="FlowBi:Emis:FeatureTests" xmlns:xs="http://www.w3.org/2001/XMLSchema"> <xs:element name="featureTests"> <xs:complexType> <xs:sequence> <xs:element name="test" minOccurs="1" maxOccurs="unbounded"> <xs:complexType> <xs:sequence> <xs:element name="summary" type="xs:string" /> <xs:sequence> <xs:element name="step" minOccurs="0" maxOccurs="unbounded"> <xs:complexType> <xs:simpleContent> <xs:extension base="xs:string"> <xs:attribute name="status" type="statusType" use="required" /> </xs:extension> </xs:simpleContent> </xs:complexType> </xs:element> </xs:sequence> </xs:sequence> <xs:attribute name="status" type="statusType" use="required" /> </xs:complexType> </xs:element> </xs:sequence> </xs:complexType> </xs:element> <xs:simpleType name="statusType"> <xs:restriction base="xs:token"> <xs:enumeration value="not run" /> <xs:enumeration value="passed" /> <xs:enumeration value="failed" /> </xs:restriction> </xs:simpleType> </xs:schema> 
+2
source

The answer provided by @Sprotty is correct (+1). I would add refinements / options that do not fit into the comments (hence the answer) ...

Typically, the reason that only a simple type has been reused by Sprotty is because attributes are usually not qualified in XSD. Since the attributes are unqualified in your example, reusing the entire attribute is only possible if the attribute is enclosed in an attribute group. Basically, reusing an attribute defined globally means qualifying the attribute.

So, this is another opportunity to reuse an attribute declaration (as opposed to a simple type):

 <?xml version="1.0" encoding="UTF-16"?> <!--XML Schema generated by QTAssistant/XML Schema Refactoring (XSR) Module (http://www.paschidev.com)--> <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" targetNamespace="FlowBi:Emis:FeatureTests" xmlns="FlowBi:Emis:FeatureTests" elementFormDefault="qualified" attributeFormDefault="unqualified"> <xs:element name="featureTests"> <xs:complexType> <xs:sequence> <xs:element name="test" minOccurs="1" maxOccurs="unbounded"> <xs:complexType> <xs:sequence> <xs:element name="summary" type="xs:string"/> <xs:sequence> <xs:element name="step" minOccurs="0" maxOccurs="unbounded"> <xs:complexType> <xs:simpleContent> <xs:extension base="xs:string"> <xs:attributeGroup ref="gaStatus" /> </xs:extension> </xs:simpleContent> </xs:complexType> </xs:element> </xs:sequence> </xs:sequence> <xs:attributeGroup ref="gaStatus" /> </xs:complexType> </xs:element> </xs:sequence> </xs:complexType> </xs:element> <xs:attributeGroup name="gaStatus"> <xs:attribute name="status" use="required"> <xs:simpleType> <xs:restriction base="xs:token"> <xs:enumeration value="not run"/> <xs:enumeration value="passed"/> <xs:enumeration value="failed"/> </xs:restriction> </xs:simpleType> </xs:attribute> </xs:attributeGroup> </xs:schema> 
+1
source

Source: https://habr.com/ru/post/1391575/


All Articles