XSD 复合空元素

Empty compound elements cannot contain content, they can only contain attributes.

Compound Empty Element:

ਇੱਕ ਖਾਲੀ XML ਐਲੀਮੈਂਟ:

<product prodid="1345" />

ਉੱਪਰੋਕਤ "product" ਐਲੀਮੈਂਟ ਵਿੱਚ ਕੋਈ content ਨਹੀਂ ਹੈ। ਬਿਨਾਂ content ਦੇ type ਨੂੰ ਪਰਿਭਾਸ਼ਿਤ ਕਰਨ ਲਈ, ਅਸੀਂ ਇੱਕ type ਦੇਣਾ ਹੈ ਜਿਸ ਵਿੱਚ ਸਿਰਫ਼ ਐਲੀਮੈਂਟ ਹੀ ਹੋਣ, ਪਰ ਇਸ ਵਿੱਚ ਕੋਈ ਐਲੀਮੈਂਟ ਨਹੀਂ ਦੇਣਾ ਹੈ, ਜਿਵੇਂ ਇਹ ਹੋਵੇ:

<xs:element name="product">
  <xs:complexType>
    <xs:complexContent>
      <xs:restriction base="xs:integer">
        <xs:attribute name="prodid" type="xs:positiveInteger"/>
      </xs:restriction>
    </xs:complexContent>
  </xs:complexType>
</xs:element>

ਉੱਪਰੋਕਤ ਉਦਾਹਰਣ ਵਿੱਚ, ਅਸੀਂ ਇੱਕ compound content ਵਾਲੀ compound type ਦੇਣ ਦੀ ਕੋਸ਼ਿਸ਼ ਕੀਤੀ ਹੈ। comprehensiveContent ਐਲੀਮੈਂਟ ਵਾਲੀ ਸੰਦੇਸ਼ ਹੈ ਕਿ ਅਸੀਂ ਕਿਸੇ ਕੰਪਲੈਕਸ type ਦੇ content model ਨੂੰ ਸੀਮਤ ਕਰਨਾ ਜਾਂ ਵਧਾਉਣਾ ਚਾਹੁੰਦੇ ਹਾਂ, ਅਤੇ integer ਸੀਮਤ ਵਾਲੀ ਐਲਾਨ ਇੱਕ ਪ੍ਰਤੀਯੋਗਿਤਾ ਦਿੰਦੀ ਹੈ ਜੋ ਕਿ ਕੋਈ ਐਲੀਮੈਂਟ content ਨਹੀਂ ਲੈਂਦੀ।

ਲੇਕਿਨ, ਇਹ "product" ਐਲੀਮੈਂਟ ਨੂੰ ਹੋਰ ਸਥਿਰ ਤੌਰ 'ਤੇ ਐਲਾਨ ਕੀਤਾ ਜਾ ਸਕਦਾ ਹੈ:

<xs:element name="product">
  <xs:complexType>
    <xs:attribute name="prodid" type="xs:positiveInteger"/>
  </xs:complexType>
</xs:element>

ਜਾਂ ਤੁਸੀਂ ਇੱਕ complexType ਐਲੀਮੈਂਟ ਲਈ ਇੱਕ ਨਾਮ ਚੁਣ ਸਕਦੇ ਹੋ, ਤਾਂ ਇਸ "product" ਐਲੀਮੈਂਟ ਲਈ type ਪ੍ਰਤੀਯੋਗਿਤਾ ਸੈੱਟ ਕਰੋ ਅਤੇ ਇਸ complexType ਨਾਮ ਨੂੰ ਰੋਕਾਓ (ਇਸ ਤਰ੍ਹਾਂ, ਕਈ ਐਲੀਮੈਂਟ ਨੂੰ ਇਕੇ ਹੀ compound type ਨੂੰ ਹਵਾਲਾ ਦਿੱਤਾ ਜਾ ਸਕਦਾ ਹੈ):

<xs:element name="product" type="prodtype"/>
<xs:complexType name="prodtype">
  <xs:attribute name="prodid" type="xs:positiveInteger"/>
</xs:complexType>