[xml] XML 스키마 minOccurs / maxOccurs 기본값

XML 스키마 사양이 이러한 경우를 처리하는 방법이 궁금합니다.

<xsd:element minOccurs="1" name="asdf"/>

주어진 maxOccurs 없음-> 이것이 카디널리티 [1..1]입니까?

<xsd:element minOccurs="5" maxOccurs="2" name="asdf"/>

나는 이것이 단순히 유효하지 않다고 생각합니까?

<xsd:element maxOccurs="2" name="asdf"/>

카디널리티 [0..2] 또는 [1..2]입니까?

XML 스키마 사양이 이러한 경우를 처리하는 방법에 대한 “공식적인”정의가 있습니까?



답변

minOccurs및 의 기본값 maxOccurs은 1입니다.

<xsd:element minOccurs="1" name="asdf"/>

카디널리티는 [1-1]입니다. 참고 : minOccurs 속성 지정하면 maxOccurs의 기본값은 1이므로 1보다 클 수 없습니다.

<xsd:element minOccurs="5" maxOccurs="2" name="asdf"/>

무효

<xsd:element maxOccurs="2" name="asdf"/>

카디널리티는 [1-2]입니다. 참고 : maxOccurs 속성 지정하면 minOccurs의 기본값은 1이므로 1보다 작을 수 없습니다.

<xsd:element minOccurs="0" maxOccurs="0"/>

요소를 금지하는 유효한 조합입니다.

자세한 내용은 http://www.w3.org/TR/xmlschema-0/#OccurrenceConstraints를 참조하십시오 .


답변

자주 묻는 질문에 대한 새롭고 확장 된 답변 …

기본값

  • 발생 제한 조건 minOccursmaxOccurs 기본값은1 입니다.

일반적인 사례 설명

<xsd:element name="A"/>

수단 A필요 하며 정확히 한 번만 나타나야 합니다 .


<xsd:element name="A" minOccurs="0"/>

평균 A선택 사항 이며 최대 한 번 나타날 수 있습니다 .


 <xsd:element name="A" maxOccurs="unbounded"/>

수단 A필요 하며 무제한으로 반복 될 수 있습니다 .


 <xsd:element name="A" minOccurs="0" maxOccurs="unbounded"/>

평균 A선택 사항 이며 무제한 반복 될 수 있습니다 .


또한보십시오

  • W3C XML 스키마 파트 0 : 프라이머

    일반적으로 minOccurs 값이 1 이상인 경우 요소가 나타나야합니다. 요소가 나타날 수있는 최대 횟수는 선언에서 maxOccurs 속성 값에 의해 결정됩니다. 이 값은 41과 같은 양의 정수이거나 최대 발생 횟수가 없음을 나타 내기 위해 제한이없는 용어 일 수 있습니다. minOccurs 및 maxOccurs 속성의 기본값은 1입니다. 따라서 comment와 같은 요소가 maxOccurs 속성없이 선언되면 요소가 두 번 이상 발생할 수 없습니다. minOccurs 속성에만 값을 지정하면 기본값 인 maxOccurs보다 작거나 같아야합니다 (예 : 0 또는 1). maxOccurs 속성에만 값을 지정하면 maxOccurs 속성 만 사용해야합니다. minOccurs의 기본값보다 크거나 같은, 즉 1 이상.

  • W3C XML 스키마 1 부 : 구조 2 판

    <element
      maxOccurs = (nonNegativeInteger | unbounded)  : 1
      minOccurs = nonNegativeInteger : 1
      >
    
    </element>
    

답변

짧은 답변:

xsd로 작성된

<xs:attribute name="minOccurs" type="xs:nonNegativeInteger" use="optional" default="1"/>
<xs:attribute name="maxOccurs" type="xs:allNNI" use="optional" default="1"/>

숫자가있는 속성을 제공하면 숫자는 경계입니다. 그렇지 않으면 속성이 정확히 한 번만 나타납니다 .


답변

예:

XML

<?xml version="1.0" encoding="UTF-8"?> 
<?xml-stylesheet type="text/xsl" href="country.xsl"?>
<country xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="country.xsd">
    <countryName>Australia</countryName>
    <capital>Canberra</capital>
    <nationalLanguage>English</nationalLanguage>
    <population>21000000</population>
    <currency>Australian Dollar</currency>
    <nationalIdentities>
        <nationalAnthem>Advance Australia Fair</nationalAnthem>
        <nationalDay>Australia Day (26 January)</nationalDay>
        <nationalColour>Green and Gold</nationalColour>
        <nationalGemstone>Opal</nationalGemstone>
        <nationalFlower>Wattle (Acacia pycnantha)</nationalFlower>
    </nationalIdentities>
    <publicHolidays>
        <newYearDay>1 January</newYearDay>
        <australiaDay>26 January</australiaDay>
        <anzacDay>25 April</anzacDay>
        <christmasDay>25 December</christmasDay>
        <boxingDay>26 December</boxingDay>
        <laborDay>Variable Date</laborDay>
        <easter>Variable Date</easter>
        <queenBirthDay>21 April (Variable Date)</queenBirthDay>
    </publicHolidays>
    <states>
        <stateName><Name>NSW -  New South Wales</Name></stateName>
        <stateName><Name>VIC -  Victoria</Name></stateName>
        <stateName><Name>QLD -  Queensland</Name></stateName>
        <stateName><Name>SA -  South Australia</Name></stateName>
        <stateName><Name>WA -  Western Australia</Name></stateName>
        <stateName><Name>TAS -  Tasmania</Name></stateName>
    </states>
    <territories>
        <territoryName>ACT -  Australian Capital Territory</territoryName>
        <territoryName>NT -  Northern Territory</territoryName>
    </territories>
