如果我没有用Google搜索到Oblivion,我就不会在这里.我有以下问题:我有一个XML Schema,3个单个XML文档和一个XML文档来链接所有其他3.我遇到以下错误,我不明白为什么.
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>
Run Code Online (Sandbox Code Playgroud)
这是我的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>
Run Code Online (Sandbox Code Playgroud)
这是我的文件使用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>
Run Code Online (Sandbox Code Playgroud)
现在我在搜索这个错误时读了很多关于命名空间的内容,但是我无法清楚地知道我哪里出错了.
如果你可以指出我正确的方向,为什么会发生这种错误,以及我如何处理它,那将是很好的.
该xml:base属性(W3C XML Base由XInclude添加,以符合规范.请参阅:http://xerces.apache.org/xerces2-j/faq-xinclude.html#faq-3
FAQ提出了两种解决方案.其中一个要求您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" />
Run Code Online (Sandbox Code Playgroud)
然后通过引用声明属性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>
Run Code Online (Sandbox Code Playgroud)