RE: XML Schema validation using JAXP Q?

 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 <tpreston@amadeusboston.com> 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
------
<!DOCTYPE htmlEditor >
<htmlEditor
  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">

  <updateTime>1999-05-31T13:20:00</updateTime>
  <fields>
    <field columnName="nickname">
      <shortDesc>Short Desc</shortDesc>
      <htmlType name="select">
        <name>firstName</name>
        <value>lastName</value>
      </htmlType>
      <allowNull>tru</allowNull>
      <defaultVal>Blueberry</defaultVal>
    </field>
  </fields>
</htmlEditor>

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

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

  <annotation>
    <documentation xml:lang="en">
     Editor document definition defines an html based editor
    </documentation>
  </annotation>

  <element name="htmlEditor" type="e:HtmlEditorType"/>

  <element name="updateTime" type="dateTime"/>

  <complexType name="HtmlEditorType">
    <sequence>
      <element ref="e:updateTime" minOccurs="1" maxOccurs="1" />
      <element name="fields" type="e:Fields" minOccurs="1" maxOccurs="1"
/>
    </sequence>
  </complexType>

  <complexType name="Fields">
    <sequence>
      <element name="field" minOccurs="1" maxOccurs="unbounded">
        <complexType>
          <sequence>
            <element name="shortDesc" type="string" minOccurs="1"
maxOccurs="1"/>
            <element name="htmlType" type="e:HtmlTypeType" minOccurs="1"
maxOccurs="1"/>
            <element name="allowNull" type="boolean" minOccurs="1"
maxOccurs="1" />
            <element name="defaultVal"  type="string"/>
          </sequence>
          <attribute name="columnName" type="string" use="required"/>
        </complexType>
      </element>
    </sequence>
  </complexType>

  <complexType name="HtmlTypeType">
    <sequence>
      <element name="name" type="string" />
      <element name="value" type="string" />
    </sequence>
    <attribute name="name" type="e:HtmlNameType" use="required"/>
  </complexType>

  <simpleType name="HtmlNameType">
    <restriction base="NMTOKEN">
      <enumeration value="select"/>
      <enumeration value="text"/>
    </restriction>
  </simpleType>
</schema>

------
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

Received on Tuesday, 18 December 2001 08:21:41 UTC