OASIS Mailing List ArchivesView the OASIS mailing list archive below
or browse/search using MarkMail.

 


Help: OASIS Mailing Lists Help | MarkMail Help

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

RE:



What version of Xerces are you using?  The namespace for XML Schema has
changed.

Xerces 1.3 only takes http://www.w3.org/2000/10/XMLSchema and
http://www.w3.org/2000/10/XMLSchema-instance (the way you have it.)

Xerces 1.4 only takes http://www.w3.org/2001/XMLSchema and
http://www.w3.org/2001/XMLSchema-instance


That's the only thing I can see that might be wrong.


Priscilla Walmsley
Vitria Technology

> -----Original Message-----
> From: Richard Featherstone [mailto:R.Featherstone@uea.ac.uk]
> Sent: Tuesday, July 10, 2001 9:02 AM
> To: xml-dev@lists.xml.org
> Subject:
>
>
>
> Please help.  I'm trying to validate against a schema using Xerces and
> JAXP.  I'm only using a simple schema to get things working, but they
> don't.  Please look at the following code and let me know
> what I'm doing
> wrong.
>
> Thanks in advance
>
> Richard
>
>
> 		HERE'S THE BASIC SCHEMA
>
> <?xml version="1.0" encoding="UTF-8"?>
> <xsd:schema xmlns:xsd="http://www.w3.org/2000/10/XMLSchema"
> elementFormDefault="qualified">
>    <xsd:element name="message" type = "MessageType"/>
>
> 	<xsd:complexType name = "MessageType">
> 	   <xsd:choice>
> 		  <xsd:element name = "request" type = "xsd:string"/>
> 		  <xsd:element name="response" type = "xsd:string"/>
> 	   </xsd:choice>
> 	</xsd:complexType>
> </xsd:schema>
>
> 		AND A VALID DOC
>
> <?xml version="1.0" encoding="UTF-8"?>
> <message xmlns:xsi="http://www.w3.org/2000/10/XMLSchema-instance"
> xsi:noNamespaceSchemaLocation="C:\WINDOWS\Desktop\Inspiration\
> schema.xsd">
>    <request>do something</request>
> </message>
>
> 		AN INVALID DOC
>
> <?xml version="1.0" encoding="UTF-8"?>
> <message xmlns:xsi="http://www.w3.org/2000/10/XMLSchema-instance"
> xsi:noNamespaceSchemaLocation="C:\WINDOWS\Desktop\Inspiration\
> schema.xsd">
>    <badTag>should fail</badTag>
> </message>
>
> 		AND THE JAVA CODE TO PARSE AND VALIDATE
>
> import java.io.*;
>
> import org.xml.sax.*;
> import org.xml.sax.helpers.*;
> import javax.xml.parsers.*;
>
> public class Parse extends DefaultHandler {
>
>     public void startElement(String uri, String localName, String
> qualName, Attributes attrs) throws SAXException {
>         System.out.println("Start\t" + localName);
>     }
>
>     public void characters (char buffer[], int offset, int
> length) throws
> SAXException {
>         if(length > 0){
>             String temp = new String(buffer, offset, length);
>
>             if(!temp.trim().equals("")){
>                 System.out.println("Content\t" + temp.trim());
>             }
>         }
>     }
>
>     public void error (SAXParseException spe) throws
> SAXParseException{
>         throw spe;
>     }
>
>     public void warning (SAXParseException spe) throws
> SAXParseException{
>         System.err.println("Warning: " + spe.getMessage());
>     }
>
>     public static void main (String args[]) {
>
>         Parse p = new Parse();
>         try{
>
>             XMLReader parser =
> (XMLReader)Class.forName("org.apache.xerces.parsers.SAXParser"
> ).newInstance();
>
>             parser.setContentHandler(p);
>             parser.setErrorHandler(p);
>
> parser.setFeature("http://xml.org/sax/features/validation",
> true);
>             parser.setFeature(
> "http://apache.org/xml/features/validation/schema", true);
>             //parser.setFeature(
> "http://apache.org/xml/features/validation/schema-full-checkin
g", true);

            parser.parse(new
InputSource("file:///C:/WINDOWS/Desktop/Inspiration/badDoc.xml"));
        }
        catch (SAXParseException spe){
            System.err.println("Parse Error: " + spe.getMessage());
        }
        catch(SAXException se){
            se.printStackTrace();
        }
        catch(Exception e){
            e.printStackTrace();
        }
        System.exit(0);
    }
}

		ERROR MESSAGE

Element type "message" must be declared


------------------------------------------------------------------
The xml-dev list is sponsored by XML.org, an initiative of OASIS
<http://www.oasis-open.org>

The list archives are at http://lists.xml.org/archives/xml-dev/

To unsubscribe from this elist send a message with the single word
"unsubscribe" in the body to: xml-dev-request@lists.xml.org