최신 웹 개발 튜토리얼
 

XSD 사용법?


XML 문서는 DTD 또는 XML 스키마에 대한 참조를 가질 수 있습니다.


간단한 XML 문서

라는이 간단한 XML 문서를 봐 "note.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 파일

다음 예라는 DTD 파일 인 "note.dtd" 상기 XML 문서의 요소를 정의 ("note.xml") :

<!ELEMENT note (to, from, heading, body)>
<!ELEMENT to (#PCDATA)>
<!ELEMENT from (#PCDATA)>
<!ELEMENT heading (#PCDATA)>
<!ELEMENT body (#PCDATA)>

: 첫 번째 줄은 네 자식 요소를 가지고 노트 요소를 정의 "to, from, heading, body" .

선 2-5은이 제목에서, 신체 요소 유형의 수를 정의 "#PCDATA" .


XML 스키마

다음 예 불리는 XML 스키마 파일 "note.xsd" 상기 XML 문서의 요소를 정의 ("note.xml") :

<?xml version="1.0"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
targetNamespace="http://www.w3ii.com"
xmlns="http://www.w3ii.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>

노트 요소는 인 complex type 은 다른 요소가 포함되어 있기 때문이다. 다른 요소 (to, from, heading, body) 있는 simple types 들은 다른 요소를 포함하지 않기 때문에. 다음 장에서 간단하고 복잡한 유형에 대한 자세한 내용을 배울 것입니다.


DTD에 대한 참조

이 XML 문서는 DTD에 대한 참조를 가지고 :

<?xml version="1.0"?>

<!DOCTYPE note SYSTEM
"http://www.w3ii.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="http://www.w3ii.com"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.w3ii.com note.xsd">
  <to>Tove</to>
  <from>Jani</from>
  <heading>Reminder</heading>
  <body>Don't forget me this weekend!</body>
</note>