XSD 방법?
XML 문서는 DTD 또는 XML 스키마에 대한 참조를 가질 수 있습니다.
간단한 XML 문서
"note.xml"이라는 간단한 XML 문서를 살펴보세요.
<?xml version="1.0"?>
<note>
<to>Tove</to>
<from>Jani</from>
<heading>Reminder</heading>
<body>Don't forget me this weekend!</body>
</note>
DTD 파일
다음 예제는 위의 XML 문서("note.xml")의 요소를 정의하는 "note.dtd"라는 DTD 파일입니다.
<!ELEMENT note (to, from, heading, body)>
<!ELEMENT to (#PCDATA)>
<!ELEMENT from (#PCDATA)>
<!ELEMENT heading (#PCDATA)>
<!ELEMENT body (#PCDATA)>
첫 번째 줄은 "to, from, 제목, 본문"이라는 네 개의 자식 요소를 갖도록 note 요소를 정의합니다.
2-5행은 to, from, header, body 요소를 "#PCDATA" 유형으로 정의합니다.
XML 스키마로
다음 예제는 위의 XML 문서("note.xml")의 요소를 정의하는 "note.xsd"라는 XML 스키마 파일입니다.
<?xml version="1.0"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
targetNamespace="https://www.w3schools.com"
xmlns="https://www.w3schools.com"
elementFormDefault="qualified">
<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>
note 요소는 다른 요소를 포함하기 때문에 복합 유형 입니다. 다른 요소(to, from, 제목, 본문)는 다른 요소를 포함하지 않기 때문에 단순 유형 입니다. 다음 장에서 단순 유형과 복합 유형에 대해 자세히 알아볼 것입니다.
DTD에 대한 참조
이 XML 문서에는 DTD에 대한 참조가 있습니다.
<?xml version="1.0"?>
<!DOCTYPE note SYSTEM
"https://www.w3schools.com/xml/note.dtd">
<note>
<to>Tove</to>
<from>Jani</from>
<heading>Reminder</heading>
<body>Don't forget me this weekend!</body>
</note>
XML 스키마에 대한 참조
이 XML 문서에는 XML 스키마에 대한 참조가 있습니다.
<?xml version="1.0"?>
<note
xmlns="https://www.w3schools.com"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="https://www.w3schools.com/xml note.xsd">
<to>Tove</to>
<from>Jani</from>
<heading>Reminder</heading>
<body>Don't forget me this weekend!</body>
</note>