</country>

XSD :

<?xml version="1.0" encoding="UTF-8"?> 
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
    <xs:element name="country">
        <xs:complexType>
            <xs:sequence>
                <xs:element name="countryName" type="xs:string"/>
                <xs:element name="capital" type="xs:string"/>
                <xs:element name="nationalLanguage" type="xs:string"/>
                <xs:element name="population" type="xs:double"/>
                <xs:element name="currency" type="xs:string"/>
                <xs:element name="nationalIdentities">
                <xs:complexType>
                    <xs:sequence>
                        <xs:element name="nationalAnthem" type="xs:string"/>
                        <xs:element name="nationalDay" type="xs:string"/>
                        <xs:element name="nationalColour" type="xs:string"/>
                        <xs:element name="nationalGemstone" type="xs:string"/>
                        <xs:element name="nationalFlower" type="xs:string"/>
                    </xs:sequence>
                </xs:complexType>
                </xs:element>
                <xs:element name="publicHolidays">
                    <xs:complexType>
                        <xs:sequence>
                            <xs:element name="newYearDay" maxOccurs="1" type="xs:string"/>
                            <xs:element name="australiaDay" maxOccurs="1" type="xs:string"/>
                            <xs:element name="anzacDay" maxOccurs="1" type="xs:string"/>
                            <xs:element name="christmasDay" maxOccurs="1" type="xs:string"/>
                            <xs:element name="boxingDay" maxOccurs="1" type="xs:string"/>
                            <xs:element name="laborDay" maxOccurs="1" type="xs:string"/>
                            <xs:element name="easter" maxOccurs="1" type="xs:string"/>
                            <xs:element name="queenBirthDay" maxOccurs="1" type="xs:string"/>
                        </xs:sequence>
                    </xs:complexType>
                </xs:element>
                <xs:element name="states">
                    <xs:complexType>
                        <xs:sequence>
                            <xs:element name="stateName" minOccurs="1" maxOccurs="unbounded">
                                <xs:complexType>
                                    <xs:sequence>
                                        <xs:element name="Name" type="xs:string"/>
                                    </xs:sequence>
                                </xs:complexType>
                            </xs:element>
                        </xs:sequence>
                    </xs:complexType>
                </xs:element>
                <xs:element name="territories">
                    <xs:complexType>
                        <xs:sequence>
                            <xs:element name="territoryName" maxOccurs="unbounded"/>
                        </xs:sequence>
                    </xs:complexType>
                </xs:element>
            </xs:sequence>
        </xs:complexType>
    </xs:element>
</xs:schema>

XSL :

<?xml version="1.0"?> 
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
    <xsl:output method="html" indent="yes" version="4.0"/>
    <xsl:template match="/">
        <html>
            <body>          
                <xsl:for-each select="country">         
                    <xsl:value-of select="countryName"/><br/>
                    <xsl:value-of select="capital"/><br/>
                    <xsl:value-of select="nationalLanguage"/><br/>
                    <xsl:value-of select="population"/><br/>
                    <xsl:value-of select="currency"/><br/>              
                    <xsl:for-each select="nationalIdentities">
                        <xsl:value-of select="nationalAnthem"/><br/>
                        <xsl:value-of select="nationalDay"/><br/>
                        <xsl:value-of select="nationalColour"/><br/>
                        <xsl:value-of select="nationalGemstone"/><br/>
                        <xsl:value-of select="nationalFlower"/><br/>
                    </xsl:for-each>
                    <xsl:for-each select="publicHolidays">
                        <xsl:value-of select="newYearDay"/><br/>
                        <xsl:value-of select="australiaDay"/><br/>
                        <xsl:value-of select="anzacDay"/><br/>
                        <xsl:value-of select="christmasDay"/><br/>
                        <xsl:value-of select="boxingDay"/><br/>
                        <xsl:value-of select="laborDay"/><br/>
                        <xsl:value-of select="easter"/><br/>
                        <xsl:value-of select="queenBirthDay"/><br/>
                    </xsl:for-each>
                    <xsl:for-each select="states/stateName">
                        <xsl:value-of select="Name"/><br/>
                    </xsl:for-each>
                </xsl:for-each>
            </body>
        </html>
    </xsl:template>
</xsl:stylesheet>

결과:

Australia
Canberra
English
21000000
Australian Dollar
Advance Australia Fair
Australia Day (26 January)
Green and Gold
Opal
Wattle (Acacia pycnantha)
1 January
26 January
25 April
25 December
26 December
Variable Date
Variable Date
21 April (Variable Date)
NSW - New South Wales
VIC - Victoria
QLD - Queensland
SA - South Australia
WA - Western Australia
TAS - Tasmania


답변