Code example for XMLReader

Methods: parse, setEntityResolver, setProperty

0
        try 
        { 
            SAXParserFactory factory = SAXParserFactory.newInstance();
            SAXParser parser = factory.newSAXParser();
            XMLReader reader = parser.getXMLReader();
            reader.setEntityResolver(new XmlEntityResolver());
            DtdHandler dtdHandler = new DtdHandler();
            try 
            { 
                reader.setProperty("http://xml.org/sax/properties/declaration-handler", dtdHandler);
            } 
            catch (SAXNotRecognizedException e)
            { 
                throw new SAXException(e);
            } 
             
            String xml = "<!DOCTYPE dummy SYSTEM \"" + systemId + "\"><dummy/>";
            reader.parse(new InputSource(new ByteArrayInputStream(xml.getBytes())));
            this.elementOrders = dtdHandler.getElementOrders();
        } 
        catch (IOException e)
        { 
            throw new DtdParseException("Failed to read dtd", e);