views:

86

answers:

0

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.)

What I'm doing is creating a <functionalSpec> tag for each functional specification I am currently reading through. I create a <requirement> tag for each requirement I find. Since I want to be able to trace where the requirement came from, I create a <trace> element with the id of the <functionalSpec> element. Instead of allowing myself to enter any plain-old-text in the <functionalSpecId> tag, I want the XSD to validate and make sure that I only enter in an id that exists for an existing functional spec. My problem is coming in where it seems the XML Schema W3C Recommendations documentation says that what I want to do is not possible. (about 1/2 way down)

{selector} specifies a restricted XPath ([XPath]) expression relative to instances of the element being declared. This must identify a node set of subordinate elements (i.e. contained within the declared element) to which the constraint applies.

I'm using Oxygen to create this since I'm fairly new to XSD files, and it gives me the following error:

E [Xerces] Identity Constraint error: identity constraint "KeyRef@1045a2" has a keyref which refers to a key or unique that is out of scope.

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?

Below is the XML file.

<?xml version="1.0" encoding="UTF-8" ?>

<srs xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="srs req2.xsd"
    xmlns="srs">

<requirements>

<requirement DateCreated="2010-06-11" id="1">
    <Text>The system shall...</Text>
    <trace>
        <functionalSpecId>B010134</functionalSpecId>
    </trace>
    <revisions>
        <revision date="2010-06-11" num="0">
            <description>Initial creation.</description>
        </revision>
    </revisions>
</requirement>

</requirements>

<functionalSpecs>

    <functionalSpec id="B010134" model="Model-T">
        <trace>
            <meeting></meeting>
        </trace>
        <revisions>
            <revision date="2009-07-08" num="0">
                <description>Initial creation.</description>
            </revision>
            <detailer>Me</detailer>
            <engineer>Me</engineer>
        </revisions>
    </functionalSpec>

</functionalSpecs>
</srs>

Below is the XSD file.

<?xml version="1.0" encoding="UTF-8" ?>

<xs:schema
  xmlns:xs="http://www.w3.org/2001/XMLSchema"
  targetNamespace="srs"
  xmlns="srs"
  xmlns:srs="srs"
  elementFormDefault="qualified">

  <!-- SRS -->

  <xs:element name="srs" type="SRSType">
  </xs:element>

  <xs:complexType name="SRSType">
    <xs:sequence>
      <xs:element ref="requirements" />
      <xs:element ref="functionalSpecs" />
    </xs:sequence>
  </xs:complexType>

  <!-- Requirements -->

  <xs:element name="requirements" type="RequirementsType">
    <xs:unique name="requirementId">
      <xs:selector xpath="srs/requirements/requirement" />
      <xs:field xpath="@id" />
    </xs:unique>
  </xs:element>

  <xs:complexType name="RequirementsType">
    <xs:choice maxOccurs="unbounded">
      <xs:element name="requirement" type="RequirementType" />
    </xs:choice>
  </xs:complexType>

  <xs:complexType name="RequirementType">
    <xs:complexContent>
      <xs:extension base="RequirementInfo">
        <xs:sequence>
          <xs:element name="trace" type="TraceType" maxOccurs="unbounded" minOccurs="1" />
          <xs:element name="revisions" type="RequirementRevisions" />
        </xs:sequence>
      </xs:extension>
    </xs:complexContent>
  </xs:complexType>

  <xs:complexType name="RequirementRevisions">
    <xs:sequence>
      <xs:element name="revision" type="RevisionInfo" minOccurs="1" maxOccurs="unbounded" />
    </xs:sequence>
  </xs:complexType>

  <xs:complexType name="RequirementInfo">
    <xs:sequence>
      <xs:element name="Text" type="Description" />
    </xs:sequence>
    <xs:attribute name="DateCreated" type="xs:date" use="required" />
    <xs:attribute name="id" type="xs:integer" use="required" />
  </xs:complexType>

  <!-- Functional Specs -->

  <xs:element name="functionalSpecs" type="FunctionalSpecsType">
    <xs:unique name="functionalSpecId">
      <xs:selector xpath="srs/functionalSpecs/functionalSpec" />
      <xs:field xpath="@id" />
    </xs:unique>
  </xs:element>

  <xs:complexType name="FunctionalSpecsType">
    <xs:choice maxOccurs="unbounded">
      <xs:element name="functionalSpec" type="FunctionalSpecType" />
    </xs:choice>
  </xs:complexType>

  <xs:complexType name="FunctionalSpecType">
    <xs:complexContent>
      <xs:extension base="FunctionalSpecInfo">
        <xs:sequence>
          <xs:element name="trace" type="TraceType" maxOccurs="unbounded" minOccurs="1" />
          <xs:element name="revisions" type="FunctionalSpecRevisions" />
        </xs:sequence>
      </xs:extension>
    </xs:complexContent>
  </xs:complexType>

  <xs:complexType name="FunctionalSpecRevisions">
    <xs:sequence>
      <xs:element name="revision" type="RevisionInfo" minOccurs="1" maxOccurs="unbounded" />
      <xs:element name="detailer" type="xs:string" />
      <xs:element name="engineer" type="xs:string" />
    </xs:sequence>
  </xs:complexType>

  <xs:complexType name="FunctionalSpecInfo">
    <xs:attribute name="id" type="xs:string" use="required" />
    <xs:attribute name="model" type="xs:string" use="required" />
  </xs:complexType>

  <!-- Requirements, Functional Specs -->

  <xs:complexType name="TraceType">
    <xs:choice>
      <xs:element name="requirementId">
        <xs:keyref refer="requirementId" name="requirementIdRef">
          <xs:selector xpath="srs/requirements/requirement" />
          <xs:field xpath="@id" />
        </xs:keyref>
      </xs:element>
      <xs:element name="functionalSpecId">
        <xs:keyref refer="functionalSpecId" name="functionalSpecIdRef">
          <xs:selector xpath="srs/functionalSpecs/functionalSpec" />
          <xs:field xpath="@id" />
        </xs:keyref>
      </xs:element>
      <xs:element name="meeting" />
    </xs:choice>
  </xs:complexType>

  <!-- Common -->

  <xs:complexType name="RevisionInfo">
    <xs:choice>
      <xs:element name="description" type="Description" />
    </xs:choice>
    <xs:attribute name="date" type="xs:date" use="required" />
    <xs:attribute name="num" type="xs:integer" use="required" />
  </xs:complexType>

  <xs:complexType name="Description" mixed="true">
    <xs:simpleContent>
      <xs:extension base="xs:string">
        <xs:attribute name="Date" type="xs:date" />
      </xs:extension>
    </xs:simpleContent>
  </xs:complexType>

</xs:schema>