Bob Foster <[EMAIL PROTECTED]> wrote on 08/05/2005 11:12:07 AM:

> Excuse me, but if you set the parser so it does DTD _and_ schema 
> validation, then the document must be both DTD-valid and schema valid?

Well, not exactly. With the dynamic validation feature turned on, the 
document will only be DTD validated if it has a DTD. Similarly a schema 
(more specifically an element declaration for the validation root) must be 
found for schema validation to be performed. If the document has both a 
DTD and schema it will be DTD validated and schema validated. If it has 
neither then no validation is performed.

> Is this really a configuration people want?

It seems like a reasonable configuration if you want to optionally 
validate based on whether a grammar is available.

> Bob Foster
> 
> 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]
> 

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]

Reply via email to