I have copied your schema and document and attempted validation using Xerces
2.2.
There is a problem in the schema: the element "job" that you define inside the
complexType rslType is *not* qualified. This is because 1) there is no
elementFormDefault="qualified" attribute on your schema element and 2) there
is no form="qualified" attribute on the element declaration itself, inside
the complex type. Schema spec states that in such a case, the element
declaration is assumed to be for an element that is *not* qualified.
In other words, the following document *would* satisfy your schema (and in
fact does with Xerces 2.2):
<?xml version="1.0" encoding="UTF-8"?>
<!-- This declaration has absolutely no effect, so I've removed it:
xmlns:rsl="http://schemas.gridforum.org/gridServices/rsl"
-->
<rsl xmlns="http://schemas.gridforum.org/gridServices/rsl"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://schemas.gridforum.org/gridServices/rsl
schema/test.xsd">
<job xmlns=""> Bastard! </job>
</rsl>
What you probably want however, is to *qualify* the element declaration in
your schema. There are two ways to do this: 1) using an "elementFormDefault"
attribute on the top-level schema element (which essentially qualifies *all*
local element declarations, except those that explicitly contain a "form"
attribute specifying otherwise) or 2) using a "form" attribute on the element
declaration. This means only that particular element will be qualified.
In both cases, you should set the chosen attribute value to "qualified".
Examples:
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
targetNamespace="http://schemas.gridforum.org/gridServices/rsl"
xmlns:rsl="schemas.gridforum.org/gridServices/rsl"
version="0.2"
elementFormDefault="qualified">
...
</xsd:schema>
- or -
(inside complexType "rslType" definition)
...
<xsd:element name="job" form="qualified" type="xsd:string" minOccurs="0"/>
...
Doing this, your original document validates.
The features I needed to set were:
- validation (setValidating(true))
- namespaces (setNamespaceAware(true))
"http://apache.org/xml/features/validation/dynamic" /* possibly not
needed */
"http://apache.org/xml/features/validation/schema"
I found all these in the Xerces documentation.
I really hope this helps you all solve your problem. It took me a while myself
to understand the elementFormDefault attribute by the way ;)
James
On Monday 07 October 2002 16:06, Peter Lane wrote:
> I just signed up to this list and stumbled accross this thread which
> illustrates exactly (as far as I can tell) the problem I'm having.
> Furthermore, I do not accept this solution (even if it works) as a valid
> "fix" to the problem. The fact remains that namespace-enabled schemas
> are not being processed correctly when referenced normally within an XML
> document. My example that doesn't work is as follows:
>
> Schema:
>
> <?xml version="1.0" encoding="UTF-8"?>
> <xsd:schema targetNamespace="http://schemas.gridforum.org/gridServices/rsl"
> xmlns:xsd="http://www.w3.org/2001/XMLSchema"
> xmlns:rsl="http://schemas.gridforum.org/gridServices/rsl"
> xmlns="http://schemas.gridforum.org/gridServices/rsl"
> version="0.2">
>
> <xsd:element name="rsl" type="rslType"/>
>
> <xsd:complexType name="rslType">
> <xsd:sequence>
> <xsd:element name="job" type="xsd:string" minOccurs="0"/>
> </xsd:sequence>
> </xsd:complexType>
>
> </xsd:schema>
>
>
>
> Document:
>
> <?xml version="1.0" encoding="UTF-8"?>
> <rsl
> xmlns:rsl="http://schemas.gridforum.org/gridServices/rsl"
> xmlns="http://schemas.gridforum.org/gridServices/rsl"
> xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
> xsi:schemaLocation="
> http://schemas.gridforum.org/gridServices/rsl
> schema/test.xsd">
> <job> Bastard! </job>
> </rsl>
>
>
>
> Xerces code:
>
> DocumentBuilderFactory parserFactory = null;
> DocumentBuilder xmlParser = null;
> try {
> parserFactory = DocumentBuilderFactory.newInstance();
> parserFactory.setNamespaceAware(true);
> parserFactory.setValidating(true);
> xmlParser = parserFactory.newDocumentBuilder();
> xmlParser.setErrorHandler(this);
> } catch (javax.xml.parsers.ParserConfigurationException pce) {
> logger.error("problem getting parser factory instance", pce);
> return null;
> }
>
> BufferedReader bufferedReader = new BufferedReader(xmlReader);
> return xmlParser.parse(new InputSource(bufferedReader));
>
>
>
> I would really appreciate some feedback on this as my project is
> basically stalled until I get this resolved.
>
> Thanks,
> Peter
>
> Amthauer, Heiner wrote:
> > Hi!
> >
> > Finally, I found a way to get it work. By setting the namespace-feature
> > to true and setting the XSD definition with the
> > http://apache.org/xml/properties/schema/external-noNamespaceSchemaLocatio
> >n property, the parser actually validates using my schema defintion.
> >
> > Thanx for your efforts.
> >
> > greetings
> > Heiner
> >
> >
> > -----Urspr�ngliche Nachricht-----
> > Von: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]
> > Gesendet am: Montag, 7. Oktober 2002 16:32
> > An: [EMAIL PROTECTED]
> > Betreff: Re: Not an FAQ: still unable to validate against XSD
> >
> > Have you tried turning on namespace? (SAXParserFactory#setNamespaceAware)
> >
> > Sandy Gao
> > Software Developer, IBM Canada
> > (1-905) 413-3255
> > [EMAIL PROTECTED]
> >
> >
> >
> >
> >
> > "Amthauer, Heiner"
> >
> > <[EMAIL PROTECTED] To: "'Xerces'"
> > <[EMAIL PROTECTED]>
> > ystems.com> cc:
> >
> > Subject: Not an FAQ:
> > still unable to validate against XSD
> > 10/07/2002 06:04 AM
> >
> > Please respond to
> >
> > xerces-j-user
> >
> >
> >
> >
> >
> >
> >
> >
> > Hi there!
> >
> > I'm still unable to validate my xml file against an XSD. Here ist the
> > code, I use to load the file via SAX, using XERCES 2.0 (JRE1.3.1):
> >
> > private static final String FLAG_VALIDATE =
> > "http://xml.org/sax/features/validation";
> > private static final String FLAG_SCHEMA =
> > "http://apache.org/xml/features/validation/schema";
> >
> > private SAXParserFactory factory = null;
> > private org.xml.sax.SAXParser saxParser = null;
> >
> > ...
> > factory = SAXParserFactory.newInstance();
> > ...
> > saxParser = factory.newSAXParser();
> > ...
> > saxParser.getXMLReader().setFeature(FLAG_VALIDATE, true);
> > saxParser.getXMLReader().setFeature(FLAG_SCHEMA, true);
> > saxParser.parse(new File(file), this);
> > ...
> >
> > This always gives me an error saying "cvc-elt.1: Cannot find the
> > declaration
> > of element 'whatever'".
> >
> > Since then, I've tried to use an EntityResolver for loading the XSD. I've
> > started with writing a little test code for the EntryResolver like this:
> >
> > public class SAXEntityResolver implements EntityResolver {
> >
> > public InputSource resolveEntity(String publicID, String
> > systemID) throws SAXException, IOException {
> > System.out.println(publicID+", "+systemID);
> > return null;
> > }
> >
> > }
> >
> > ...
> >
> > private static final String FLAG_VALIDATE =
> > "http://xml.org/sax/features/validation";
> > private static final String FLAG_SCHEMA =
> > "http://apache.org/xml/features/validation/schema";
> >
> > private SAXParserFactory factory = null;
> > private SAXParser saxParser = null;
> >
> > ...
> > factory = SAXParserFactory.newInstance();
> > ...
> > saxParser = factory.newSAXParser();
> > ...
> > saxParser.getXMLReader().setFeature(FLAG_VALIDATE, true);
> > saxParser.getXMLReader().setFeature(FLAG_SCHEMA, true);
> > saxParser.getXMLReader().setEntityResolver(new
> > SAXEntityResolver());
> > saxParser.parse(new File(file), this);
> > ...
> >
> > In result, my programm still reads the xml file with the same error as
> > before. The println() in the EntityResolver is never reached.
> >
> > I woulde really appreciate any help on this. Next on schedule is testing
> > and
> > I'm still unable to validate the xml file. Btw., loading the file with
> > any other XML/XSD aware application works fine.
> >
> > regards
> > Heiner
> >
> >
> > ---------------------------------------------------------------
> > Dipl. Ing. Heiner Amthauer
> >
> > T-Systems GEI GmbH
> >
> > Hausanschrift: Magirusstr. 39/1, 89077 Ulm
> > Postanschrift: Postfach 20 64, 89010 Ulm
> > Telefon: +49 ( 731) 9344-4422
> > Telefax: +49 (731) 9344-4409
> > Mobil: +49 (1 78) 4269335
> > E-Mail: [EMAIL PROTECTED]
> > Internet: http://www.t-systems.com
> >
> >
> >
> > ---------------------------------------------------------------------
> > 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]
> >
> > ---------------------------------------------------------------------
> > 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]
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]