2016-07-28 96 views
-1

以下是我的XSD。我收到错误。你能否验证这个?错误:元素模式的名称空间必须来自模式名称空间http://www.w3.org/2001/XMLSchema

<?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 '

请帮助我。

+1

请[**接受**](http://meta.stackoverflow.com/q/5234/234215)无论哪个答案已帮助您最。谢谢。 – kjhughes

回答

0

有几个问题:

  • 该架构是由必须在XML Schema名称空间(使用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> 
    
2

您对目标命名空间即时错误是由于对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> 
相关问题