xml - 错误 : The namespace of element schema must be from schema namespace http://www. w3.org/2001/XMLSchema

标签 xml xsd xsd-validation xml-validation

下面是我的 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>

错误是

The namespace of element schema must be from schema namespace 'http://www.w3.org/2001/XMLSchema'

请帮帮我。

最佳答案

有关目标命名空间的直接错误是由于在 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> 

关于xml - 错误 : The namespace of element schema must be from schema namespace http://www. w3.org/2001/XMLSchema,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38641268/

相关文章:

java - XSL :FO inline and pretty print

Java:在另一个类中访问 XML 值作为新变量

java - 在 XSD 的限制中指定多个模式

.net - 如何在两台负载平衡的机器上强制自动生成的 WSDL 匹配?

java - 如果在验证第一个文件后将替换组成员添加到架构中,则使用 Saxon 验证多个 xml 文件会失败

java - 配置一个 XSD 由多个 xs :schemas? 组成

java - 正则表达式 xml 之外的电子邮件地址

xml - Xslt转换

xsd - 文字的 xsd 数据类型有子类吗?

node.js - 使用 libxmljs 和 nodejs 时出现无效的 XSD 架构