XML문서는 DTD나 XML스키마를 참조할 수 있다.
exam.xml
<?xml version="1.0"?>
<exam>
<questions>
<question>
다음 중 옳은 것은?
<example>
1.
</example>
<example>
1.
</example>
<answer>
1.
</answer>
<solution>
따라서...
</solution>
</question>
</questions>
</exam>
exam.dtd
<!ELEMENT exam (questions+)>
<!ELEMENT questions (question*)>
<!ELEMENT question (#PCDATA|example|answer|solution)*>
<!ELEMENT example (#PCDATA)>
<!ELEMENT answer (#PCDATA)>
<!ELEMENT solution (#PCDATA)>
exam.xsd
<?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="exam">
<xs:complexType>
<xs:sequence>
<xs:element name="questions">
<xs:complexType>
<xs:sequence>
<xs:element name="question" type="questionType" maxOccurs="unbounded"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:complexType name="questionType" mixed="true">
<xs:sequence>
<xs:element name="example" type="xs:string" maxOccurs="unbounded"/>
<xs:element name="answer" type="xs:string"/>
<xs:element name="solution" type="xs:string"/>
</xs:sequence>
</xs:complexType>
</xs:schema>
DTD참조
<?xml version="1.0"?>
<!DOCTYPE exam SYSTEM
"http://localhost/xml/exam.dtd">
<exam>
<questions>
<question>
다음 중 옳은 것은?
<example>
1.
</example>
<example>
1.
</example>
<answer>
1.
</answer>
<solution>
따라서...
</solution>
</question>
</questions>
</exam>
XSD참조
<?xml version="1.0"?>
<exam
xmlns="http://www.w3schools.com"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://localhost exam.xsd">
<questions>
<question>
다음 중 옳은 것은?
<example>
1.
</example>
<example>
1.
</example>
<answer>
1.
</answer>
<solution>
따라서...
</solution>
</question>
</questions>
</exam>
댓글
댓글 쓰기