You are viewing a plain text version of this content. The canonical link for it is here.
Posted to j-users@xerces.apache.org by Michael Glavassevich <mr...@ca.ibm.com> on 2008/03/10 21:55:36 UTC

Re: How To Configure a Schema Validating Parser for Use With JAXP

Hi Eliot,

Eliot Kimber <ek...@reallysi.com> wrote on 03/10/2008 03:46:12 PM:

> I need to process schema-based documents with Saxon where the documents
> need to have default attribute values that are only in the schema (these
> happen to be DITA documents where the processing depends on the values
> of the common class= attribute which normally never exists in instances).
>
> I'm using Xerces as the parser by using these two JVM args:
>
> -Djavax.xml.parsers.DocumentBuilderFactory=org.apache.xerces.jaxp.
> DocumentBuilderFactoryImpl
> -Djavax.xml.parsers.SAXParserFactory=org.apache.xerces.jaxp.
> SAXParserFactoryImpl
>
> That makes Xerces the parser but does not, by itself, turn on schema
> validation.
>
> I added this arg:
>
> -Dorg.apache.xerces.xni.parser.XMLParserConfiguration=org.apache.
> xerces.parsers.StandardParserConfiguration
>
> But it had no apparent affect. In particular, the default attribute
> values were not being passed through to Saxon.

All you've done by setting that property is specify a parser configuration
which is capable of performing schema validation. You still need to turn
the feature on programmatically.

> I feel like I should be able to do this completely from the command line
> by setting the appropriate JVM parameters but so far I have not been
> able to and I'm not sure if it's user error or a missing feature of
Xerces.
>
> My fallback was to create a simple subclass of SaxParserFactoryImpl and
> set the schema validation property there, which works (I'm now seeing
> the default attribute values). But I was really hoping to avoid having
> to maintain a custom class (with all the deployment complexity that
> implies) if I can do everything from the command line.
>
> My expectation was that I would be able to use JVM args to set all the
> relevant Xerces parser properties or, failing that, create a
> configuration properties file. But I see nothing the Xerces docs that
> suggest either approach is supported.
>
> So my questions are:
>
> 1. Is there a way to configure Xerces to do schema validation for
> JAXP-based parser users from the command line?

There isn't and in general there's no way to accomplish that with Xerces
other features.

> 2. If not, why not?

No one asked for it. Also, using system properties to configure the parser
may be a convenient solution but it can create more problems [1].

> Thanks,
>
> Eliot
>
> --
> Eliot Kimber
> Senior Solutions Architect
> "Bringing Strategy, Content, and Technology Together"
> Main: 610.631.6770
> www.reallysi.com
> www.rsuitecms.com
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: j-users-unsubscribe@xerces.apache.org
> For additional commands, e-mail: j-users-help@xerces.apache.org

Thanks.

[1] http://issues.apache.org/jira/browse/XERCESJ-976

Michael Glavassevich
XML Parser Development
IBM Toronto Lab
E-mail: mrglavas@ca.ibm.com
E-mail: mrglavas@apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: j-users-unsubscribe@xerces.apache.org
For additional commands, e-mail: j-users-help@xerces.apache.org


Re: [Resolved] How To Configure a Schema Validating Parser for Use With JAXP

Posted by Eliot Kimber <ek...@reallysi.com>.
This class seems to do what I want given that I can't do what I want 
from the command line.

But this seems like it would be a really common combination, namely 
schema validation and catalog resolution but I couldn't find an example 
of this combination anywhere. It would make really useful convenience 
class in the Xerces distribution. It could even look for some 
class-specific system properties to configure the specific validation 
settings (I have validation turned off but schema processing turned on 
since I only want the attribute value defaults and I don't want invalid 
docs to kill my process).


--- Start SchemaValidatingCatalogResolvingXMLReader.java ---
package org.example.xerces;

import org.apache.xml.resolver.CatalogManager;
import org.apache.xml.resolver.tools.ResolvingXMLReader;
import org.xml.sax.SAXNotRecognizedException;

/**
  *
  */
public class SchemaValidatingCatalogResolvingXMLReader extends
		ResolvingXMLReader {

	/**
	 * @throws Throwable
	 * @throws SAXNotRecognizedException
	 *
	 */
	public SchemaValidatingCatalogResolvingXMLReader() throws 
SAXNotRecognizedException, Throwable {
		super();
		init();
	}

	/**
	 * @throws Throwable
	 * @throws SAXNotRecognizedException
	 *
	 */
	private void init() throws SAXNotRecognizedException, Throwable {
		System.err.println(" + INFO: Using " + this.getClass().getName());
		this.setFeature("http://xml.org/sax/features/validation", false);
		this.setFeature("http://apache.org/xml/features/validation/schema", true);
		this.setFeature("http://apache.org/xml/features/validation/dynamic", 
true);
	}

	/**
	 * @param catalogManager
	 * @throws Throwable
	 * @throws SAXNotRecognizedException
	 */
	public SchemaValidatingCatalogResolvingXMLReader(CatalogManager 
catalogManager) throws SAXNotRecognizedException, Throwable {
		super(catalogManager);
		init();
	}

}
--- end Java class ---



