Dies Koper <[EMAIL PROTECTED]> wrote on 08/09/2005 08:06:08 PM: > Hello, > > If I understand correctly, the properties (features) below are Xerces > specific. Is there a way to do this that works for all JAXP1.2 parsers?
No, the only method for turning on schema validation with JAXP 1.2 is to use the "http://java.sun.com/xml/jaxp/properties/schemaLanguage" property. When you set the schemaLanguage property, JAXP 1.2 parsers must validate against the given schema language only. You either get schema validation if the property is set or DTD validation if it is not set, but you cannot get both. DOM Level 3 supports something similar [1] to the dynamic validation feature but this is only available in JAXP 1.3 parsers. > Thanks, > Dies > > Michael Glavassevich wrote: > > Hello Dies, > > > > When you set the schemaLanguage property to > > http://www.w3.org/2001/XMLSchema only schema validation is performed. If > > you want to configure Xerces so that it performs DTD validation if the > > document has a DTD and/or schema validation if a schema grammar is > > specified, try setting the validation [1], schema validation [2] and > > dynamic validation [3] features to true. > > > > [1] http://xml.apache.org/xerces2-j/features.html#validation > > [2] http://xml.apache.org/xerces2-j/features.html#validation.schema > > [3] http://xml.apache.org/xerces2-j/features.html#validation.dynamic > > > > Dies Koper <[EMAIL PROTECTED]> wrote on 08/03/2005 09:26:38 PM: > > > > > >>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] > >> > > > > > > Michael Glavassevich > > XML Parser Development > > IBM Toronto Lab > > E-mail: [EMAIL PROTECTED] > > E-mail: [EMAIL PROTECTED] > > > > > > --------------------------------------------------------------------- > > To unsubscribe, e-mail: [EMAIL PROTECTED] > > For additional commands, e-mail: [EMAIL PROTECTED] > > > > > > > --------------------------------------------------------------------- > To unsubscribe, e-mail: [EMAIL PROTECTED] > For additional commands, e-mail: [EMAIL PROTECTED] > [1] http://www.w3.org/TR/DOM-Level-3-Core/core.html#parameter-validate-if-schema Michael Glavassevich XML Parser Development IBM Toronto Lab E-mail: [EMAIL PROTECTED] E-mail: [EMAIL PROTECTED] --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
