Khi xác định XSD, bạn có thể chọn để xác định loại của mình là loại lồng nhau hoặc loại toàn cầu (complexType).XSD: Các loại lồng nhau so với các loại toàn cầu
Tôi hiểu rằng các loại toàn cầu được sử dụng nhiều hơn khi nói đến hình thái hoặc tái sử dụng các yếu tố.
Tuy nhiên, nếu bạn có mô hình dữ liệu lớn, bạn sẽ phải xác định cho mỗi cấp một complexType toàn cục và sau đó tạo phần tử tham chiếu đến loại toàn cục.
Nested
<xs:element name="person">
<xs:complexType>
<xs:sequence>
<xs:element name="name">
<xs:complexType>
<xs:sequence>
<xs:element name="firstname"/>
<xs:element name="lastname"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="address">
<xs:complexType>
<xs:sequence>
<xs:element name="street"/>
<xs:element name="city"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
toàn cầu
<xs:element name="person">
<xs:complexType>
<xs:sequence>
<xs:element name="name" type="nameType"/>
<xs:element name="address" type="addressType"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:complexType name="nameType">
<xs:sequence>
<xs:element name="firstname"/>
<xs:element name="lastname"/>
</xs:sequence>
</xs:complexType>
<xs:complexType name="addressType">
<xs:sequence>
<xs:element name="street"/>
<xs:element name="city"/>
</xs:sequence>
</xs:complexType>
Do đó, câu hỏi của tôi: Khi bạn đang sử dụng loại lồng nhau thay vì làm cho chúng toàn cầu?
Đối với bất kỳ ai quan tâm: Câu hỏi của tôi bằng cách nào đó liên quan đến câu hỏi này (XML attribute vs element).