|
View:
New views
4 Messages
—
Rating Filter:
Alert me
|
|
|
schema validation and elementFormDefaultI 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 _______________________________________________ To control your jdom-interest membership: http://www.jdom.org/mailman/options/jdom-interest/youraddr@... |
|
|
RE: schema validation and elementFormDefault> What is up with elementFormDefault="unqualified"? It seems to
> change the rules for determining which namespace an element > belongs to... Is it fundamentally broken? It's not broken, in that it's perfectly well defined, but it it produces highly counter-intuitive results and there is never a good reason for using it. Regards, Michael Kay http://www.saxonica.com/ http://twitter.com/michaelhkay _______________________________________________ To control your jdom-interest membership: http://www.jdom.org/mailman/options/jdom-interest/youraddr@... |
|
|
Re: schema validation and elementFormDefaultOn Tuesday 20 October 2009 14:53:44 you wrote:
> > What is up with elementFormDefault="unqualified"? It seems to > > change the rules for determining which namespace an element > > belongs to... Is it fundamentally broken? > > It's not broken, in that it's perfectly well defined, but it it produces > highly counter-intuitive results and there is never a good reason for using > it. When I parse valid document (valid according to a schema using elementFormDefault="unqualified") JDOM puts the root element and the child in different namespaces, eg: <?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> JDOM puts VOTABLE in the "http://www.ivoa.net/xml/VOTable/v1.2" namepsace and it puts RESOURCE in the "" namespace. SAX (xerces) schema validation says the document is valid, so it must think RESOURCE is in the "http://www.ivoa.net/xml/VOTable/v1.2" namespace; that is the intent of the schema authors. Is JDOM wrong in the sense of not being capable of correctly assigning namespaces in this case because it does not check this setting in the schema? I'm not saying it is a bug... Is it a known (insurmountable?) limitation of JDOM? thanks in advance, -- 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 _______________________________________________ To control your jdom-interest membership: http://www.jdom.org/mailman/options/jdom-interest/youraddr@... |
|
|
RE: schema validation and elementFormDefault> When I parse valid document (valid according to a schema using
> elementFormDefault="unqualified") JDOM puts the root element > and the child in different namespaces, eg: > > <?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> > > JDOM puts VOTABLE in the > "http://www.ivoa.net/xml/VOTable/v1.2" namepsace and it puts > RESOURCE in the "" namespace. Quite correct. That's what the schema says it should do. > > SAX (xerces) schema validation says the document is valid, so > it must think RESOURCE is in the > "http://www.ivoa.net/xml/VOTable/v1.2" namespace; that is the > intent of the schema authors. By using elementFormDefault="unqualified" the schema authors were signifying that locally-declared elements are in no namespace. If they intended them to be in the target namespace, they should have used elementFormDefault="qualified". > > Is JDOM wrong in the sense of not being capable of correctly > assigning namespaces in this case because it does not check > this setting in the schema? No, JDOM is correct. As I said before, elementFormDefault="unqualified" gives very counter-intuitive results, and for that reason is rarely used (except by beginners who don't know better), but if it is used, this is what it means and JDOM is handling it correctly. Regards, Michael Kay http://www.saxonica.com/ http://twitter.com/michaelhkay _______________________________________________ To control your jdom-interest membership: http://www.jdom.org/mailman/options/jdom-interest/youraddr@... |
| Free embeddable forum powered by Nabble | Forum Help |