8

如果我没有用 Google 搜索到 Oblivion,我就不会在这里。我有以下问题:我有一个 XML 模式、3 个单个 XML 文档和一个用于链接所有其他 3 个的 XML 文档。我遇到了以下错误,我不明白为什么。

E [Xerces] cvc-complex-type.3.2.2:属性“xml:base”不允许出现在元素“SoftwareRequirementsDocument”中。

我已经阅读了谷歌的一堆论坛帖子,里面有类似问题的人,但他们的修复都没有帮助我。我将发布我的 Schema、1 个要连接的 XML 文档以及带有 XInclude 的 XML 文档。我将发布每个文档的开头,因为这是需要的。

这是 NotionalSchema2.xsd:

<xsd:element name="ProjectLifecycleDocuments" type="ProjectLifecycleDocumentsType"/>
<xsd:complexType name="ProjectLifecycleDocumentsType">
    <xsd:choice minOccurs="0" maxOccurs="unbounded">
        <xsd:element ref="Team"/>
        <xsd:element ref="SoftwareRequirementsDocument"/>
        <xsd:element ref="UseCaseDocument"/>
        <xsd:element ref="TestCaseDocument"/>
    </xsd:choice>
    <xsd:attribute name="id" use="required" type="xsd:ID"/>
</xsd:complexType>

<xsd:element name="SoftwareRequirementsDocument" type="SoftwareRequirementsDocumentType"/>
<xsd:complexType name="SoftwareRequirementsDocumentType">
    <xsd:sequence>
        <xsd:element ref="Section" maxOccurs="unbounded"/>

        <!-- Other global elements to be referenced here. -->
    </xsd:sequence>
    <xsd:attribute name="projectName" use="required" type="xsd:string"/>
    <!--<xsd:attribute name="id" use="required" type="xsd:ID"/>-->
</xsd:complexType>

这是我的 NotionalSRS2.xml:

<SoftwareRequirementsDocument projectName="Lifecycle Documents with Requirements  
Tracking" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
xsi:noNamespaceSchemaLocation="NotionalSchema2.xsd"      
xmlns:xx="http://apache.org/xml/features/xinclude/fixup-base-uris">

    <Section id="RQ1.0">

    <Title>Introduction</Title>
  <Para>The Software Requirements Specification details the extent of NUWC’s Lifecycle Project Manager. The product’s main feature is it’s ability to create and manage lifecycle documents using a graphical user interface. The lifecycle documents will be organized and exported using an XML Schema. This can be accomplished by a user who has no knowledge of the XML language. This document will review all the basic functionality required for a user to edit, create, and manage lifecycle projects.
  </Para>    
    </Section>

    <Section id="RQ1.1">
        <Title>Purpose</Title>
        <Para> To provide a detailed description of how the product will produce it’s lifecycle documents as well as edit and export them. It also overviews the basic functional requirements requested by the customer.
        </Para>
    </Section>

这是我使用 XInclude 的文件 ProjectLifecycleDocuments.xml :

<ProjectLifecycleDocuments id="PL1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-     
instance" xmlns:xi="http://www.w3.org/2001/XInclude"
xsi:noNamespaceSchemaLocation="NotionalSchema2.xsd">
<xi:include href="NotionalSRS2.xml"/> 

</ProjectLifecycleDocuments>

现在我在搜索这个错误时阅读了很多关于命名空间的信息,但我无法清楚地了解我哪里出错了。

如果您能指出正确的方向,说明为什么会发生此错误以及如何修复它,那就太好了。

4

1 回答 1

11

xml:base属性(W3C XML Base由 XInclude 添加以符合规范。请参阅:http: //xerces.apache.org/xerces2-j/faq-xinclude.html#faq-3

常见问题解答提出了两种解决方案。其中之一要求您xml:base在运行解析器时通过设置功能来禁用属性的插入。另一个包括配置您的架构以允许xml:base包含类型中的属性,您可以通过在架构中导入 XML XSD 来做到这一点:

<xsd:import namespace="http://www.w3.org/XML/1998/namespace" schemaLocation="http://www.w3.org/2001/03/xml.xsd" />

然后通过引用声明该属性xml:base

<xsd:complexType name="SoftwareRequirementsDocumentType">
    <xsd:sequence> ... </xsd:sequence>
    <xsd:attribute name="projectName" use="required" type="xsd:string"/>
    <xsd:attribute ref="xml:base"/>
    ...
</xsd:complexType>
于 2014-04-01T16:22:27.040 回答