RE: XML Schema validation using JAXP Q?

Hello, I am a little confused by some of the recent comments regarding JAXP 1.1 and XML Schema support.
I have successfully validated instance documents, using Xalan and JAXP1.1, against XMLSchema (single and multiple schema, using both include and import). Mr. Preston, you offered the following code and also stated that we must be implementation :

//  Create a Xerces DOM Parser
        DOMParser parser = new DOMParser();
 
        //  Turn Validation on
        try {
            parser.setFeature
            ("http://xml.org/sax/features/validation", true);
            parser.setFeature 
            ("http://apache.org/xml/features/validation/schema",true);
            parser.setFeature

However, the following works quite well for me when validating against XMLSchema. No reference to Xerces other than classpath is needed:

DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
dbf.setValidating (true);
dbf.setNamespaceAware (true);
DocumentBuilder db = dbf.newDocumentBuilder ();
db.setErrorHandler (new MyErrorHandler ());
Document d = db.parse (uri);

Unless I am missing the point here, or possibly confused between Reference Implementation and Specification, as you included a reference to, JAXP1.1 is XMLSchema-aware while JAXP1.0.1 is not.

Tom Rowland
  

  Tom Preston <tpreston@amadeusboston.com> wrote: http://xml.apache.org/~edwingo/jaxp-faq.html

"Currently the JAXP 1.1 specification does not expose XML Schema nor any
other non-DTD schema language directly via the API. However, in Xerces-j 1.x
parsers, turning on both validation and namespace processing features will
cause XML Schema validation to occur."

Therefore, lines of code like 
setAttribute("http://apache.org/xml/features/validation/schema", true); need
be implementation specific.

Tom

-----Original Message-----
From: Jakub.Valenta@Deio.net
To: Tom Preston; xmlschema-dev@w3.org
Sent: 12/18/01 2:55 AM
Subject: RE: XML Schema validation using JAXP Q?


Thanks a lot for help,
I would like to ask one more think. Is the example, you gave me, going
to
work with any JAXP compatible parser, or is the validation Xerces
proprietary?

br,

Jakub





Tom Preston on 12/17/2001 10:57:20 PM

To: Jakub.Valenta@Deio.net, xmlschema-dev@w3.org
cc:

Subject: RE: XML Schema validation using JAXP Q?

You write a trivial java program like this:

Compile and run it like this (notice xerces.jar and xml-apis.jar are
needed):

C:\xml>javac -classpath
.;c:\thirdparty\apache\xerces.jar;c:\thirdparty\apache\x
ml-apis.jar SchemaValidate.java

C:\xml>java -classpath
.;c:\thirdparty\apache\xerces.jar;c:\thirdparty\apache\xm
l-apis.jar SchemaValidate editor99.xml
Error: org.xml.sax.SAXParseException: Datatype error: In element
'allowNull' :
tru is not a boolean.


NOtice that editor99.xml failed validation. Here is editor99.xml and
editor.xsd which it validates against (note the xsi:schemaLocation is
defined in the .xml file):

------
editor.xml
------

xmlns="http://www.emilygraham.com/java/other/Editor"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.emilygraham.com/java/other/Editor
http://www.emilygraham.com/java/other/editor.xsd">

1999-05-31T13:20:00


Short Desc

firstName
lastName

tru
Blueberry




------
editor.xsd
------

xmlns="http://www.w3.org/2001/XMLSchema"
xmlns:e="http://www.emilygraham.com/java/other/Editor"
elementFormDefault="qualified">



Editor document definition defines an html based editor










/>








maxOccurs="1"/>
maxOccurs="1"/>
maxOccurs="1" />
























------
hope this helps.

TOm

-----Original Message-----
From: Jakub.Valenta@Deio.net [mailto:Jakub.Valenta@Deio.net]
Sent: Monday, December 17, 2001 12:26 PM
To: xmlschema-dev@w3.org
Subject: XML Schema validation using JAXP Q?


Hi all,
I would like to ask if it is possible to validate xml document against
XML
Schema using JAXP? At the moment I am using XALAN and it should be XML
Schema aware, but I have no clue how to do the vlidation using JAXP.

Any help appreciated,

Jaub





Thomas Rowland
Software Engineer
25 Green Pasture Rd.
Bethel, CT 06801
(203) 798-8337
tomorrwland@yahoo.com


---------------------------------
Do You Yahoo!?
Check out Yahoo! Shopping and Yahoo! Auctionsfor all of your holiday gifts!

Received on Wednesday, 19 December 2001 15:11:21 UTC