RE: xerces-j validation issues

Tom,

Maybe you also need to turn on schema validation:

parser.setFeature ("http://xml.org/sax/features/validation/schema", 
    true);

Hope that helps,
Priscilla
-----------------------------------------------------------
Priscilla Walmsley                   priscilla@walmsley.com
Vitria Technology                     http://www.vitria.com
Author, Definitive XML Schema    (Prentice Hall, Dec. 2001)
-----------------------------------------------------------

> -----Original Message-----
> From: xmlschema-dev-request@w3.org
> [mailto:xmlschema-dev-request@w3.org]On Behalf Of Tom Preston
> Sent: Thursday, December 06, 2001 12:36 PM
> To: Eddie Robertsson
> Cc: XMLSchema (E-mail)
> Subject: RE: xerces-j validation issues
> 
> 
> Eddie, all,
> 
> I fixed the updateTime and boolean values but I don't think 
> that was the
> root of the problem.  I am using Xerces2.0.0beta3 
> xerces.jar...here is the
> output:
> 
> C:\xml>java -classpath .;c:\vcom\bin\xerces\xerces.jar ValidatingDOM
> editor99.xm
> l
> org.xml.sax.SAXNotRecognizedException:
> http://apache.org/xml/properties/schema/e
> xternal-schemaLocation
> Error:  org.xml.sax.SAXParseException: Document is invalid: no grammar
> found.
> htmlEditor
> updateTime
> fields
> field
> shortDesc
> htmlType
> name
> value
> allowNull
> defaultVal
> 
> Maybe my code is not good?  Do I have to specify a "grammar" 
> in the code?  I
> always get the grammar problem even when commenting out the
> parser.setProperty below.  Here is the code:
> 
> import org.apache.xerces.parsers.DOMParser;
> import org.xml.sax.ErrorHandler;
> import org.w3c.dom.Document;
> import org.w3c.dom.Node;
> import org.w3c.dom.Element;
> import org.w3c.dom.NodeList;
> import org.xml.sax.SAXException;
> import org.xml.sax.SAXParseException;
> import org.xml.sax.SAXNotRecognizedException;
> import org.xml.sax.SAXNotSupportedException;
> import java.io.IOException;
> 
> //  A Valdating DOM Application
> //  with registered Error Handlers
> public class ValidatingDOM implements ErrorHandler {
>     
>     // Constructor
>     public ValidatingDOM (String xmlFile) {
>         //  Create a Xerces DOM Parser
>         DOMParser parser = new DOMParser();
>     
>         //  Turn Validation on
>         try {
>             parser.setFeature 
>             ("http://xml.org/sax/features/validation", 
>             true);
>             parser.setProperty
>  
> ("http://apache.org/xml/properties/schema/external-schemaLocation",
>             "http://www.emilygraham.com/java/other/editor.xsd");
>         } catch (SAXNotRecognizedException e) {
>             System.err.println (e);
>         } catch (SAXNotSupportedException e) {
>             System.err.println (e);
>         }
>     
>         //  Register Error Handler
>         parser.setErrorHandler (this);
> 
>         //  Parse the Document      
>         //  and traverse the DOM
>         try {
>             parser.parse(xmlFile);
>             Document document = parser.getDocument();
>             traverse (document);
>         } catch (SAXException e) {
>             System.err.println (e);
>         } catch (IOException e) {
>             System.err.println (e);
>         }
>     }
>     
>     //  Traverse DOM Tree.  Print out Element Names
>     private void traverse (Node node) {
>         int type = node.getNodeType();
>         if (type == Node.ELEMENT_NODE)
>             System.out.println (node.getNodeName());
>         NodeList children = node.getChildNodes();
>         if (children != null) {
>             for (int i=0; i< children.getLength(); i++) 
>                 traverse (children.item(i));    
>         }
>     }
>     
>     //  Warning Event Handler
>     public void warning (SAXParseException e)
>         throws SAXException {
>         System.err.println ("Warning:  "+e);
>     }
> 
>     //  Error Event Handler
>     public void error (SAXParseException e)
>         throws SAXException {
>         System.err.println ("Error:  "+e);
>     }
>     
>     //  Fatal Error Event Handler
>     public void fatalError (SAXParseException e)
>         throws SAXException {
>         System.err.println ("Fatal Error:  "+e);
>     }
>     
>     // Main Method
>     public static void main (String[] args) {
>         ValidatingDOM validatingDOM = 
>         	new ValidatingDOM (args[0]);
>     }
> }
> 
> 
> -----Original Message-----
> From: Eddie Robertsson [mailto:eddie@allette.com.au]
> Sent: Wednesday, December 05, 2001 5:42 PM
> To: Tom Preston
> Cc: XMLSchema (E-mail)
> Subject: Re: xerces-j validation issues
> 
> 
> > What is this problem?
> >
> > Here is the doc set (which XSV thinks is fine):
> >
> > XML IS:
> > -----------
> > <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></updateTime>
> >   <fields>
> >     <field columnName="nickname">
> >       <shortDesc>Short Desc</shortDesc>
> >       <htmlType name="select">
> >         <name>firstName</name>
> >         <value>lastName</value>
> >       </htmlType>
> >       <allowNull>adfsa</allowNull>
> >       <defaultVal>Blueberry</defaultVal>
> >     </field>
> >   </fields>
> > </htmlEditor>
> 
> Apart from the fact that <updateTime> doesn't have a valid 
> dateTime and that
> "adfsa" isn't a valid boolean for element <allowNull> it all 
> seems fine to
> me
> (XSV wouldn't catch this because simpleType checking isn't 
> implemented yet).
> What version of Xerces are you using?
> I just tried it with Xercex 2 beta and it validated fine.
> 
> Cheers,
> /Eddie
> 
> >
> > ----------
> > XSD IS:
> > ----------
> > <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>
> >
> > ------------
> >
> > 2) When i attept to force external validation with this 
> line of code:
> >
> > parser.setProperty
> >
> > ("http://apache.org/xml/properties/schema/external-schemaLocation",
> >             "http://www.emilygraham.com/java/other/editor.xsd");
> >
> > I get this exception:
> >
> > org.xml.sax.SAXNotRecognizedException:
> > http://apache.org/xml/properties/schema/external-schemaLocation
> >
> > Does anyone know why this would happen?
> >
> > --------
> > 3) Does anyone know where I can get a set of very simple 
> documents that
> will
> > pass MANY different validations.  Just one example would be nice.
> >
> > Thanks
> >
> > Tom
> 
> 

Received on Thursday, 6 December 2001 13:48:35 UTC