2012-07-11 3 views
1

내가는 XML과 같은 문서가 있습니다옵션 요소 유형 DTD

<?xml version="1.0" encoding="UTF-8" ?> 
<!DOCTYPE school SYSTEM ""> 
<school> 
    <data> 
     <id> 
      <uid>1</uid> 
     </id> 
     <information> 
      <name>Michael</name> 
      <surename>Julius</surename> 
     </information> 
     <note> 
      <test>hans</test> 

     </note> 
    </data> 
</school> 

과 DTD 파일을

<!ELEMENT school (data)> 
<!ELEMENT data (id,information,note)> 
<!ELEMENT id (uid)> 
<!ELEMENT uid (#PCDATA)> 
<!ELEMENT information (name,surename?)> 
<!ELEMENT name (#PCDATA)> 
<!ELEMENT surename (#PCDATA)> 
<!ELEMENT note (#PCDATA)> <--- unknown element type 

내가 좋아하는 선택적 요소 유형으로 <note> 요소를 정의 할

<note> 
    <test2>test2</test2> 
</note> 

또는

<note> 
    <unknown name></unknown name> 
</note> 

어떤 도움이 필요합니까? thankz

답변

1

note의 요소 선언에 ANY을 사용할 수 있습니다. 이렇게하면 모든 요소가 note의 하위 요소가 될 수 있지만 해당 요소도 정의되어야합니다 (요소 선언이 있어야 함). 정의되지 않은 요소를 가질 수 없습니다.

note 선언 :

<!ELEMENT note ANY> 

예 인스턴스 (이것은 테스트 쉬웠다 때문에 DTD는 외부에있을 수 있지만 내부 서브 세트를 사용)

<!DOCTYPE school [ 
<!ELEMENT school (data)> 
<!ELEMENT data (id,information,note)> 
<!ELEMENT id (uid)> 
<!ELEMENT uid (#PCDATA)> 
<!ELEMENT information (name,surename?)> 
<!ELEMENT name (#PCDATA)> 
<!ELEMENT surename (#PCDATA)> 
<!ELEMENT note ANY> 
<!ELEMENT test2 (#PCDATA)><!--The element "test2" still has to be declared.--> 
]> 
<school> 
    <data> 
     <id> 
      <uid>1</uid> 
     </id> 
     <information> 
      <name>Michael</name> 
      <surename>Julius</surename> 
     </information> 
     <note> 
      <test2>hans</test2>   
     </note> 
    </data> 
</school>