我试图让我的 XML 模式处理一些可追溯性功能,因为我在阅读一些功能规范时正在收集需求。(对于需求管理来说并不理想,但至少是一个开始。)
我正在做的是为我目前正在阅读的每个功能规范创建一个 < functionalSpec>标记。我为找到的每个需求创建了一个 < required>标签。由于我希望能够跟踪需求的来源,因此我创建了一个 < trace>元素,其id为 < functionalSpec>元素。我不想让自己在 < functionalSpecId>标记中输入任何纯旧文本,而是希望 XSD 验证并确保我只输入现有功能规范存在的id 。我的问题出现在XML Schema W3C Recommendations的地方文档说我想做的事情是不可能的。(大约下降 1/2)
{selector} 指定相对于被声明元素的实例的受限 XPath ([XPath]) 表达式。这必须标识约束适用的从属元素的节点集(即包含在声明的元素中)。
我正在使用 Oxygen 创建它,因为我对 XSD 文件还很陌生,它给了我以下错误:
E [Xerces] 身份约束错误:身份约束“KeyRef@1045a2”有一个 keyref 引用超出范围的键或唯一值。
所以我的问题是,有没有人知道一种方法可以让我通过使用 XSD 来使用与下面相同的 XML 结构?
下面是 XML 文件。
<?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>
下面是 XSD 文件。
<?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>