xml - 架构文件名未检测到命名空间

标签 xml xsd namespaces schema

我有很多 XSD,它包含在单个 XSD 文件中,所有文件都变得有效,并且相应的 XML 文件也使用氧 XML 编辑器对相应的 XSD 有效。但是在针对产品中的 XSD 文件上传 xml 文件时。我收到以下错误:

Error resolving component 'Definition.attrib'. It was detected that 'Definition.attrib' has no namespace, but components with no target namespace are not referenceable from schema document



当我打开相应的文件时,它显示在氧 XML 编辑器中已验证。下面是对应文件的代码:
<?xml version="1.0" encoding="UTF-8"?>

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

<xs:include schemaLocation="common-attrib.xsd"></xs:include>
<xs:include schemaLocation="../common/common-attribs.xsd"></xs:include>

<xs:attributeGroup name="mean.attlist">
  <xs:attributeGroup ref="Definition.attrib"/>
  <xs:attributeGroup ref="Common.attrib"/>
</xs:attributeGroup>


<xs:complexType name="mean.type">
  <xs:attributeGroup ref="mean.attlist"/>
</xs:complexType>

<xs:element name="mean" type="mean.type"/>

<xs:attributeGroup name="sdev.attlist">
  <xs:attributeGroup ref="Definition.attrib"/>
  <xs:attributeGroup ref="Common.attrib"/>
</xs:attributeGroup>

<xs:complexType name="sdev.type">
  <xs:attributeGroup ref="sdev.attlist"/>
</xs:complexType>

<xs:element name="sdev" type="sdev.type"/>

<!-- "variance" -->

<xs:attributeGroup name="variance.attlist">
  <xs:attributeGroup ref="Definition.attrib"/>
  <xs:attributeGroup ref="Common.attrib"/>
</xs:attributeGroup>

<xs:complexType name="variance.type">
  <xs:attributeGroup ref="variance.attlist"/>
</xs:complexType>

<xs:element name="variance" type="variance.type"/>

<!-- "median" -->

<xs:attributeGroup name="median.attlist">
  <xs:attributeGroup ref="Definition.attrib"/>
  <xs:attributeGroup ref="Common.attrib"/>
</xs:attributeGroup>

<xs:complexType name="median.type">
  <xs:attributeGroup ref="median.attlist"/>
</xs:complexType>

<xs:element name="median" type="median.type"/>

<!-- "mode" -->

<xs:attributeGroup name="mode.attlist">
  <xs:attributeGroup ref="Definition.attrib"/>
  <xs:attributeGroup ref="Common.attrib"/>
</xs:attributeGroup>

<xs:complexType name="mode.type">
  <xs:attributeGroup ref="mode.attlist"/>
</xs:complexType>

<xs:element name="mode" type="mode.type"/>

<!-- "moment" -->

<xs:attributeGroup name="moment.attlist">
  <xs:attributeGroup ref="Definition.attrib"/>
  <xs:attributeGroup ref="Common.attrib"/>
</xs:attributeGroup>

<xs:complexType name="moment.type">
  <xs:attributeGroup ref="moment.attlist"/>
</xs:complexType>

<xs:element name="moment" type="moment.type"/>

<!-- "momentabout" -->

<xs:attributeGroup name="momentabout.attlist">
  <xs:attributeGroup ref="Definition.attrib"/>
  <xs:attributeGroup ref="Common.attrib"/>
</xs:attributeGroup>

<xs:group name="momentabout.content">
  <xs:sequence>
    <xs:group ref="Content-statistics.class"/>
  </xs:sequence>
</xs:group>

<xs:complexType name="momentabout.type">
  <xs:group ref="momentabout.content"  minOccurs="1" maxOccurs="unbounded"/>
  <xs:attributeGroup ref="momentabout.attlist"/>
</xs:complexType>

<xs:element name="momentabout" type="momentabout.type"/>

<!-- And the group of everything -->

<xs:group name="Content-statistics.class">
  <xs:choice>
    <xs:element ref="mean"/>
    <xs:element ref="sdev"/>
    <xs:element ref="variance"/>
    <xs:element ref="median"/>
    <xs:element ref="mode"/>
    <xs:element ref="moment"/>
    <xs:element ref="momentabout"/>
  </xs:choice>
</xs:group>


</xs:schema>

对应的xml文件在这里:
<?xml version="1.0" encoding="UTF-8"?>
<document xmlns:CORE="http://www.reallysi.com" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:m="http://www.w3.org/1998/Math/MathML" xsi:noNamespaceSchemaLocation="oup.xsd">
<documentinfo publisher="OUPAustralia" title="Test Title - HE" titlenumber="1" isbn13="9780190311360" edition="4" author="Reynolds"/>
<chapter no="2">
<title><num>2</num><head>Inquiry Pedagogy</head></title>
<intro>
<para fo="Y"><txt><b>Good pedagogy</b></txt></para>
<para><txt><b>Research</b></txt></para>
</intro>
</document>

任何人都可以帮我解决这个问题,为什么会发生这个错误。请为此提供建议。

最佳答案

您还没有明确定义 Definition.attrib 的模式文档是否存在是否可以从顶级架构文档访问。似乎有两种可能性:(a) 没有对该属性组的声明,或者 (b) 有声明,但它位于错误的命名空间中。无论哪种方式,您都有一个悬空引用。

我怀疑您在不同环境中看到不同效果的原因是 XSD 规范在有这样的悬空引用时为处理器提供了一些灵活性。该规范鼓励处理器继续执行,只要引用是对验证此实例文档实际上并不需要的组件。但规则有些模糊。

关于xml - 架构文件名未检测到命名空间,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53294725/

相关文章:

php - 如何将从另一个命名空间导入的普通函数传递为可调用函数?

namespaces - 将 Clojure 命名空间拆分为多个文件

xml - 使用带有命名空间的正确路径来解析 XML(在 VBA 中)

java - 按钮与底部对齐,从 ImageView 中隐藏

c# - 我如何列出 XML 中的所有 namespace ?

php - 如何以编程方式发现给定域上的博客提要?

xml - 具有可选子元素的默认 XML 序列(或全部)是否必须至少有一个子元素?

android - 错误 : No resource identifier found for attribute 'starColor' in package 'android'

c++ - 使用 -icu 构建 xerces

python - 是否可以获取 XSD 中定义的 XML 节点类型?