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 Bram Vandeputte <br...@cs.kuleuven.be> on 2009/04/24 11:33:36 UTC

external XML schema validation

Hi All,


I am trying to build a customized online validator, and I need the "http://apache.org/xml/properties/external-SchemaLocation 
" property for explicitly defining a schema to validate against, even  
if no schema is provided in the document.

The problem is that I always get a : SAXNotRecognizedException :  
"Property 'http://apache.org/xml/properties/external-SchemaLocation'  
is not recognized.".


I am using Xerces-j 2.9.1 . I have tried it by setting this property  
to the xmlreader and the saxparser itself, but nothing works... Could  
you please tell me what I am doing wrong ?

Here is my code :

System.setProperty("javax.xml.validation.SchemaFactory:http://www.w3.org/2001/XMLSchema 
","org.apache.xerces.jaxp.validation.XMLSchemaFactory");
System 
.setProperty 
("org 
.apache 
.xerces 
.xni 
.parser 
.XMLParserConfiguration 
","org.apache.xerces.parsers.IntegratedParserConfiguration");
String language = XMLConstants.W3C_XML_SCHEMA_NS_URI;

SAXParserFactory spf = SAXParserFactory.newInstance();
spf.setValidating(true);
spf.setNamespaceAware(true);
spf.setFeature("http://apache.org/xml/features/validation/schema",  
true);

parser = spf.newSAXParser();

XMLReader xmlReader = parser.getXMLReader();
xmlReader.setProperty("http://apache.org/xml/properties/external-SchemaLocation 
","http://ltsc.ieee.org/xsd/LOM http://ltsc.ieee.org/xsd/lomv1.0/lomLoose.xsd 
");


Thanks a lot in advance for you help !


greetings,
Bram Vandeputte


--
Bram Vandeputte

Katholieke Universiteit Leuven
Dept. Computer Science
Celestijnenlaan 200A, A03.010
B-3001 Leuven, Belgium

Phone: +32 16 327659
Mob:   +32 474 667796
Fax:   -




Re: external XML schema validation

Posted by Michael Glavassevich <mr...@ca.ibm.com>.
Hi Bram,

Bram Vandeputte <br...@cs.kuleuven.be> wrote on 04/24/2009
05:33:36 AM:

> Hi All,
>
> I am trying to build a customized online validator, and I need the "
> http://apache.org/xml/properties/external-SchemaLocation" property
> for explicitly defining a schema to validate against, even if no
> schema is provided in the document.
>
> The problem is that I always get a : SAXNotRecognizedException :
"Property '
> http://apache.org/xml/properties/external-SchemaLocation' is not
recognized.".
>
> I am using Xerces-j 2.9.1 . I have tried it by setting this property
> to the xmlreader and the saxparser itself, but nothing works...
> Could you please tell me what I am doing wrong ?

The name of the property is
"http://apache.org/xml/properties/schema/external-schemaLocation". You
capitalized the 's' on schemaLocation. That's why it wasn't recognized.

> Here is my code :
>
> System.setProperty("javax.xml.validation.SchemaFactory:http://www.
>
w3.org/2001/XMLSchema","org.apache.xerces.jaxp.validation.XMLSchemaFactory");
> System.setProperty("org.apache.xerces.xni.parser.XMLParserConfiguration",
> "org.apache.xerces.parsers.IntegratedParserConfiguration");
> String language = XMLConstants.W3C_XML_SCHEMA_NS_URI;
>
> SAXParserFactory spf = SAXParserFactory.newInstance();
> spf.setValidating(true);
> spf.setNamespaceAware(true);
> spf.setFeature("http://apache.org/xml/features/validation/schema", true);
>
> parser = spf.newSAXParser();
>
> XMLReader xmlReader = parser.getXMLReader();
> xmlReader.setProperty("http://apache.org/xml/properties/external-
> SchemaLocation","http://ltsc.ieee.org/xsd/LOM http://ltsc.ieee.
> org/xsd/lomv1.0/lomLoose.xsd");
>
> Thanks a lot in advance for you help !

If you're just starting to write your application I'd suggest using the
JAXP Valdation API [1] instead of the Xerces specific features and
properties. You'll get better performance (from the grammar caching) and
more portable code. Should also avoid setting the
"org.apache.xerces.xni.parser.XMLParserConfiguration" system property to
something other than the current default (or one that extends the default)
unless you have a specific reason to do so.
"org.apache.xerces.parsers.IntegratedParserConfiguration" is ancient and
doesn't support many of the features introduced in recent releases.

> greetings,
> Bram Vandeputte
>
>
> --
> Bram Vandeputte
>
> Katholieke Universiteit Leuven
> Dept. Computer Science
> Celestijnenlaan 200A, A03.010
> B-3001 Leuven, Belgium
>
> Phone: +32 16 327659
> Mob:   +32 474 667796
> Fax:   -

Thanks.

[1] http://xerces.apache.org/xerces2-j/faq-pcfp.html#faq-4

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