XSD కంపోజిట్ మూలకం సూచకం

ఇండికేటర్స్ ద్వారా, మేము పత్రంలో ఉపయోగించే అంశాల విధంను నియంత్రించవచ్చు.

ఇండికేటర్

ఏడు ఇండికేటర్స్ ఉన్నాయి:

ఆర్డర్ ఇండికేటర్:

  • అన్ని
  • క్లోజ్
  • సీక్వెన్స్

ఇంకారెన్స్ ఇండికేటర్:

  • maxOccurs
  • minOccurs

Group సూచకం:

  • Group name
  • attributeGroup name

Order సూచకం

Order సూచకం మూలకాల క్రమాన్ని నిర్వచిస్తుంది.

All సూచకం

<all> సూచకం ఉపమూలకాలను ఏదైనా క్రమంలో కనుగొనబడే విధంగా మరియు ప్రతి ఉపమూలకం ఒకే సారి మాత్రమే కనుగొనబడే విధంగా నిర్వచిస్తుంది:

<xs:element name="person">
  <xs:complexType>
    <xs:all>
      <xs:element name="firstname" type="xs:string"/>
      <xs:element name="lastname" type="xs:string"/>
    </xs:all>
  </xs:complexType>
</xs:element>

ప్రత్యామ్నాయం ఉంది:మీరు <all> సూచకాన్ని ఉపయోగించినప్పుడు, <minOccurs> ను 0 లేదా 1 గా అమర్చవచ్చు, మరియు <maxOccurs> సూచకాన్ని మాత్రమే 1 గా అమర్చవచ్చు (మరియు ఆ తర్వాత వివరించబడుతుంది <minOccurs> మరియు <maxOccurs>).

Choice సూచకం

<choice> సూచకం ఒక ఉపమూలకాన్ని లేదా మరొక ఉపమూలకాన్ని (ఇది లేదా అది) కనుగొనబడే విధంగా నిర్వచిస్తుంది:

<xs:element name="person">
  <xs:complexType>
    <xs:choice>
      <xs:element name="employee" type="employee"/>
      <xs:element name="member" type="member"/>
    </xs:choice>
  </xs:complexType>
</xs:element>

హిఫాయతం:ఉపమూలకాలను ఏదైనా సంఖ్యలో కనుగొనబడే విధంగా అమర్చడానికి, <maxOccurs> (మరియు ఆ తర్వాత వివరించబడుతుంది) ను unbounded (అనంత సార్లు) గా అమర్చండి.

Sequence సూచకం

<sequence> సూచకం ఉపమూలకాలను ప్రత్యేక క్రమంలో కనుగొనబడే విధంగా నిర్వచిస్తుంది:

<xs:element name="person">
  <xs:complexType>
    <xs:sequence>
      <xs:element name="firstname" type="xs:string"/>
      <xs:element name="lastname" type="xs:string"/>
    </xs:sequence>
  </xs:complexType>
</xs:element>

Occurrence సూచకం

Occurrence సూచకం ఒక మూలకం కనుగొనబడే అవగాహనను నిర్వచిస్తుంది.

ప్రత్యామ్నాయం ఉంది:అన్ని "Order" మరియు "Group" సూచకాలు (any, all, choice, sequence, group name మరియు group reference) కోసం, వాటిలో మొత్తం maxOccurs మరియు minOccurs యొక్క అప్రమేయ విలువలు 1 ఉంటాయి.

maxOccurs సూచకం

<maxOccurs> సూచకం ఒక మూలకం కనుగొనబడే గరిష్ట సంఖ్యను నిర్ణయిస్తుంది:

<xs:element name="person">
  <xs:complexType>
    <xs:sequence>
      <xs:element name="full_name" type="xs:string"/>
      <xs:element name="child_name" type="xs:string"> maxOccurs="10"/>
    </xs:sequence>
  </xs:complexType>
</xs:element>

పైన ఉన్న ఉదాహరణ చూపిస్తుంది కి, "child_name" అనే ఉపమూలకం "person" మూలకంలో కనుగొనబడవచ్చు కనీసం ఒక సారి (మొదటి స్థానంలో minOccurs యొక్క అప్రమేయ విలువ ఉంది 1), గరిష్టంగా 10 సార్లు.

minOccurs సూచకం

<minOccurs> సూచకం ఒక మూలకం కనుగొనబడే కనీస సంఖ్యను నిర్ణయిస్తుంది:

<xs:element name="person">
  <xs:complexType>
    <xs:sequence>
      <xs:element name="full_name" type="xs:string"/>
      <xs:element name="child_name" type="xs:string">
      maxOccurs="10" minOccurs="0"/>
    </xs:sequence>
  </xs:complexType>
</xs:element>

పైన ఉన్న ఉదాహరణ చూపిస్తుంది కి, "child_name" అనే ఉపమూలకం "person" మూలకంలో కనుగొనబడవచ్చు కనీసం 0 సార్లు మరియు గరిష్టంగా 10 సార్లు.

