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 Bob Foster <bo...@objfac.com> on 2005/05/17 19:21:23 UTC
How to use entities with XML Schema?
Several customers want to validate with XML Schema but still use general
entities for shorthand. I'm not having much luck finding the magic
combination of Xerces features that makes this work. E.g.,
SAXParser parser = new SAXParser(symbolTable, grammarPool);
parser.setEntityResolver(er);
parser.setErrorHandler(eh);
try {
parser.setFeature("http://xml.org/sax/features/namespaces", true);
parser.setFeature("http://xml.org/sax/features/validation", true);
parser.setFeature("http://apache.org/xml/features/validation/schema",
true);
parser.setFeature("http://apache.org/xml/features/validation/schema-full-checking",
true);
InputSource in = new InputSource(docReader);
in.setSystemId(docUri);
parser.parse(in);
...
With the above, validation is always done from the DTD, ignoring the
schema explicitly declared in the document with xsi:schemaLocation. If I
change "http://xml.org/sax/features/validation" to false, no validation
is done at all.
Help greatly appreciated!
Bob Foster
---------------------------------------------------------------------
To unsubscribe, e-mail: j-users-unsubscribe@xerces.apache.org
For additional commands, e-mail: j-users-help@xerces.apache.org
Re: How to use entities with XML Schema?
Posted by Bob Foster <bo...@objfac.com>.
Elliotte Harold wrote:
> Bob Foster wrote:
>> Nope. If you have a DOCTYPE with either an internal or external DTD,
>> Xerces validates against the DTD.
>
> Not necessarily true. You can tell Xerces to read the DTD but not
> validate or not to read the external DTD subset at all. I forget which
> mode is the default, but I don't think it's validating.
This statement was in the validation-on context, which is currently
needed to turn on XML Schema validation. But you're right, it's the
default behavior but not necessarily true, as other postings have shown.
Bob Foster
---------------------------------------------------------------------
To unsubscribe, e-mail: j-users-unsubscribe@xerces.apache.org
For additional commands, e-mail: j-users-help@xerces.apache.org
Re: How to use entities with XML Schema?
Posted by Elliotte Harold <el...@metalab.unc.edu>.
Bob Foster wrote:
> Nope. If you have a DOCTYPE with either an internal or external DTD,
> Xerces validates against the DTD.
>
Not necessarily true. You can tell Xerces to read the DTD but not
validate or not to read the external DTD subset at all. I forget which
mode is the default, but I don't think it's validating.
--
Elliotte Rusty Harold elharo@metalab.unc.edu
XML in a Nutshell 3rd Edition Just Published!
http://www.cafeconleche.org/books/xian3/
http://www.amazon.com/exec/obidos/ISBN=0596007647/cafeaulaitA/ref=nosim
---------------------------------------------------------------------
To unsubscribe, e-mail: j-users-unsubscribe@xerces.apache.org
For additional commands, e-mail: j-users-help@xerces.apache.org
Re: How to use entities with XML Schema?
Posted by Bob Foster <bo...@objfac.com>.
George Cristian Bina wrote:
> Hi Neil, Bob,
>
> > I haven't actually tried this, but what happens if you use the JAXP
> > property "http://java.sun.com/xml/jaxp/properties/schemaLanguage",
> set to
> > "http://www.w3.org/2001/XMLSchema"?
>
> It works, I replied to Bob with the same advise about two months ago:
> http://marc.theaimsgroup.com/?l=xerces-j-dev&m=111156796913646&w=2
Missed this part on first reading. Actually, it doesn't work, or rather
it's an incomplete recipe, as later postings show.
Bob
---------------------------------------------------------------------
To unsubscribe, e-mail: j-users-unsubscribe@xerces.apache.org
For additional commands, e-mail: j-users-help@xerces.apache.org
Re: How to use entities with XML Schema?
Posted by Bob Foster <bo...@objfac.com>.
Thanks for the suggestion! This works (in a Xerces SAXParser, as well)
if you also set the feature
"http://xml.org/sax/features/external-general-entities " to true. (The
space at the end seems to be required.)
The Xerces-specific code that I used is:
SAXParser parser = new SAXParser(symbolTable, grammarPool);
parser.setEntityResolver(er);
parser.setErrorHandler(eh);
try {
parser.setFeature(Xerces2Constants.NAMESPACES_FEATURE_ID, true);
parser.setFeature(Xerces2Constants.VALIDATION_FEATURE_ID, true);
parser.setFeature(Xerces2Constants.SCHEMA_VALIDATION_FEATURE_ID, true);
parser.setFeature(Xerces2Constants.SCHEMA_FULL_CHECKING_FEATURE_ID,
true);
// this will allow the parser not to emit DTD-related
// errors, as the jaxp spec demands
parser.setProperty(
"http://java.sun.com/xml/jaxp/properties/schemaLanguage",
"http://www.w3.org/2001/XMLSchema");
// This causes the external subset to be parsed.
parser.setFeature(
"http://xml.org/sax/features/external-general-entities ", true);
InputSource in = new InputSource(docReader);
in.setSystemId(docUri);
parser.parse(in);
...
The first comment is copied out of the Xerces implementation.
Bob
George Cristian Bina wrote:
> Hi Neil, Bob,
>
> > I haven't actually tried this, but what happens if you use the JAXP
> > property "http://java.sun.com/xml/jaxp/properties/schemaLanguage",
> set to
> > "http://www.w3.org/2001/XMLSchema"?
>
> It works, I replied to Bob with the same advise about two months ago:
> http://marc.theaimsgroup.com/?l=xerces-j-dev&m=111156796913646&w=2
>
> [Bob]
> > A number of XML editors have started supporting this no
> > concept, raising user expectations this is a valid combination.
>
> Well, we added support for this at users requests more that a year ago I
> think.
>
> Best Regards,
> George
> ---------------------------------------------------------------------
> George Cristian Bina
> <oXygen/> XML Editor, Schema Editor and XSLT Editor/Debugger
> http://www.oxygenxml.com
>
>
> Neil Graham wrote:
>
>> Hi Bob,
>>
>> I haven't actually tried this, but what happens if you use the JAXP
>> property "http://java.sun.com/xml/jaxp/properties/schemaLanguage", set
>> to "http://www.w3.org/2001/XMLSchema"? If you set isValidating to
>> true on a SAXParserFactory, and set this property on the SAXParser
>> instance, I believe you should get the behaviour you desire.
>>
>> Cheers,
>> Neil
>> Neil Graham
>> Manager, XML Parser Development
>> IBM Toronto Lab
>> Phone: 905-413-3519, T/L 969-3519
>> E-mail: neilg@ca.ibm.com
>>
>>
>>
>>
>>
>> Bob Foster <bo...@objfac.com> 05/18/2005 02:14 AM
>> Please respond to
>> j-users
>>
>>
>> To
>> j-users@xerces.apache.org
>> cc
>>
>> Subject
>> Re: How to use entities with XML Schema?
>>
>>
>>
>>
>>
>>
>> Joseph Kesselman wrote:
>>
>>> Schema has no concept of entities, so to do this you have to validate
>>> against a DTD (or an internal subset) to expand the entities, then
>>
>>
>> validate
>>
>>> again against the schema. I _think_ simply turning on both kinds of
>>> validation and having the proper doctype in the source file will do the
>>> right thing.
>>
>>
>>
>> Nope. If you have a DOCTYPE with either an internal or external DTD,
>> Xerces validates against the DTD.
>>
>>
>>> Officially (officiously?), the folks who designed schemas expect us to
>>
>>
>> stop
>>
>>> using entities and migrate to some other variety of macro/external-data
>>> reference.
>>
>>
>>
>> Not their problem, eh?
>>
>> It's mine. A number of XML editors have started supporting this no
>> concept, raising user expectations this is a valid combination.
>>
>> Bob Foster
---------------------------------------------------------------------
To unsubscribe, e-mail: j-users-unsubscribe@xerces.apache.org
For additional commands, e-mail: j-users-help@xerces.apache.org
Re: How to use entities with XML Schema?
Posted by George Cristian Bina <ge...@sync.ro>.
Hi Neil, Bob,
> I haven't actually tried this, but what happens if you use the JAXP
> property "http://java.sun.com/xml/jaxp/properties/schemaLanguage",
set to
> "http://www.w3.org/2001/XMLSchema"?
It works, I replied to Bob with the same advise about two months ago:
http://marc.theaimsgroup.com/?l=xerces-j-dev&m=111156796913646&w=2
[Bob]
> A number of XML editors have started supporting this no
> concept, raising user expectations this is a valid combination.
Well, we added support for this at users requests more that a year ago I
think.
Best Regards,
George
---------------------------------------------------------------------
George Cristian Bina
<oXygen/> XML Editor, Schema Editor and XSLT Editor/Debugger
http://www.oxygenxml.com
Neil Graham wrote:
> Hi Bob,
>
> I haven't actually tried this, but what happens if you use the JAXP
> property "http://java.sun.com/xml/jaxp/properties/schemaLanguage", set to
> "http://www.w3.org/2001/XMLSchema"? If you set isValidating to true on a
> SAXParserFactory, and set this property on the SAXParser instance, I
> believe you should get the behaviour you desire.
>
> Cheers,
> Neil
> Neil Graham
> Manager, XML Parser Development
> IBM Toronto Lab
> Phone: 905-413-3519, T/L 969-3519
> E-mail: neilg@ca.ibm.com
>
>
>
>
>
> Bob Foster <bo...@objfac.com>
> 05/18/2005 02:14 AM
> Please respond to
> j-users
>
>
> To
> j-users@xerces.apache.org
> cc
>
> Subject
> Re: How to use entities with XML Schema?
>
>
>
>
>
>
> Joseph Kesselman wrote:
>
>>Schema has no concept of entities, so to do this you have to validate
>>against a DTD (or an internal subset) to expand the entities, then
>
> validate
>
>>again against the schema. I _think_ simply turning on both kinds of
>>validation and having the proper doctype in the source file will do the
>>right thing.
>
>
> Nope. If you have a DOCTYPE with either an internal or external DTD,
> Xerces validates against the DTD.
>
>
>>Officially (officiously?), the folks who designed schemas expect us to
>
> stop
>
>>using entities and migrate to some other variety of macro/external-data
>>reference.
>
>
> Not their problem, eh?
>
> It's mine. A number of XML editors have started supporting this no
> concept, raising user expectations this is a valid combination.
>
> Bob Foster
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: j-users-unsubscribe@xerces.apache.org
> For additional commands, e-mail: j-users-help@xerces.apache.org
>
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: j-users-unsubscribe@xerces.apache.org
> For additional commands, e-mail: j-users-help@xerces.apache.org
>
---------------------------------------------------------------------
To unsubscribe, e-mail: j-users-unsubscribe@xerces.apache.org
For additional commands, e-mail: j-users-help@xerces.apache.org
Re: How to use entities with XML Schema?
Posted by Bob Foster <bo...@objfac.com>.
Thanks. That does indeed suppress validation from the DTD, but the
parser seems to have lost its ability to read the external subset. Given
input like:
schematest.xml:
<!DOCTYPE example SYSTEM "schematest.dtd">
<example xsi:noNamespaceSchemaLocation="schematest.xsd"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<foo/>
&ba;
</example>
where schematest.dtd contains:
<!ENTITY fu "<foo/>">
<!ENTITY ba "<bar/>">
The parser says: 'Error - the entity "ba" was referenced and not
declared". Works fine if you move the entity defs to the internal subset.
Is this in accordance with jaxp? How to get the parser to read the
external subset?
Bob
Neil Graham wrote:
> Hi Bob,
>
> I haven't actually tried this, but what happens if you use the JAXP
> property "http://java.sun.com/xml/jaxp/properties/schemaLanguage", set to
> "http://www.w3.org/2001/XMLSchema"? If you set isValidating to true on a
> SAXParserFactory, and set this property on the SAXParser instance, I
> believe you should get the behaviour you desire.
>
> Cheers,
> Neil
> Neil Graham
> Manager, XML Parser Development
> IBM Toronto Lab
> Phone: 905-413-3519, T/L 969-3519
> E-mail: neilg@ca.ibm.com
>
>
>
>
>
> Bob Foster <bo...@objfac.com>
> 05/18/2005 02:14 AM
> Please respond to
> j-users
>
>
> To
> j-users@xerces.apache.org
> cc
>
> Subject
> Re: How to use entities with XML Schema?
>
>
>
>
>
>
> Joseph Kesselman wrote:
>
>>Schema has no concept of entities, so to do this you have to validate
>>against a DTD (or an internal subset) to expand the entities, then
>
> validate
>
>>again against the schema. I _think_ simply turning on both kinds of
>>validation and having the proper doctype in the source file will do the
>>right thing.
>
>
> Nope. If you have a DOCTYPE with either an internal or external DTD,
> Xerces validates against the DTD.
>
>
>>Officially (officiously?), the folks who designed schemas expect us to
>
> stop
>
>>using entities and migrate to some other variety of macro/external-data
>>reference.
>
>
> Not their problem, eh?
>
> It's mine. A number of XML editors have started supporting this no
> concept, raising user expectations this is a valid combination.
>
> Bob Foster
---------------------------------------------------------------------
To unsubscribe, e-mail: j-users-unsubscribe@xerces.apache.org
For additional commands, e-mail: j-users-help@xerces.apache.org
Re: How to use entities with XML Schema?
Posted by Neil Graham <ne...@ca.ibm.com>.
Hi Bob,
I haven't actually tried this, but what happens if you use the JAXP
property "http://java.sun.com/xml/jaxp/properties/schemaLanguage", set to
"http://www.w3.org/2001/XMLSchema"? If you set isValidating to true on a
SAXParserFactory, and set this property on the SAXParser instance, I
believe you should get the behaviour you desire.
Cheers,
Neil
Neil Graham
Manager, XML Parser Development
IBM Toronto Lab
Phone: 905-413-3519, T/L 969-3519
E-mail: neilg@ca.ibm.com
Bob Foster <bo...@objfac.com>
05/18/2005 02:14 AM
Please respond to
j-users
To
j-users@xerces.apache.org
cc
Subject
Re: How to use entities with XML Schema?
Joseph Kesselman wrote:
> Schema has no concept of entities, so to do this you have to validate
> against a DTD (or an internal subset) to expand the entities, then
validate
> again against the schema. I _think_ simply turning on both kinds of
> validation and having the proper doctype in the source file will do the
> right thing.
Nope. If you have a DOCTYPE with either an internal or external DTD,
Xerces validates against the DTD.
> Officially (officiously?), the folks who designed schemas expect us to
stop
> using entities and migrate to some other variety of macro/external-data
> reference.
Not their problem, eh?
It's mine. A number of XML editors have started supporting this no
concept, raising user expectations this is a valid combination.
Bob Foster
---------------------------------------------------------------------
To unsubscribe, e-mail: j-users-unsubscribe@xerces.apache.org
For additional commands, e-mail: j-users-help@xerces.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: j-users-unsubscribe@xerces.apache.org
For additional commands, e-mail: j-users-help@xerces.apache.org
Re: How to use entities with XML Schema?
Posted by Bob Foster <bo...@objfac.com>.
Joseph Kesselman wrote:
> Schema has no concept of entities, so to do this you have to validate
> against a DTD (or an internal subset) to expand the entities, then validate
> again against the schema. I _think_ simply turning on both kinds of
> validation and having the proper doctype in the source file will do the
> right thing.
Nope. If you have a DOCTYPE with either an internal or external DTD,
Xerces validates against the DTD.
> Officially (officiously?), the folks who designed schemas expect us to stop
> using entities and migrate to some other variety of macro/external-data
> reference.
Not their problem, eh?
It's mine. A number of XML editors have started supporting this no
concept, raising user expectations this is a valid combination.
Bob Foster
---------------------------------------------------------------------
To unsubscribe, e-mail: j-users-unsubscribe@xerces.apache.org
For additional commands, e-mail: j-users-help@xerces.apache.org
Re: How to use entities with XML Schema?
Posted by Joseph Kesselman <ke...@us.ibm.com>.
Schema has no concept of entities, so to do this you have to validate
against a DTD (or an internal subset) to expand the entities, then validate
again against the schema. I _think_ simply turning on both kinds of
validation and having the proper doctype in the source file will do the
right thing.
Officially (officiously?), the folks who designed schemas expect us to stop
using entities and migrate to some other variety of macro/external-data
reference.
______________________________________
Joe Kesselman, IBM Next-Generation Web Technologies: XML, XSL and more.
"The world changed profoundly and unpredictably the day Tim Berners Lee
got bitten by a radioactive spider." -- Rafe Culpin, in r.m.filk
---------------------------------------------------------------------
To unsubscribe, e-mail: j-users-unsubscribe@xerces.apache.org
For additional commands, e-mail: j-users-help@xerces.apache.org