Thanks for your response.  Could you let me know how the schema location
string passed to the validate method looks like?  I learned from other
sources saying that you have to pass in something like "part1 part2" with a
space in between.

Plus, my XmlReader was created by the factory using SAXParser as the class.
I did similar thing as to set the features and set the property.  I got the
following error:

Sat Dec 15 14:49:38 EST 2001:<E> <HTTP> java.lang.NoSuchMethodError
        at
org.apache.xerces.parsers.DOMParser.startElement(DOMParser.java:1131)

        at
org.apache.xerces.validators.common.XMLValidator.callStartElement(XML
Validator.java:1284)
        at
org.apache.xerces.framework.XMLDocumentScanner.scanElement(XMLDocumen
tScanner.java:1806)
        at
org.apache.xerces.framework.XMLDocumentScanner$ContentDispatcher.disp
atch(XMLDocumentScanner.java:949)
        at
org.apache.xerces.framework.XMLDocumentScanner.parseSome(XMLDocumentS
canner.java:381)
        at org.apache.xerces.framework.XMLParser.parse(XMLParser.java:1098)
        at
org.apache.xerces.validators.common.XMLValidator.resolveSchemaGrammar
(XMLValidator.java:2823)
        at
org.apache.xerces.validators.common.XMLValidator.parseSchemas(XMLVali
dator.java:2747)
        at
org.apache.xerces.validators.common.XMLValidator.bindNamespacesToElem
entAndAttributes(XMLValidator.java:2628)
        at
org.apache.xerces.validators.common.XMLValidator.callStartElement(XML
Validator.java:1218)
        at
org.apache.xerces.framework.XMLDocumentScanner$ContentDispatcher.disp
atch(XMLDocumentScanner.java:938)
        at
org.apache.xerces.framework.XMLDocumentScanner.parseSome(XMLDocumentS
canner.java:381)
        at org.apache.xerces.framework.XMLParser.parse(XMLParser.java:1098)


It'd be greatly appreciated if you can point me to the right direction.

-- DX

-----Original Message-----
From: Xuemin Guan [mailto:[EMAIL PROTECTED]
Sent: Tuesday, December 18, 2001 9:02 PM
To: [EMAIL PROTECTED]
Subject: RE: Re[2]: Schema validating XML parsing


At 20:54 01/12/18 -0500, you wrote:
>Could you send me a code snippet of all steps needed for schema validation?
>I am desparate.  I am using XmlReader and I am not sure if that makes a
>difference.
>
>Thanks in advance.
>
>-- DX

Have a look at the following code: note: it is an example, you can modify
it to meet your specific needs.

package com.appresso.dataspider.adapter.sap.common;

import org.xml.sax.ErrorHandler;
import org.xml.sax.SAXException;
import org.xml.sax.SAXParseException;
import org.xml.sax.InputSource;

import org.apache.xerces.parsers.SAXParser;

import java.io.IOException;

public class XMLValidator {


         private static final XMLValidator xmlValidator = new
XMLValidator();

         public static XMLValidator getInstance(){
                 return xmlValidator;
         }

         private XMLValidator(){

         }

         public void validate(InputSource in, String schemaLocation, String
strNamespace)
                 throws SAXException, IOException
         {
         SAXParser reader = new SAXParser();

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

         //set the parser's property: the target namespace, and schema
location
         if(!strNamespace.equals(""))
 
reader.setProperty("http://apache.org/xml/properties/schema/external-schemaL
ocation",
                                          strNamespace+" "+schemaLocation);
         else
 
reader.setProperty("http://apache.org/xml/properties/schema/external-noNames
paceSchemaLocation",
                                        schemaLocation);
         // Register the error handler
         reader.setErrorHandler(new MyErrorHandler());
         reader.parse(in);
         }
}

class MyErrorHandler implements ErrorHandler {
     public void warning(SAXParseException exception) {
                 String errorReport = "**Parsing Warning**\n" +
                                                   "  Line:    " +
                                       exception.getLineNumber() + "\n" +
                                       "  URI:     " +
                                       exception.getSystemId() + "\n" +
                                       "  Message: " +
                                       exception.getMessage();
         // We only give information when a warning arises.
         System.out.println(errorReport);
     }

     public void error(SAXParseException exception) throws SAXException {
                 String errorReport = "**Parsing Error**\n" +
                                                   "  Line:    " +
                                       exception.getLineNumber() + "\n" +
                                       "  URI:     " +
                                       exception.getSystemId() + "\n" +
                                       "  Message: " +
                                       exception.getMessage();
         System.out.println(errorReport);
         throw new SAXException(errorReport);
     }

     public void fatalError(SAXParseException exception) throws SAXException
{
                 String errorReport = "**Parsing Fatal Error**\n" +
                                                   "  Line:    " +
                                       exception.getLineNumber() + "\n" +
                                       "  URI:     " +
                                       exception.getSystemId() + "\n" +
                                       "  Message: " +
                                       exception.getMessage();

         System.out.println(errorReport);
         throw new SAXException(errorReport);
     }
}

-------
Xuemin Guan
Software Engineer
Appresso SpA (www.appresso.com)
Tel:  +81-3-4412-7790(Direct)
        +81-3-4412-7700(Represent)
Email: [EMAIL PROTECTED] 


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to