-- 
Eliot Kimber
Senior Solutions Architect
"Bringing Strategy, Content, and Technology Together"
Main: 610.631.6770
www.reallysi.com
www.rsuitecms.com

---------------------------------------------------------------------
To unsubscribe, e-mail: j-users-unsubscribe@xerces.apache.org
For additional commands, e-mail: j-users-help@xerces.apache.org


Re: How To Configure a Schema Validating Parser for Use With JAXP

Posted by Eliot Kimber <ek...@reallysi.com>.
keshlam@us.ibm.com wrote:
>  >Hmm. I can see the point about properties affecting everything running
>  >under a single JVM in an app server but it still seems like there ought
>  >to be a convenient way to do this from the command line where the JVM
>  >instance is of course only going to apply to the one process being run.
> 
> If you're talking about command line, you're taking about an application 
> launched from the command line, right?
> 
> Have that application set the parser appropriately. Or have it take an 
> option which sets this appropriately.

I'm running Saxon from the command line. So I have no direct control 
over it.

But what I can do is use JAXP to set the parser that Saxon uses.

Cheers,

Eliot

-- 
Eliot Kimber
Senior Solutions Architect
"Bringing Strategy, Content, and Technology Together"
Main: 610.631.6770
www.reallysi.com
www.rsuitecms.com

---------------------------------------------------------------------
To unsubscribe, e-mail: j-users-unsubscribe@xerces.apache.org
For additional commands, e-mail: j-users-help@xerces.apache.org


Re: How To Configure a Schema Validating Parser for Use With JAXP

Posted by ke...@us.ibm.com.
>Hmm. I can see the point about properties affecting everything running
>under a single JVM in an app server but it still seems like there ought
>to be a convenient way to do this from the command line where the JVM
>instance is of course only going to apply to the one process being run.

If you're talking about command line, you're taking about an application
launched from the command line, right?

Have that application set the parser appropriately. Or have it take an
option which sets this appropriately.

______________________________________
"... Three things see no end: A loop with exit code done wrong,
A semaphore untested, And the change that comes along. ..."
  -- "Threes" Rev 1.1 - Duane Elms / Leslie Fish
(http://www.ovff.org/pegasus/songs/threes-rev-11.html)

Re: How To Configure a Schema Validating Parser for Use With JAXP

Posted by Eliot Kimber <ek...@reallysi.com>.
Michael Glavassevich wrote:
>> So my questions are:
>>
>> 1. Is there a way to configure Xerces to do schema validation for
>> JAXP-based parser users from the command line?
> 
> There isn't and in general there's no way to accomplish that with Xerces
> other features.
> 
>> 2. If not, why not?
> 
> No one asked for it. Also, using system properties to configure the parser
> may be a convenient solution but it can create more problems [1].

Hmm. I can see the point about properties affecting everything running 
under a single JVM in an app server but it still seems like there ought 
to be a convenient way to do this from the command line where the JVM 
instance is of course only going to apply to the one process being run.

I guess my disconnect is what is the point of having the ability to 
specify a *parser* class using a system property if you can't also 
configure the parser using system properties.

Maybe I'm just looking in the wrong place but I've spent all day trying 
to find a clear and simple description of how to create a standalone 
Xerxes-based SAX parser instance that can be used via the JAXP API and 
will do schema validation (and also catalog-based schema component 
resolution).

So far I have not been able to find that simple thing--all the docs I've 
found are in the context of creating a parser and then using it 
immediately in ones own code, not creating a parser class that will then 
be used by JAXP parser users (e.g., Saxon).

Part of my frustration is that I know I only need to set a couple of 
properties but I'm having a hard time figuring out how to do that in a 
simple way.

Cheers,

Eliot

-- 
Eliot Kimber
Senior Solutions Architect
"Bringing Strategy, Content, and Technology Together"
Main: 610.631.6770
www.reallysi.com
www.rsuitecms.com

---------------------------------------------------------------------
To unsubscribe, e-mail: j-users-unsubscribe@xerces.apache.org
For additional commands, e-mail: j-users-help@xerces.apache.org