【问题标题】:Error: The namespace of element schema must be from schema namespace http://www.w3.org/2001/XMLSchema错误:元素架构的命名空间必须来自架构命名空间 http://www.w3.org/2001/XMLSchema
【发布时间】:2016-12-03 03:14:35
【问题描述】:

下面是我的 XSD。我收到错误。你能验证一下吗?

<?xml version="1.0" encoding="windows-1252" ?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
            xmlns="http://api.vvz.com/"
            xmlns:vz="http://api.vvz.com/"
            targetNamespace="http://api.vvz.com/">
  <vz:element name="Account">
    <annotation>
      <documentation>
        A sample element
      </documentation>
    </annotation>
    <simpleType name="ID">
    <restriction base="xs:string">
     <pattern value='[a-zA-Z0-9]'/>
    </restriction>
   </simpleType>
     <complexType>
    <complexContent>
     <sequence>
     <element minOccurs="0" maxOccurs="unbounded" name="fieldsToNull"
              nillable="true" type="string"/>
     <element minOccurs="0" maxOccurs="1" name="Id" nillable="true"
              type="vz:ID"/>
    </sequence>
    </complexContent>
   </complexType>
  </vz:element>
</xsd:schema>

错误是

元素架构的命名空间必须来自架构命名空间'http://www.w3.org/2001/XMLSchema'

请帮帮我。

【问题讨论】:

  • accept 哪个答案对您帮助最大。谢谢。

标签: xml xsd xsd-validation xml-validation


【解决方案1】:

关于目标命名空间的直接错误是由于在 xsd:schema 上声明了 xmlns="http://api.vvz.com/"。删除它。您不希望 XSD 本身位于该名称空间中;您需要该命名空间中的受管控 XML,而这已经通过 targetNamespace="http://api.vvz.com/" 实现。

XSD 的其余部分有许多错误和不明确的目标。这是一组使其生效的一致修复:

<?xml version="1.0" encoding="windows-1252" ?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
            xmlns:vz="http://api.vvz.com/"
            targetNamespace="http://api.vvz.com/">

  <xsd:element name="Account" type="vz:AccountType">
    <xsd:annotation>
      <xsd:documentation>
        A sample element
      </xsd:documentation>
    </xsd:annotation>
  </xsd:element>

  <xsd:complexType name="AccountType">
    <xsd:sequence>
      <xsd:element minOccurs="0" maxOccurs="unbounded" name="fieldsToNull"
                   nillable="true" type="xsd:string"/>
      <xsd:element minOccurs="0" maxOccurs="1" name="Id" nillable="true"
                   type="vz:IdType"/>
    </xsd:sequence>
  </xsd:complexType>

  <xsd:simpleType name="IdType">
    <xsd:restriction base="xsd:string">
      <xsd:pattern value='[a-zA-Z0-9]'/>
    </xsd:restriction>
  </xsd:simpleType>  

</xsd:schema> 

【讨论】:

    【解决方案2】:

    有几个问题:

    • 构成架构的所有元素都必须位于 XML 架构命名空间中(使用 xsd 前缀)。
    • 命名的简单类型必须是顶级的。
    • 对内置类型 string 的引用也必须在 XML Schema 命名空间中(xsd 前缀)。
    • 元素complexContent 是无关的。

      <?xml version="1.0" encoding="windows-1252" ?>
      <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
          xmlns="http://api.vvz.com/"
          xmlns:vz="http://api.vvz.com/"
          targetNamespace="http://api.vvz.com/">
          <xsd:simpleType name="ID">
              <xsd:restriction base="xsd:string">
                  <xsd:pattern value='[a-zA-Z0-9]'/>
              </xsd:restriction>
          </xsd:simpleType>
          <xsd:annotation>
              <xsd:documentation>
                  A sample element
              </xsd:documentation>
          </xsd:annotation>
          <xsd:element name="Account">
              <xsd:complexType>
                  <xsd:sequence>
                      <xsd:element minOccurs="0" maxOccurs="unbounded" name="fieldsToNull"
                          nillable="true" type="xsd:string"/>
                      <xsd:element minOccurs="0" maxOccurs="1" name="Id" nillable="true"
                          type="vz:ID"/>
                  </xsd:sequence>
              </xsd:complexType>
          </xsd:element>
      </xsd:schema>
      

    【讨论】:

      猜你喜欢
      • 2011-06-22
      • 2015-06-21
      • 2012-04-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-12-27
      • 1970-01-01
      相关资源
      最近更新 更多