Hello all, I am trying to parse xml files, that are either DTD or schema based. I expected the parser to automatically determine whether the files are DTD or schema based when it parses them and validate them accordingly, but I can't get it to work.
It validates my DTD based file fine, I then need to set the "http://java.sun.com/xml/jaxp/properties/schemaLanguage" attribute to "http://www.w3.org/2001/XMLSchema" to be able to read the schema based file, that also works fine. But with this attribute set I cannot read the DTD based file anymore, it gives the following error: org.xml.sax.SAXParseException: cvc-elt.1: Cannot find the declaration of element 'ejb-jar'. I set up the parser as follows: DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); factory.setValidating( true ); factory.setNamespaceAware(true); String JAXP_SCHEMA_LANGUAGE = "http://java.sun.com/xml/jaxp/properties/schemaLanguage"; String W3C_XML_SCHEMA = "http://www.w3.org/2001/XMLSchema"; factory.setAttribute(JAXP_SCHEMA_LANGUAGE, W3C_XML_SCHEMA); DocumentBuilder builder = factory.newDocumentBuilder(); (xercesImpl.jar 2.7.1 and xml-apis.jar are in JDK14\JRE\lib\ext) The xml files look like: [DTD based] <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE ejb-jar PUBLIC "-//Sun Microsystems, Inc.//DTD Enterprise JavaBeans 2.0//EN" "http://java.sun.com/dtd/ejb-jar_2_0.dtd"> <ejb-jar> ... [schema based] <?xml version="1.0" encoding="UTF-8"?> <ejb-jar version="2.1" xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/ejb-jar_2_1.xsd"> ... The culprit seems to be the setting of the attribute: with it schema based files work and DTD based files not, without it the other way around. How should I change my code to be able to parse and validate both? Thanks, Dies --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