హిఫాయతం:ఏదైనా ఎలమెంట్ని ఎంతో కనుగొనలేము చేయడానికి maxOccurs="unbounded" ఈ ప్రకటనను ఉపయోగించండి:

ఒక వాస్తవ ఉదాహరణ:

XML ఫైల్ "Myfamily.xml" పేరు కలిగిన:

<?xml version="1.0" encoding="ISO-8859-1"?>
<persons xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
xsi:noNamespaceSchemaLocation="family.xsd">
<person>
<full_name>Tony Smith</full_name>
<child_name>Cecilie</child_name>
</person>
<person>
<full_name>David Smith</full_name>
<child_name>Jogn</child_name>
<child_name>mike</child_name>
<child_name>kyle</child_name>
<child_name>mary</child_name>
</person>
<person>
<full_name>Michael Smith</full_name>
</person>
</persons>

ఈ XML ఫైల్ "persons" అనే పేరు వాలి రూట్ ఎలమెంట్లో, మేము మూడు "person" ఎలమెంట్లను నిర్వచించాము. ప్రతి "person" ఎలమెంట్లో "full_name" ఎలమెంట్ని కలిగి ఉండాలి, మరియు అది 5 వరకు "child_name" ఎలమెంట్లను కలిగి ఉండవచ్చు.

ఈ స్కీమా ఫైల్ "family.xsd" ఉంది:

<?xml version="1.0" encoding="ISO-8859-1"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
elementFormDefault="qualified">
<xs:element name="persons">
  <xs:complexType>
    <xs:sequence>
      <xs:element name="person" maxOccurs="unbounded">
        <xs:complexType>
          <xs:sequence>
            <xs:element name="full_name" type="xs:string"/>
            <xs:element name="child_name" type="xs:string">
            minOccurs="0" maxOccurs="5"/>
          </xs:sequence>
        </xs:complexType>
      </xs:element>
    </xs:sequence>
  </xs:complexType>
</xs:element>
</xs:schema>

Group సూచకం

Group సూచకం all అంశాలను నిర్వచించడానికి ఉపయోగించబడుతుంది.

అంశాల సమూహం

అంశాల సమూహం నిర్వచించడానికి group ప్రకటనను ఉపయోగించబడుతుంది:

<xs:group name="组名称">
  ...
</xs:group>

మీరు group ప్రకటనలోని ఒక all, choice లేదా sequence అంశాన్ని నిర్వచించవలసి ఉంటుంది. ఈ ఉదాహరణలో, "persongroup" పేరుతోని group నిర్వచించబడింది, ఇది అంశాల సమూహాన్ని నిర్వచిస్తుంది మరియు అంశాలు నిజమైన క్రమంలో కనిపించాలి:

<xs:group name="persongroup">
  <xs:sequence>
    <xs:element name="firstname" type="xs:string"/>
    <xs:element name="lastname" type="xs:string"/>
    <xs:element name="birthday" type="xs:date"/>
  </xs:sequence>
</xs:group>

మీరు group నిర్వచించిన తర్వాత, మరొక నిర్వచనంలో దానిని ఉపయోగించవచ్చు:

<xs:group name="persongroup">
  <xs:sequence>
    <xs:element name="firstname" type="xs:string"/>
    <xs:element name="lastname" type="xs:string"/>
    <xs:element name="birthday" type="xs:date"/>
  </xs:sequence>
</xs:group>
<xs:element name="person" type="personinfo"/>
<xs:complexType name="personinfo">
  <xs:sequence>
    <xs:group ref="persongroup"/>
    <xs:element name="country" type="xs:string"/>
  </xs:sequence>
</xs:complexType>

అంశాల సమూహం

అంశాల సమూహం attributeGroup ప్రకటన ద్వారా నిర్వచించబడుతుంది:

<xs:attributeGroup name="组名称">
  ...
</xs:attributeGroup>

ఈ ఉదాహరణలో, "personattrgroup" పేరుతోని ఒక అంశాల సమూహాన్ని నిర్వచించబడింది:

<xs:attributeGroup name="personattrgroup">
  <xs:attribute name="firstname" type="xs:string"/>
  <xs:attribute name="lastname" type="xs:string"/>
  <xs:attribute name="birthday" type="xs:date"/>
</xs:attributeGroup>

మీరు అంతర్జాతి అంశాలను నిర్వచించిన తర్వాత, మరొక నిర్వచనంలో దానిని ఉపయోగించవచ్చు, ఇలా వంటిది:

<xs:attributeGroup name="personattrgroup">
  <xs:attribute name="firstname" type="xs:string"/>
  <xs:attribute name="lastname" type="xs:string"/>
  <xs:attribute name="birthday" type="xs:date"/>
</xs:attributeGroup>
<xs:element name="person">
  <xs:complexType>
    <xs:attributeGroup ref="personattrgroup"/>
  </xs:complexType>
</xs:element>