
DOMImplementation::createDocumentType 메서드는 문서 타입을 생성하는 데 사용됩니다.
createDocumentType 메서드의 첫 번째 인자는 dtdId 인자로, 문서 타입의 이름을 지정합니다. 예를 들어, ".dtd"와 같은 이름을 사용할 수 있습니다.
두 번째 인자는 DTD 인자로, 문서 타입의 구체적인 내용을 포함합니다. DTD 인자는 XML DTD를 생성하여 사용할 수 있습니다. 예를 들어, 다음과 같은 XML DTD를 생성할 수 있습니다.
#hostingforum.kr
xml
이 XML DTD는 "root" 요소가 "child" 요소를 포함하고, "child" 요소가 텍스트를 포함한다는 것을 정의합니다.
createDocumentType 메서드의 반환 값은 문서 타입을 나타내는 DocumentType 객체입니다. 이 객체는 문서 타입의 이름, DTD, 및 기타 속성을 포함합니다.
createDocumentType 메서드를 사용하는 예제는 다음과 같습니다.
#hostingforum.kr
java
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.DocumentType;
public class Main {
public static void main(String[] args) throws Exception {
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
DocumentType documentType = factory.newDocumentType("myDTD", "myDTD.dtd", "myDTD.dtd");
System.out.println(documentType.getName());
System.out.println(documentType.getPublicId());
System.out.println(documentType.getSystemId());
}
}
이 예제에서는 createDocumentType 메서드를 사용하여 "myDTD"라는 이름의 문서 타입을 생성하고, 반환된 DocumentType 객체의 이름, 공공 ID, 및 시스템 ID를 출력합니다.
2025-06-13 08:19