2014-01-10 49 views

回答

1

不,mixed不是由子元素繼承。

鑑於這種XSD:

<?xml version="1.0"?> 
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"> 
    <xs:element name="root"> 
    <xs:complexType mixed="true"> 
     <xs:sequence> 
     <xs:element name="child" minOccurs="0" maxOccurs="unbounded"> 
      <xs:complexType> 
      <xs:sequence> 
       <xs:element name="grandchild" minOccurs="0" maxOccurs="unbounded"> 
       </xs:element> 
      </xs:sequence> 
      </xs:complexType> 
     </xs:element> 
     </xs:sequence> 
    </xs:complexType> 
    </xs:element> 
</xs:schema> 

此XML文檔實例:

<root> 
    text1 
    <child> 
    text2 
    <grandchild/> 
    </child> 
</root> 

將是無效因爲rootmixed內容模型是不是一起的內容傳遞型號爲child

驗證解析器將發出一個錯誤,如下列:

元素「孩子」不能有字符[兒童],因爲該類型的 內容類型的元素而已。

又見相似,但不同的問題Is mixed inherited when a complexType is extended?