Note that there are some explanatory texts on larger screens.

plurals
  1. POTraceability with XSD
    primarykey
    data
    text
    <p>I am trying to let my XML schema handle a little traceability functionality as I'm gathering requirements while I read through some functional specifications. (Not ideal for requirement management, but at least its a start.)</p> <p>What I'm doing is creating a &lt;<em>functionalSpec></em> tag for each functional specification I am currently reading through. I create a &lt;<em>requirement></em> tag for each requirement I find. Since I want to be able to trace where the requirement came from, I create a &lt;<em>trace></em> element with the <em>id</em> of the &lt;<em>functionalSpec></em> element. Instead of allowing myself to enter any plain-old-text in the &lt;<em>functionalSpecId></em> tag, I want the XSD to validate and make sure that I only enter in an <em>id</em> that exists for an existing functional spec. My problem is coming in where it seems the <a href="http://www.w3.org/TR/xmlschema-1/" rel="nofollow noreferrer">XML Schema W3C Recommendations</a> documentation says that what I want to do is not possible. (about 1/2 way down)</p> <blockquote> <p>{selector} specifies a restricted XPath ([XPath]) expression <strong>relative to instances of the element being declared</strong>. This must identify a node set of subordinate elements (i.e. contained within the declared element) to which the constraint applies.</p> </blockquote> <p>I'm using Oxygen to create this since I'm fairly new to XSD files, and it gives me the following error:</p> <blockquote> <p>E [Xerces] Identity Constraint error: identity constraint "KeyRef@1045a2" has a keyref which refers to a key or unique that is out of scope.</p> </blockquote> <p>So my question is does anyone know of a way that will allow me to use the same XML structure that I have below through using XSD?</p> <p><strong>Below is the XML file.</strong></p> <pre><code>&lt;?xml version="1.0" encoding="UTF-8" ?&gt; &lt;srs xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="srs req2.xsd" xmlns="srs"&gt; &lt;requirements&gt; &lt;requirement DateCreated="2010-06-11" id="1"&gt; &lt;Text&gt;The system shall...&lt;/Text&gt; &lt;trace&gt; &lt;functionalSpecId&gt;B010134&lt;/functionalSpecId&gt; &lt;/trace&gt; &lt;revisions&gt; &lt;revision date="2010-06-11" num="0"&gt; &lt;description&gt;Initial creation.&lt;/description&gt; &lt;/revision&gt; &lt;/revisions&gt; &lt;/requirement&gt; &lt;/requirements&gt; &lt;functionalSpecs&gt; &lt;functionalSpec id="B010134" model="Model-T"&gt; &lt;trace&gt; &lt;meeting&gt;&lt;/meeting&gt; &lt;/trace&gt; &lt;revisions&gt; &lt;revision date="2009-07-08" num="0"&gt; &lt;description&gt;Initial creation.&lt;/description&gt; &lt;/revision&gt; &lt;detailer&gt;Me&lt;/detailer&gt; &lt;engineer&gt;Me&lt;/engineer&gt; &lt;/revisions&gt; &lt;/functionalSpec&gt; &lt;/functionalSpecs&gt; &lt;/srs&gt; </code></pre> <p><strong>Below is the XSD file.</strong></p> <pre><code>&lt;?xml version="1.0" encoding="UTF-8" ?&gt; &lt;xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" targetNamespace="srs" xmlns="srs" xmlns:srs="srs" elementFormDefault="qualified"&gt; &lt;!-- SRS --&gt; &lt;xs:element name="srs" type="SRSType"&gt; &lt;/xs:element&gt; &lt;xs:complexType name="SRSType"&gt; &lt;xs:sequence&gt; &lt;xs:element ref="requirements" /&gt; &lt;xs:element ref="functionalSpecs" /&gt; &lt;/xs:sequence&gt; &lt;/xs:complexType&gt; &lt;!-- Requirements --&gt; &lt;xs:element name="requirements" type="RequirementsType"&gt; &lt;xs:unique name="requirementId"&gt; &lt;xs:selector xpath="srs/requirements/requirement" /&gt; &lt;xs:field xpath="@id" /&gt; &lt;/xs:unique&gt; &lt;/xs:element&gt; &lt;xs:complexType name="RequirementsType"&gt; &lt;xs:choice maxOccurs="unbounded"&gt; &lt;xs:element name="requirement" type="RequirementType" /&gt; &lt;/xs:choice&gt; &lt;/xs:complexType&gt; &lt;xs:complexType name="RequirementType"&gt; &lt;xs:complexContent&gt; &lt;xs:extension base="RequirementInfo"&gt; &lt;xs:sequence&gt; &lt;xs:element name="trace" type="TraceType" maxOccurs="unbounded" minOccurs="1" /&gt; &lt;xs:element name="revisions" type="RequirementRevisions" /&gt; &lt;/xs:sequence&gt; &lt;/xs:extension&gt; &lt;/xs:complexContent&gt; &lt;/xs:complexType&gt; &lt;xs:complexType name="RequirementRevisions"&gt; &lt;xs:sequence&gt; &lt;xs:element name="revision" type="RevisionInfo" minOccurs="1" maxOccurs="unbounded" /&gt; &lt;/xs:sequence&gt; &lt;/xs:complexType&gt; &lt;xs:complexType name="RequirementInfo"&gt; &lt;xs:sequence&gt; &lt;xs:element name="Text" type="Description" /&gt; &lt;/xs:sequence&gt; &lt;xs:attribute name="DateCreated" type="xs:date" use="required" /&gt; &lt;xs:attribute name="id" type="xs:integer" use="required" /&gt; &lt;/xs:complexType&gt; &lt;!-- Functional Specs --&gt; &lt;xs:element name="functionalSpecs" type="FunctionalSpecsType"&gt; &lt;xs:unique name="functionalSpecId"&gt; &lt;xs:selector xpath="srs/functionalSpecs/functionalSpec" /&gt; &lt;xs:field xpath="@id" /&gt; &lt;/xs:unique&gt; &lt;/xs:element&gt; &lt;xs:complexType name="FunctionalSpecsType"&gt; &lt;xs:choice maxOccurs="unbounded"&gt; &lt;xs:element name="functionalSpec" type="FunctionalSpecType" /&gt; &lt;/xs:choice&gt; &lt;/xs:complexType&gt; &lt;xs:complexType name="FunctionalSpecType"&gt; &lt;xs:complexContent&gt; &lt;xs:extension base="FunctionalSpecInfo"&gt; &lt;xs:sequence&gt; &lt;xs:element name="trace" type="TraceType" maxOccurs="unbounded" minOccurs="1" /&gt; &lt;xs:element name="revisions" type="FunctionalSpecRevisions" /&gt; &lt;/xs:sequence&gt; &lt;/xs:extension&gt; &lt;/xs:complexContent&gt; &lt;/xs:complexType&gt; &lt;xs:complexType name="FunctionalSpecRevisions"&gt; &lt;xs:sequence&gt; &lt;xs:element name="revision" type="RevisionInfo" minOccurs="1" maxOccurs="unbounded" /&gt; &lt;xs:element name="detailer" type="xs:string" /&gt; &lt;xs:element name="engineer" type="xs:string" /&gt; &lt;/xs:sequence&gt; &lt;/xs:complexType&gt; &lt;xs:complexType name="FunctionalSpecInfo"&gt; &lt;xs:attribute name="id" type="xs:string" use="required" /&gt; &lt;xs:attribute name="model" type="xs:string" use="required" /&gt; &lt;/xs:complexType&gt; &lt;!-- Requirements, Functional Specs --&gt; &lt;xs:complexType name="TraceType"&gt; &lt;xs:choice&gt; &lt;xs:element name="requirementId"&gt; &lt;xs:keyref refer="requirementId" name="requirementIdRef"&gt; &lt;xs:selector xpath="srs/requirements/requirement" /&gt; &lt;xs:field xpath="@id" /&gt; &lt;/xs:keyref&gt; &lt;/xs:element&gt; &lt;xs:element name="functionalSpecId"&gt; &lt;xs:keyref refer="functionalSpecId" name="functionalSpecIdRef"&gt; &lt;xs:selector xpath="srs/functionalSpecs/functionalSpec" /&gt; &lt;xs:field xpath="@id" /&gt; &lt;/xs:keyref&gt; &lt;/xs:element&gt; &lt;xs:element name="meeting" /&gt; &lt;/xs:choice&gt; &lt;/xs:complexType&gt; &lt;!-- Common --&gt; &lt;xs:complexType name="RevisionInfo"&gt; &lt;xs:choice&gt; &lt;xs:element name="description" type="Description" /&gt; &lt;/xs:choice&gt; &lt;xs:attribute name="date" type="xs:date" use="required" /&gt; &lt;xs:attribute name="num" type="xs:integer" use="required" /&gt; &lt;/xs:complexType&gt; &lt;xs:complexType name="Description" mixed="true"&gt; &lt;xs:simpleContent&gt; &lt;xs:extension base="xs:string"&gt; &lt;xs:attribute name="Date" type="xs:date" /&gt; &lt;/xs:extension&gt; &lt;/xs:simpleContent&gt; &lt;/xs:complexType&gt; &lt;/xs:schema&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload