: XML 문서의 구조를 설명하는 역할을 한다.
XSD(XML Schema Definition)라고도 한다.<?xml version="1.0"?>
<note
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="note.xsd">
<to>Eugene</to>
<from>Brown</from>
<heading>Dinner Appointment</heading>
<body>6 PM at Pine Hill</body>
</note>
note : XML 문서의 루트 요소로, note라는 이름을 가진 요소입니다.xmlns:xsi : XML Schema 인스턴스 네임스페이스를 정의한다xsi:noNamespaceSchemaLocation : 이 속성은 XML 문서가 유효성 검사를 받을 스키마의 위치를 지정한다. <?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="note">
<xs:complexType>
<xs:sequence>
<xs:element name="to" type="xs:string" />
<xs:element name="from" type="xs:string" />
<xs:element name="heading" type="xs:string" />
<xs:element name="body" type="xs:string" />
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
xs:schema : XSD 문서의 루트 요소로, XML 스키마의 시작을 나타낸다.xmlns:xs : XML Schema 네임스페이스를 정의한다.xs는 XML 스키마의 접두사로, XSD 문서 내에서 사용되는 모든 요소가 이 네임스페이스에 속함을 의미한다.<xs:element name="note">
xs:element: XML 문서 내에서 사용할 수 있는 요소를 정의한다.name="note": 요소의 이름을 note로 지정한다.<xs:complexType>
<xs:sequence>
xs:complexType: 요소가 복합 타입(하위 요소를 가질 수 있는 타입)임을 나타낸다.xs:sequence: 하위 요소들이 반드시 정의된 순서대로 나타나야 함을 의미한다.<xs:element name="to" type="xs:string" />
<xs:element name="from" type="xs:string" />
<xs:element name="heading" type="xs:string" />
<xs:element name="body" type="xs:string" />
xs:element는 note 요소의 하위 요소들을 정의한다.name: 요소의 이름을 지정한다.type: 요소의 데이터 타입을 지정한다. 여기서는 모두 xs:string으로, 문자열 데이터를 나타낸다.: 이 XML 스키마는 note라는 요소를 정의하며, 그 안에는 to, from, heading, body라는 네 개의 문자열 타입의 하위 요소가 순서대로 포함되어야 한다. 이 스키마를 사용하여 XML 문서가 올바른 구조를 따르고 있는지 검증할 수 있다.
: https://www.freeformatter.com/xml-validator-xsd.html
: XML 문서의 법적 빌딩 블록을 정의하는 것이다.
: 요소의 값을 고정시키고, 정의된 고정값으로만 설정할 수 있고, 다른 값으로 변경할 수 없다.
: title이라는 이름의 element는 'fixedValue'라는 고정값을 가진다.
<?xml version="1.0"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="workProgress">
<xs:complexType>
<xs:sequence>
<xs:element name="title" type="xs:string" fixed="fixedValue" />
<xs:element name="phase" type="xs:string" />
<xs:element name="importance" type="xs:decimal" />
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
: 요소에 대한 기본값을 정의한다. 이 기본값을 해당 요소가 명시적으로 지정되지 않은 경우 사용된다.
: title이라는 이름의 element는 'defaultValue'라는 기본값을 가진다.
<?xml version="1.0"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="workProgress">
<xs:complexType>
<xs:sequence>
<xs:element name="title" type="xs:string" default="defaultValue" />
<xs:element name="phase" type="xs:string" />
<xs:element name="importance" type="xs:decimal" />
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
