2011-08-11 24 views
1

这是一个正确的语法还是我需要将第一个简单类型更改为复杂?创建XSD时什么是simpleType的正确语法?

<xs:simpleType name="t_name"> 
     <xs:attribute name="a_name" > 
      <xs:simpleType> 
      <xs:restriction base="xs:hexBinary" > 
       <xs:length value="4”/> 
      </xs:restriction> 
      </xs:simpleType> 
     </xs:attribute> 
</xs:simpleType> 

回答

1

是这应该是一个复杂类型

条件是XS被定义为<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">

从W3Schools的文章 “What is a Complex Element?

复杂元素是XML元素包含其他元素 和/或属性。

有四种复杂元素:

  • 空元素只包含其他元素只包含文本同时包含其他元素和文本注释
  • 元素
  • 元素
  • 内容:这些元素中的每一个都可能包含属性!

,是因为该属性<xs:attribute name="a_name" >的需要,使之成为复合型

如果您保存以下为文件和验证它here

<?xml version="1.0"?> 
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"> 
<xs:simpleType name="t_name"> 
     <xs:attribute name="a_name" > 
      <xs:simpleType> 
      <xs:restriction base="xs:hexBinary" > 
       <xs:length value="4"/> 
      </xs:restriction> 
      </xs:simpleType> 
     </xs:attribute> 
    </xs:simpleType> 
</xs:schema> 

你会得到以下

每个cvc复合类型无效.1.2.4:元素t {http://www.w3.org/2001/XMLSchema} :这里不允许属性(1)元素 {http://www.w3.org/2001/XMLSchema}:simpleType,期待 [{http://www.w3.org/2001/XMLSchema}:annotation,{http://www.w3.org/2001/XMLSchema}:restriction,{http://www.w3.org/2001 /XMLSchema}:list,{http://www.w3.org/2001/XMLSchema}:union]:

相关问题