Dies Koper <[EMAIL PROTECTED]> wrote on 08/05/2005 02:38:11 AM:

> Hello Michael,
> 
> Thank you. You make it look so easy!
> 
> It seems to work now, but I'd like to confirm a few things:
> 
> I had the following property set:
>    factory.setAttribute(JAXP_SCHEMA_LANGUAGE, W3C_XML_SCHEMA);
> (schemaLanguage set to http://www.w3.org/2001/XMLSchema)
> 
> Do I still need it? It seems to work both with and without it.

No. With the property set, DTD validation won't be performed. To get the 
configuration you need, don't set this property.
 
> I also have the following set:
>    factory.setValidating( true );
> 
> How does this differ from [1]? Do I still need it?
> (I noticed that with this line and without [1], it doesn't validate 
> properly)

Internally, setValidating(true) turns on the validation feature so it 
shouldn't matter whether you call it or explicitly set the feature to 
true.

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

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