[jdom-interest] schema validation and elementFormDefault

Patrick Dowler patrick.dowler at nrc-cnrc.gc.ca
Tue Oct 20 14:13:59 PDT 2009


I am having trouble understanding the effect/correctness of elementFormDefault 
being not set (or set to unqualified) in a schema I am using. In the current 
draft of the schema, elementFormDefault is not set.

My test program build the document (SAXBuilder, xerces SAXParser) with and 
without schema validation. Below are 3 tests I did with different documents. 

In test #1 and #2 JDOM puts both the root and child element in the same 
expected namespace, but SAX validation fails. With #3, JDOM puts the root and 
child elements in different namespaces but SAX validation succeeds. #3 is 
nominally equivalent to the examples for using elementFormDefault="unqualified" 
in the W3C XML schema spec. So, it looks to me like JDOM and SAX (the schema) 
disagree on the namespace of the child element.

If I change the schema to have elementFormDefault="qualified", test #1 and #2 
pass and test #3 fails and everything seems consistent. So my problem seems to 
stem from the behaviour of elementFormDefault="unqualified".

Can anyone shed any light on this? 

What is up with elementFormDefault="unqualified"? It seems to change the rules 
for determining which namespace an element belongs to... Is it fundamentally 
broken? 

thanks in advance,

Patrick

PS-I should note that the schema in question is just passing through a review 
stage toward standardisation, so I can argue for elementFormDefault="qualified" 
instead. 


*** Document #1: terminology: is this default namespace usage?

<?xml version="1.0"?>
<VOTABLE version="1.2" 
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns="http://www.ivoa.net/xml/VOTable/v1.2">

<RESOURCE/>

</VOTABLE>

Test output #1:

building with validate=false...
[Element: <VOTABLE [Namespace: http://www.ivoa.net/xml/VOTable/v1.2]/>]
  is in [Namespace: prefix "" is mapped to URI   
  "http://www.ivoa.net/xml/VOTable/v1.2"]
[Element: <RESOURCE [Namespace: http://www.ivoa.net/xml/VOTable/v1.2]/>]
  is in [Namespace: prefix "" is mapped to URI 
  "http://www.ivoa.net/xml/VOTable/v1.2"]
building with validate=false... [OK]


building with validate=true...
FAILED: 
Error on line 6 of document file:
/home/cadc/pdowler/work/src/scratch/test/votable1.xml:
 cvc-complex-type.2.4.a:
 Invalid content was found starting with element 'RESOURCE'. One of 
'{DESCRIPTION, DEFINITIONS, COOSYS, GROUP, PARAM, INFO, RESOURCE}' is 
expected.

*** Test Document #2: explicit namespace prefixes

<?xml version="1.0"?>
<vot:VOTABLE version="1.2" 
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:vot="http://www.ivoa.net/xml/VOTable/v1.2">

<vot:RESOURCE/>

</vot:VOTABLE>

Test output #2:

building with validate=false...
[Element: <vot:VOTABLE [Namespace: http://www.ivoa.net/xml/VOTable/v1.2]/>]
  is in [Namespace: prefix "vot" is mapped to URI 
"http://www.ivoa.net/xml/VOTable/v1.2"]
[Element: <vot:RESOURCE [Namespace: http://www.ivoa.net/xml/VOTable/v1.2]/>]
  is in [Namespace: prefix "vot" is mapped to URI 
"http://www.ivoa.net/xml/VOTable/v1.2"]
building with validate=false... [OK]


building with validate=true...
FAILED: 
Error on line 6 of document file:
/home/cadc/pdowler/work/src/scratch/test/votable2.xml:
 cvc-complex-type.2.4.a:
 Invalid content was found starting with element 'vot:RESOURCE'. One of 
'{DESCRIPTION, DEFINITIONS, COOSYS, GROUP, PARAM, INFO, RESOURCE}' is 
expected.:


*** Test Document #3: ugly hack?

<?xml version="1.0"?>
<vot:VOTABLE version="1.2" 
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:vot="http://www.ivoa.net/xml/VOTable/v1.2">

<RESOURCE/>

</vot:VOTABLE>

Test result #3:

building with validate=false...
[Element: <vot:VOTABLE [Namespace: http://www.ivoa.net/xml/VOTable/v1.2]/>]
  is in [Namespace: prefix "vot" is mapped to URI 
"http://www.ivoa.net/xml/VOTable/v1.2"]
[Element: <RESOURCE/>]
  is in [Namespace: prefix "" is mapped to URI ""]
building with validate=false... [OK]


building with validate=true...
[Element: <vot:VOTABLE [Namespace: http://www.ivoa.net/xml/VOTable/v1.2]/>]
  is in [Namespace: prefix "vot" is mapped to URI 
"http://www.ivoa.net/xml/VOTable/v1.2"]
[Element: <RESOURCE/>]
  is in [Namespace: prefix "" is mapped to URI ""]
building with validate=true... [OK]


-- 

Patrick Dowler
Tel/Tél: (250) 363-0044
Canadian Astronomy Data Centre
National Research Council Canada
5071 West Saanich Road
Victoria, BC V9E 2M7

Centre canadien de donnees astronomiques
Conseil national de recherches Canada
5071, chemin West Saanich
Victoria (C.-B.) V9E 2M7



More information about the jdom-interest mailing list