// Copyright (c) Keith D Gregory, all rights reserved
package com.kdgregory.example.xml.parsing;

import java.io.InputStream;

import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;

import org.w3c.dom.Document;

import org.xml.sax.InputSource;


public class DTDValidatedParsing
{
    public static void main(String[] argv) throws Exception
    {
        // this resource is opened here to separate the mechanics of finding it from the process of using it
        // note that the parser is responsible for closing the stream
        InputStream xml = Thread.currentThread().getContextClassLoader().getResourceAsStream("albumsWithEmbeddedDoctype.xml"); 

        DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
        dbf.setNamespaceAware(true);
        dbf.setValidating(true);

        DocumentBuilder db = dbf.newDocumentBuilder();

        Document dom = db.parse(new InputSource(xml));

        System.out.println("root element name = " + dom.getDocumentElement().getNodeName());
    }
}
