I'm working on an Autocomplete NPP file for the DOORS dxl language. There is about 1500 keywords and during editing typos are created that are hard to find. There is no Schema xsd file for the autocomplete xml file tag layout. So I am writing my first one and am hoping that it will pinpoint it to the line causing the problem. The NPP xml tools pluggin says the structure is correct, but tags could be missing. Setting enable auto-validation in the tool can find errors but points one in the wrong area of a big xml file. Hopefully the XSD will narrow it down further.
My Autocomplete xsd validation is having problem using online xsd tester sites. It says the "ref" for autocomplete attribute is wrong and the the sequence is wrong. I think I can use multiple sequence attributes to force xml tag ordering. I don't know what the real issue is since if I delete all sequences it starts complaining about the elements and the more I delete, it doesn't fix it so I can start working backwards and add things back in.
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
id="NPP-XSD-1"
elementFormDefault="qualified"
attributeFormDefault="qualified"
>
<!-- targetNamespace="C:\Users\tester\Documents\DOORS_RPE_Library\DOORS_DXL_Examples\NotePPlus_DXL_tool" -->
<!-- xmlns="C:\Users\tester\Documents\DOORS_RPE_Library\DOORS_DXL_Examples\NotePPlus_DXL_tool" -->
<!-- Purpose: XML Schema for Note Pad Plus Autocomple validation. -->
<!-- Initialization of XML Schema statements for use in the main XML Schema body that follows -->
<!-- Note: AttributesGroups provides a mechanism to group a set of attribute declarations so that
they can be incorporated as a group into complex type definitions.
An attribute group can be defined only as a child of the schema element.
In this case, the name attribute must be present and contain the attribute, attributeGroup,
or anyAttribute elements that make up the attribute group.
When a complexType or an attributeGroup element includes an attribute group, the ref attribute
must be present and the name attribute is not allowed.
An attribute group reference can be defined only as a child of the attributeGroup or complexType element.
In this case, the ref attribute must be present and contain the name of the referenced attribute group.
XML ID value can't be a number,and is a string. Used to uniquely identifier an XML element
The TargetNamespace is the namespace of all schema components in this schema as well as any schema included
using the include element.
-->
<!-- Define Group attributes -->
<xs:attributeGroup name="environmentgroupAttr" id="G_attr-1">
<xs:attribute name="ignoreCase">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:pattern value="yes|no"/>
</xs:restriction>
</xs:simpleType>
</xs:attribute>
<xs:attribute name="startFunc" type="xs:string"/>
<xs:attribute name="stopFunc" type="xs:string"/>
<xs:attribute name="paramSeparator" type="xs:string"/>
<xs:attribute name="terminal" type="xs:string"/>
</xs:attributeGroup>
<xs:attributeGroup name="keywordgroupAttr" id="G_attr-2">
<xs:attribute name="name" type="xs:string"/>
<xs:attribute name="func">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:pattern value="yes|no"/>
</xs:restriction>
</xs:simpleType>
</xs:attribute>
</xs:attributeGroup>
<xs:attributeGroup name="overloadgroupAttr" id="G_attr-3">
<xs:attribute name="retVal" type="xs:string"/>
<xs:attribute name="descr" type="xs:string"/>
</xs:attributeGroup>
<!-- Define ComplexTypes based on Group Attributes -->
<xs:complexType name="autocompleteType" mixed="false" id="C_type-1">
<xs:attribute name="language" type="xs:string"/>
</xs:complexType>
<xs:complexType name="environmentType" mixed="false" id="C_type-2">
<xs:attributeGroup ref="environmentgroupAttr"/>
</xs:complexType>
<xs:complexType name="keywordType" mixed="false" id="C_type-3">
<xs:attributeGroup ref="keywordgroupAttr"/>
</xs:complexType>
<xs:complexType name="overloadType" mixed="false" id="C_type-4">
<xs:attributeGroup ref="overloadgroupAttr"/>
</xs:complexType>
<xs:complexType name="paramType" mixed="false" id="C_type-5">
<xs:attribute name="name" type="xs:string"/>
</xs:complexType>
<!-- Define Autocomple elements -->
<xs:element name="AutoComplete" type="autocompleteType"/>
<xs:element name="Environment" type="environmentType"/>
<xs:element name="KeyWord" type="keywordType"/>
<xs:element name="Overload" type="overloadType"/>
<xs:element name="Param" type="paramType"/>
<!-- XML Autocomplete Message structure (group) based on earlier defined structures. -->
<xs:group name="Autocomplete_msg_struct">
<!-- 1st level -->
<xs:sequence>
<xs:element ref="AutoComplete" minOccurs="1" maxOccurs="1">
<!-- 2nd level -->
<xs:sequence>
<xs:element ref="Environment" minOccurs="1" maxOccurs="1"/>
<!-- 3rd level -->
<xs:sequence>
<xs:element ref="KeyWord" minOccurs="1" maxOccurs="unbounded">
<xs:element ref="Overload" minOccurs="1" maxOccurs="unbounded">
<xs:element ref="Param" minOccurs="0" maxOccurs="unbounded"/>
</xs:element><!-- Overload tag -->
</xs:element><!-- KeyWord tag -->
</xs:sequence><!-- 3rd level -->
</xs:sequence><!-- 2nd level -->
</xs:element><!-- AutoComplete tag -->
</xs:sequence><!-- 1st level -->
</xs:group>
<!-- Main AutoComplete XML message structure for NPP -->
<xs:element name="NotepadPlus">
<xs:complexType mixed="false">
<xs:group ref="Autocomplete_msg_struct"/>
</xs:complexType>
</xs:element>
</xs:schema>
After the Main comment I've replaced the elements to get the NotepadPlus tag to be processed correctly.
<xs:complexType name="NotepadPlus_struct" mixed="true">
<xs:group ref="Autocomplete_msg_struct" minOccurs="1" maxOccurs="1"/>
</xs:complexType>
<xs:element name="NotepadPlus" type="NotepadPlus_struct"/>
CodePudding user response:
In the Autocomplete_msg_struct group, you can't reference an element, using the ref
attribute (<xs:element ref="AutoComplete" />
) and then include a content model (sequence, choice, all). It's one or the other.
What you can do is create a new element, also called AutoComplete
(this is local to your group definition i.e. it's not global, so it won't conflict), then create an inline complexType that extends the autoCompleteType, and includes your '2nd level' sequence content model there:
<xs:group name="Autocomplete_msg_struct">
<!-- 1st level -->
<xs:sequence>
<!-- AutoComplete tag, note there's no 'ref' attribute here -->
<xs:element name="AutoComplete">
<xs:complexType mixed="true">
<xs:complexContent>
<xs:extension base="autocompleteType">
<!-- 2nd level -->
<xs:sequence>
<!-- Left out for brevity -->
</xs:sequence><!-- 2nd level -->
</xs:extension>
</xs:complexContent>
</xs:complexType>
</xs:element>
</xs:sequence>
<!-- 1st level -->
</xs:group>