XML 스키마 튜토리얼login
XML 스키마 튜토리얼
작가:php.cn  업데이트 시간:2022-04-20 14:13:02

XML 스키마를 사용하는 방법


XSD 사용 방법?


XML 문서는 DTD 또는 XML 스키마를 참조할 수 있습니다.


간단한 XML 문서:

"note.xml"이라는 이름의 이 XML 문서를 살펴보십시오.

<?xml version="1.0"?>
<note>
<to>토베</to>
<from>자니</from>
<heading>알림</heading>
<body>이번 주말에 저를 잊지 마세요!</body>
</note>


DTD 파일

다음 예는 "note.dtd"라는 DTD 파일입니다. 해당 XML 문서( "note.xml" )는 다음과 같이 정의됩니다.

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

Line 1은 note 요소에 4개의 하위 요소가 있음을 정의합니다. "to, from , 제목, 본문".

라인 2-5는 to, from,heading, body 요소의 유형을 "#PCDATA"로 정의합니다.


XML Schema

다음 예는 위의 XML 문서("note.xml")의 요소를 정의하는 "note.xsd"라는 XML 스키마 파일입니다.

<?xml version= "1.0 "?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
targetNamespace="http://www.w3schools.com"
xmlns="http :/ /www.w3schools.com"
elementFormDefault="qualified">

<xs:element name="note">
​ <xs:복합 유형>
                    <xs:순서>
​​ <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:순서>
​ </xs:complexType>
</xs:element>

</xs:schema>

note 요소는 다른 하위 요소를 포함하므로 복합 유형입니다. 다른 요소(to, from,heading,body)는 다른 요소를 포함하지 않으므로 단순 유형입니다. 다음 장에서는 복합 유형과 단순 유형에 대해 자세히 알아봅니다.


DTD에 대한 참조

이 파일에는 DTD에 대한 참조가 포함되어 있습니다:

<?xml version="1.0"?>

<!DOCTYPE note SYSTEM
"http://www.w3schools. com/dtd/note.dtd">

<note>
<to>토베</to>
<from>자니</from>
<heading>알림</heading>
<body>이번 주말에 저를 잊지 마세요!</body>
</note>


XML 스키마에 대한 참조

이 파일에는 XML 스키마에 대한 참조가 포함되어 있습니다:

< xml version="1.0"?>

<note
xmlns="http://www.w3schools.com"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance "
xsi:schemaLocation="http://www.w3schools.com note.xsd">
<to>토베</to>
<from>자니</from>
<heading>알림</heading>
<body>이번 주말에도 저를 잊지 마세요!</body>
</note>

PHP 중국어 웹사이트