Schema를 만들어 보자.

 1)기본 골격

<Schema name="myschema" xmlns="urn:schemas-microsoft-com:xml-data"
                        xmlns:dt="urn:schemas-microsoft-com:datatypes">
 <!-- ... -->
</Schema>

=>schema를 정의하고 여기서 쓰이는 datatype ms에서 정의한 것을 사용하겠다.는 의미이다.

2) 쓰이는 문법

 ¨<ElementType>

<ElementType
    content="{empty | textOnly | eltOnly | mixed}" 
    dt:type="datatype" ßtext 들어가는 element 필요
    model="{open | closed}" ßopen default
    name="element 이름"  
    order="{one | seq | many}" >

 ©content :

empty  =><tag/>이렇게 쓸 수 있는 tag를 말한다.(어떠한 element text를 가지지 않는다.)

          textOnly=><tag>text만 쓸수 있다</tag>이렇게만 쓸수 있다.

          eltOnly =><tag>

                      <sub tag>text가능</subtag>

                    </tag>이것만 가능.

          mixed=>혼합형

©dt:type

: dt:type=string 이렇게 쓰므로써 text가 어떤 type이 되야하는지를 가리킨다.

          쓸수 있는 type은 아래와 같다

 

 

 

boolean

0 or 1, where 0 == "false" and 1 =="true".

char

String, one character long.

date

Date in a subset ISO 8601 format, without the time data. For example: "1994-11-05".

dateTime

Date in a subset of ISO 8601 format, with optional time and no optional zone. Fractional seconds can be as precise as nanoseconds. For example, "1988-04-07T18:39:09".

float

Real number, with no limit on digits; can potentially have a leading sign, fractional digits, and optionally an exponent. Punctuation as in U.S. English. Values range from 1.7976931348623157E+308 to 2.2250738585072014E-308.

int

Number, with optional sign, no fractions, and no exponent.

number

Number, with no limit on digits; can potentially have a leading sign, fractional digits, and optionally an exponent. Punctuation as in U.S. English. (Values have same range as most significant number, R8, 1.7976931348623157E+308 to 2.2250738585072014E-308.)

time

Time in a subset ISO 8601 format, with no date and no time zone. For example: "08:15:27".

entity

Represents the XML ENTITY type.

entities

Represents the XML ENTITIES type.

enumeration

Represents an enumerated type (supported on attributes only).

id

Represents the XML ID type.

idref

Represents the XML IDREF type.

idrefs

Represents the XML IDREFS type.

nmtoken

Represents the XML NMTOKEN type.

nmtokens

Represents the XML NMTOKENS type.

notation

Represents a NOTATION type.

string

Represents a string type.


©model:

openor close둘중에 하나의 값을 갖는다.

<ElementType name=연습 model=open or close>

 open 일경우 다른 schema에서 element를 가져올 수 있다. 즉 여기 정의된 구조에는 없지만 부가적인 element가 붙을 수도 있다는 것이다.

ex) <ElementType name=first>

       <element type=second/>

 </ElementType >

//1 schema

<ElementType name=additional>

</ElementType >

//2 schema

<first namespace=x-schema:1schema namespace=x-schema:2schema>

  <second>연습이다</second>

  <2:additional>이것이 open이다</2:additional>

</first>

©order

 order=”one” or “seq” or “many”

one:하나의 element set만 나와야 한다<!ELEMENT(A,B)>

seq:순서를 꼭 지켜야 한다=<!ELEMENT (A,B)+>

many:나오든 말든 상관 없음.<!ELEMENT (A?,B?)>

 

¨AttributeType

<AttributeType
    default="default-value" ßdefault 가지는 
    dt:type="primitive-type" <-entity, entities, enumeration, id, idref, idrefs, nmtoken, nmtokens, notation, or string. 가질수 있다.
    dt:values="enumerated-values" ßtype enumeration일때 가질수 있는  나열
    name="idref" ßattribute 이름
    required="{yes | no}" >ßelement상에  나타나야 하는지 아닌지 일러줌
ex>
<AttributeType name="colors" dt:type="enumeration"
   dt:values="red green blue">
 

 ¨element (ElementType 안에서만 나온다.)

<element
    type="element-type" ß ElementType 으로 정의된 element name
    [minOccurs="{0 | 1}"] <-0이면  element  optional한걸 알수 있다.
    [maxOccurs="{1 | *}"] ß1이면 최대한 1번이고 *이면 unlimit
>

<!ELEMENT A (C,D,E)>할때 C,D,E를 말한다.

 

¨attribute =<!ATTLIST a attname>

 <attribute
    default="default-value" 
    type="attribute-type"
    [required="{yes | no}"] > 

 

 역시 속한 ElementType에서만 나온다.

 <ElementType name=”a”>

<attribute type=”att_name” default=”red” >

</ ElementType>


¨group

<group
    maxOccurs="{1 | *}" 
    minOccurs="{0 | 1}" 
    order="{one | seq | many}" >

 ex>


 
 
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
 
 
 
  
 

 
  
  

x1,y1을 하나의 set로 묶는다.

<ElementType name="x" order="one">

 
  
  
  
  
  
  
  
  
  
  
  
  
 
 
 
  
  
 
  <group order="seq">
    <element type="x1">
    <element type="y1">
</group>
</ElementType>       

  order예를 들어보자.

   order one일때

<ElementType name="z" order="one">
<element type="x">
<element type="y">
</ElementType>
xml  
<z>
  <x/> 
<y></y>
</z>

seq

<ElementType name="x" order="one">
  <group order="seq">
    <element type="x1">
    <element type="y1">
  </group>
  <group order="seq">
    <element type="x2">
    <element type="y2">
  </group>
</ElementType>

The following two examples represent legal instances of this schema:

<x>
   <x1/> 
   <y1/>
</x>
and: 
<x>
   <x2/>
   <y2/>
</x>

The following example demonstrates the "many" setting:

<ElementType name="x" content="eltOnly" order="many">
    <element type='q'>
    <element type='r'>
</ElementType>

The following five examples represent all legal instances for this schema:

<x> </x>
<x> <q> </x>
<x> <r> </x>
<x> <q> <r> </x>
<x> <r> <q> </x>

schema 예를 보자

<Schema xmlns="urn:schemas-microsoft-com:xml-data" 
  xmlns:dt="urn:schemas-microsoft-com:datatypes">
  <AttributeType name='studentID' dt:type='string' required='yes'/>
  <ElementType name='name' content='textOnly'/>
  <ElementType name='GPA' content='textOnly' dt:type='float'/>
  <ElementType name='student' content='mixed'>
    <attribute type='studentID'/>
    <element type='name'/>
    <element type='GPA'/>
  </ElementType>
  <ElementType name='class' content='eltOnly'>
    <element type='student'/>
  </ElementType>  
</Schema>
문제>아래 xml파일을 만족시킬 schema 만들어보세요.
<order>
  <customer>
    <name>Fidelma McGinn</name>
    <phone_number>425-655-3393</phone_number>
  </customer>
  <item>
    <number>5523918</number>
    <description>shovel</description>
    <price>39.99<price>
  </item>
  <date_of_purchase>1998-10-23</date_of_purchase>
  <date_of_delivery>1998-11-03</date_of_delivery>
</order>

여러 개의 답이 나올수 있습니다.

나의 답

<Schema xmlns="urn:schemas-microsoft-com:xml-data"   xmlns:dt="urn:schemas-microsoft-com:datatypes">

 <ElementType name=”order” content=”eltOnly” order=”seq”>

  <element type=”customer” minOccurs=”1” maxOccurs=”1”/>

  <element type=”item” minOccurs=”1” maxOccurs=”1”/>

  <element type=”date_of_purchase” minOccurs=”1” maxOccurs=”1”/>

<element type=”date_of_delivery” minOccurs=”1” maxOccurs=”1”/>

   </ElementType>

   <ElementType name=”customer” content=”eltOnly” order=”seq”>

      <element type=”name” minOccurs=”1” maxOccurs=”1”/>

<element type=”phone_number” minOccurs=”1” maxOccurs=”1”/>

     </ElementType>

     <ElementType name=”item” content=”eltOnly” order=”seq”>

      <element type=”number” minOccurs=”1” maxOccurs=”1”/>

<element type=”description” minOccurs=”1” maxOccurs=”1”/>

<element type=”price” minOccurs=”1” maxOccurs=”1”/>

</ElementType>

<ElementType name=”date_of_purchase” content=”textOnly” order=”seq” dt:datatype=”date”/>

<ElementType name=”date_of_delivery” content=”textOnly” order=”seq” dt:datatype=”date”/>

<ElementType name=”name” content=”textOnly” order=”seq” dt:datatype=”string”/>

<ElementType name=”phone_number” content=”textOnly” order=”seq” dt:datatype=”string”/>

<ElementType name=”number” content=”textOnly” order=”seq” dt:datatype=”number”/>

<ElementType name=”description” content=”textOnly” order=”seq” dt:datatype=”string”/>

<ElementType name=”price” content=”textOnly” order=”seq” dt:datatype=”float”/>

</Schema>