Subjects
Home
VOTE Move XML Commons to Xerces
Commented: (XERCESJ 589) Bug with pattern restriction on long strings
: Xerces J 2 8 1 Release on Wednesday, September 13th
: Xerces J 2 9 0 Release on Wednesday, November 22nd
Commented: (XERCESJ 1066) Restriction+choice+substitutionGroup error
Commented: (XERCESJ 1178) Error getting prefix for an attribute with no n
Updated: (XERCESJ 1244) XMLSchemaValidator does not contribute element 's
Some consideration about the xerces DOM implementation
Updated: (XERCESJ 1066) Restriction+choice+substitutionGroup error
Commented: (XERCESJ 1227) Poor performance / OutOfMemoryError for sequenc
retain exception stack traces
Updated: (XERCESJ 1193) NPE or hang when parsing using the "continue afte
Future of NekoHTML
Commented: (XERCESJ 1203) NPE in XMLDTDProcessor
DOM Level 3 APIs for Xalan J and a new Xalan release (2 7 1)
: xml commons external 1 3 04 Release on Wednesday, November 22nd
Commented: (XERCESJ 1247) Incorrect location information on SAX when usin
XInclude exceptions how to mirror Xerces J functionality into Xerces C++?
First proposal on SoC project "Add support for the StAX (JSR 173) cursor API
: xml commons resolver 1 2 Release on Wednesday, November 22nd
Typo in RangeToken java Please check
Validator features
java lang ClassCastException when adopting Node
using the org apache xerces impl xs identity package
Updated: (XERCESJ 1257) buffer overflow in UTF8Reader for characters out
Problem with ref attributes and schema validation
Updated: (XERCESJ 122) XMLSchemaValidator does not contribute element 's d
Performance problem under load Xerces with Weblogic 9 x
remove ignored memory allocation
Commented: (XERCESJ 1177) SAXXMLStreamReader doesn 't always report namesp
Commented: (XERCESJ 977) Null pointer exception during DOM parsing
Commented: (XERCESJ 1197) Code cleanup for org apache xml serialize
Commented: (XERCESJ 1201) Initial contribution for StAX Event API
Updated: (XERCESJ 1061) Regex "$ " and "^ " characters treated as special c
Commented: (XERCESJ 1199) SAXXMLStreamReader should attempt to register a
Commented: (XERCESJ 1061) Regex "$ " and "^ " characters treated as special
Updated: (XERCESJ 589) Bug with pattern restriction on long strings
StackOverflow
xerces Range unnecessarily not garbage collectable if not detached
Updated: (XERCESJ 1178) Error getting prefix for an attribute with no nam
Bug in xs:redefine
Commented: (XERCESJ 1204) Can not set XMLEntityResolver for LSParser
Updated: (XERCESJ 1253) Prototype for SoC2007 project "Add support for th
Updated: (XERCESJ 1259) Add SteamFilter Function to SoC2007 project "Add
Assigned: (XERCESJ 444) SAXException thrown by EntityResolver is reported
Google Summer of Code 2007
Xerces J and XInclude relative path issue
Assigned: (XERCESJ 206) Stack overflow when using a schema validation
Commented: (XERCESJ 1215) Restrictions involving two levels of substituti
Closed: (XERCESJ 1203) NPE in XMLDTDProcessor
non overriding equals methoda
Resolved: (XERCESJ 1079) invalid value returned for TOTALDIGITS facet in
Xerces AS3 port
Updated: (XERCESJ 325) Regular Expression; Pattern "| " clause order de
Updated: (XERCESJ 1196) Javadoc generation fails on Java SE 5 0
Closed: (XERCESJ 1202) DTD validation on XIncluded documents when the sch
Created: (XERCESJ 1124) Nonspecific schema error message
a bug in xerces
Updated: (XERCESJ 1201) Initial contribution for StAX Event API
Closed: (XERCESJ 1254) Empty uris in targetNamespace attribute not report
Links
Home
Oracle database error code
 
Search:  
Power your search with and, or, +, -, or "some phrase" operators.
XML validation using xml schema string

XML validation using xml schema string

2003-01-24       - By Praveen Peddi
Reply:     1     2     3     4     5     6     7     8     9     10     >>  

Hi Jeff,
I did exactly what you told and it doesn't seem to work. Please look at the
following code and see if I am doing anything wrong.
The error I get is:
**Parsing Error**
 Line:    1
 URI:     null
 Message: cvc-elt.1: Cannot find the declaration of element 'content'.
SAXException Exception
Total time of SAXValidate:3546
org.xml.sax.SAXException: Error Validating the content XML.
at XMLValidator.validateXmlAgainstLocalSchema(XMLValidator.java:105)

My Entity Resolver is:
public class SchemaEntityResolver implements EntityResolver {

InputSource source;
 EntityResolver defaultResolver;
 String fakeLocationURI;


public SchemaEntityResolver(EntityResolver defaultResolver, String
mySchemaString,
String fakeLocationURI) {
     source = new InputSource(new StringReader(mySchemaString));
     this.defaultResolver = defaultResolver;
      this.fakeLocationURI = fakeLocationURI;
 }


   public InputSource resolveEntity(String pubId, String sysId)
       throws IOException, SAXException {
 if ((pubId != null && pubId.equals(fakeLocationURI))
          || (sysId != null && sysId.equals(fakeLocationURI))) {
          return source;
    }
     return defaultResolver.resolveEntity(pubId, sysId);
   }
}

And My validate method is as follows:

public static void validateXmlAgainstLocalSchema(String XMLString, String
schemaString) throws SAXException{
  long startTime = System.currentTimeMillis();
           System.out.println("Files: XML:" + XMLString + " XSD:" +
schemaString);
           XMLReader parser = null;
           // Instantiate a parser
           try{
               parser =  XMLReaderFactory.createXMLReader("org.apache.xerces
.parsers.SAXParser");
           } catch (org.xml.sax.SAXException ex){
               System.out.println("SAXException Exception");
   throw new SAXException("Error Obtaining the parser.");
           }

           try{

               // Register the error handler
               parser.setErrorHandler(new SchemaErrorHandler());

               //parser.setFeature("http://apache.org/xml/features/continue
-after-fatal-error", true);
               // Turn on validation
               parser.setFeature("http://xml.org/sax/features/namespaces",true
);
               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-checking",true);
               //parser.setProperty("http://apache.org/xml/properties/schema
/external-noNamespaceSchemaLocation",Schema);
   parser.setEntityResolver(new SchemaEntityResolver(parser.getEntityResolver(
), schemaString, "http://www.contextmedia.com"));


           } catch (org.xml.sax.SAXNotRecognizedException ex){
   ex.printStackTrace();
                   System.out.println("SAXNotRecognizedException Exception");
   
           } catch (org.xml.sax.SAXNotSupportedException ex){
   ex.printStackTrace();
                   System.out.println("SAXNotSupportedException Exception");
           }

           // Parse the document
           try{
               //String XMLSystemId = new File(XMLString).toURL()
.toExternalForm();
               parser.parse(new InputSource(new StringReader(XMLString)));
   //parser.parse(XMLSystemId);
               System.out.println("Parsed Successfully by SAX Parser");
           } catch (org.xml.sax.SAXException ex){
               System.out.println("SAXException Exception");
   throw new SAXException("Error Validating the content XML.");
           } catch (java.io.IOException ex){
               System.out.println("IOException Exception");
   throw new SAXException("Error Validating the content XML.");
           } finally {
  long endTime = System.currentTimeMillis();
        System.out.println("Total time of SAXValidate:"+(endTime-startTime));
  }
   }

----- Original Message -----
From: "Jeff Greif" <jgreif@(protected)>
To: <xerces-j-user@(protected)>
Sent: Thursday, January 23, 2003 3:07 PM
Subject: Re: XML validation using xml schema string


> Something like this (just typed into mail message, neither compiled nor
> tested).
>
> in main:
>
>     DomParser parser = new DomParser();
>     parser.setEntityResolver(new
> MyEntityResolver(parser.getEntityResolver(),
>
> mySchemaString, myfakeSchemaLocationURI));
>
> class MyEntityResolver {
>   InputSource source;
>   EntityResolver defaultResolver;
>   String fakeLocationURI;
>    public MyEntityResolver(EntityResolver default, String mySchemaString,
> String fakeLocationURI) {
>       source = new InputSource(new StringReader(mySchemaString));
>       defaultResolver = default;
>        this.fakeLocationURI = fakeLocationURI;
>   }
>   public InputSource resolveEntity(String pubId, String sysId) {
>       if ((pubId != null && pubId.equals(fakeLocationURI))
>            || (sysId != null && sysId.equals(fakeLocationURI))) {
>           return source;
>     }
>       return defaultResolver.resolveEntity(pubId, sysId);
>   }
>
> }
>
> Jeff
> ----- Original Message -----
> From: "Praveen Peddi" <ppeddi@(protected)>
> To: <xerces-j-user@(protected)>
> Sent: Thursday, January 23, 2003 10:51 AM
> Subject: Re: XML validation using xml schema string
>
>
> > Jeff,
> > I think I didn't get you completely.
> >
> > Could you please write a sample code or modify my code below so that I can
> > understand what you are syaing.
> >
> > Thanks
> > Praveen
> > ----- Original Message -----
> > From: "Jeff Greif" <jgreif@(protected)>
> > To: <xerces-j-user@(protected)>
> > Sent: Thursday, January 23, 2003 11:28 AM
> > Subject: Re: XML validation using xml schema string
> >
> >
> > > I'm not able to give information correct in detail, but here is an
> outline
> > > of what must happen:
> > >
> > > The entity resolver is called with a namespace URI or a schema location
> as
> > > an argument, I think.  In the course of parsing your instance document
> > (.xml
> > > file), it will be called to process your schema's namespace and possibly
> > > other namespaces (e.g. the XMLSchema-instance namespace) mentioned
> > therein.
> > > Probably you should get the default entity resolver for the parser
> (which
> > > knows how to handle some things, presumably), and create your own entity
> > > resolver holding that one as a member.  Then when asked for a particular
> > > schema by its namespace or location, if it's your schema, return the
> input
> > > source as your code below does, otherwise, pass the request to the
> member
> > > resolver which knows better than you what to do.
> > >
> > > Jeff
> > >
> > > ----- Original Message -----
> > > From: "Praveen Peddi" <ppeddi@(protected)>
> > > To: <xerces-j-user@(protected)>
> > > Sent: Thursday, January 23, 2003 7:44 AM
> > > Subject: Re: XML validation using xml schema string
> > >
> > >
> > > > I posted a question yesterday about the validation of XML against the
> > > local
> > > > schema (in memory). Could anyone please look at the message below and
> > > reply
> > > > if you know the answer.
> > > >
> > > > Thanks in Advance.
> > > >
> > > > Praveen
> > > > ----- Original Message -----
> > > > From: "Praveen Peddi" <ppeddi@(protected)>
> > > > To: <sandygao@(protected)>; <xerces-j-user@(protected)>
> > > > Sent: Wednesday, January 22, 2003 1:35 PM
> > > > Subject: Re: XML validation using xml schema string
> > > >
> > > >
> > > > > As you said I wrote an EntityResolver but it didn't work. Could you
> > send
> > > > me
> > > > > a sample code (just the validation code) if u already have one.
> > > > >
> > > > > My validate method looks as follows:
> > > > >
> > > > > public static void validateXmlAgainstLocalSchema(String XMLString,
> > > String
> > > > > schemaString) throws SAXException{
> > > > >    long startTime = System.currentTimeMillis();
> > > > >             System.out.println("Files: XML:" + XMLString + " XSD:" +
> > > > > schemaString);
> > > > >             XMLReader parser = null;
> > > > >             // Instantiate a parser
> > > > >             try{
> > > > >                 parser =
> > > > >
> > XMLReaderFactory.createXMLReader("org.apache.xerces.parsers.SAXParser");
> > > > >             } catch (org.xml.sax.SAXException ex){
> > > > >                 System.out.println("SAXException Exception");
> > > > >     throw new SAXException("Error Obtaining the parser.");
> > > > >             }
> > > > >
> > > > >             try{
> > > > >
> > > > >                 // Register the error handler
> > > > >                 parser.setErrorHandler(new SchemaErrorHandler());
> > > > >
> > > > >
> > > > >
> > > >
> > >
> >
> //parser.setFeature("http://apache.org/xml/features/continue-after-fatal-err
> > > > > or", true);
> > > > >                 // Turn on validation
> > > > >
> > > > > parser.setFeature("http://xml.org/sax/features/namespaces",true);
> > > > >
> > > > 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-che
> > > > > cking",true);
> > > > >
> > > > >
> > > >
> > >
> >
> //parser.setProperty("http://apache.org/xml/properties/schema/external-noNam
> > > > > espaceSchemaLocation",Schema);
> > > > >     parser.setEntityResolver(new
> SchemaEntityResolver(schemaString));
> > > > >
> > > > >
> > > > >             } catch (org.xml.sax.SAXNotRecognizedException ex){
> > > > >     ex.printStackTrace();
> > > > >                     System.out.println("SAXNotRecognizedException
> > > > > Exception");
> > > > >             } catch (org.xml.sax.SAXNotSupportedException ex){
> > > > >     ex.printStackTrace();
> > > > >                     System.out.println("SAXNotSupportedException
> > > > > Exception");
> > > > >             }
> > > > >
> > > > >             // Parse the document
> > > > >             try{
> > > > >                 //String XMLSystemId = new
> > > > > File(XMLString).toURL().toExternalForm();
> > > > >                 parser.parse(new InputSource(new
> > > > StringReader(XMLString)));
> > > > >     //parser.parse(XMLSystemId);
> > > > >                 System.out.println("Parsed Successfully by SAX
> > Parser");
> > > > >             } catch (org.xml.sax.SAXException ex){
> > > > >                 System.out.println("SAXException Exception");
> > > > >     throw new SAXException("Error Validating the content XML.");
> > > > >             } catch (java.io.IOException ex){
> > > > >                 System.out.println("IOException Exception");
> > > > >     throw new SAXException("Error Validating the content XML.");
> > > > >             } finally {
> > > > >    long endTime = System.currentTimeMillis();
> > > > >          System.out.println("Total time of
> > > > > SAXValidate:"+(endTime-startTime));
> > > > >    }
> > > > >     }//SAXValidate
> > > > >
> > > > > And SchemaEntityResolver looks as follows:
> > > > >
> > > > > public class SchemaEntityResolver implements EntityResolver {
> > > > >  InputSource source = null;
> > > > >  public SchemaEntityResolver(String schemaString) {
> > > > >   source = new InputSource(new StringReader(schemaString));
> > > > >  }
> > > > >
> > > > >     public InputSource resolveEntity(String publicID, String
> systemID)
> > > > >         throws SAXException {
> > > > >             return source;
> > > > >     }
> > > > > }
> > > > >
> > > > > When I try to validate an xml with the schema string, I get the
> > > following
> > > > > error:
> > > > > Line:    1
> > > > >   URI:     null
> > > > >   Message: cvc-elt.1: Cannot find the declaration of element
> > 'content'.
> > > > >
> > > > >
> > > > > Am I doing it wrong? If so please tell me how to use the
> > entityresolver.
> > > > >
> > > > > Praveen
> > > > >
> > > > >
> > > > > ----- Original Message -----
> > > > > From: <sandygao@(protected)>
> > > > > To: <xerces-j-user@(protected)>
> > > > > Sent: Monday, January 20, 2003 10:18 AM
> > > > > Subject: Re: XML validation using xml schema string
> > > > >
> > > > >
> > > > > > Write an entity resolver
> > > > > >
> > > > >
> > > >
> > >
> >
> (http://xml.apache.org/xerces2-j/javadocs/api/org/xml/sax/EntityResolver.htm
> > > > > l),
> > > > > >
> > > > > > and returned an input source with a StringReader when the schema
> > > > document
> > > > > > is asked.
> > > > > >
> > > > > > HTH,
> > > > > > Sandy Gao
> > > > > > Software Developer, IBM Canada
> > > > > > (1-905) 413-3255
> > > > > > sandygao@(protected)
> > > > > >
> > > > > >
> > > > > >
> > > > > >
> > > > > >                       "Praveen Peddi"
> > > > > >                       <ppeddi@(protected)        To:
> > > > > <xerces-j-user@(protected)>
> > > > > >                       dia.com>                 cc:
> > > > > >                                                Subject:  Re: XML
> > > > > validation using xml schema string
> > > > > >                       01/20/2003 09:16
> > > > > >                       AM
> > > > > >                       Please respond to
> > > > > >                       xerces-j-user
> > > > > >
> > > > > >
> > > > > >
> > > > > >
> > > > > >
> > > > > > Hi all,
> > > > > > Last week I sent an email regarding the xml validation against the
> > > > schema,
> > > > > > but didn't get any reply. Please reply if any one has answer to my
> > > > > > question. Is it possible to validate an xml document using a
> schema
> > > > > > document (not the schema url) that is present with in the
> > application.
> > > > If
> > > > > > its not possible, whats the best way of achieving it. Please read
> my
> > > > > > previous email below.
> > > > > >
> > > > > > Thanks
> > > > > > Praveen
> > > > > >
> > > > > >  Hi all,
> > > > > >  I want to validate an xml document with an existing schema. I
> know
> > > > there
> > > > > >  is a code to do it when the schema is present as a URL. BUt in my
> > > case
> > > > > >  schema is present with in the application memory (since it is
> > stored
> > > in
> > > > > >  the database) and that is not the url or on the hard disk.
> > > > > >  I have the following method which validates only when the schema
> is
> > > > > >  present externally. Note that the argument Schema is a URL:
> > > > > >  public static void DOMValidate(String XMLfile, String Schema){
> > > > > >    long startTime = System.currentTimeMillis();
> > > > > >
> > > > > >          // Instantiate the DOM parser.
> > > > > >          DOMParser parser = new DOMParser();
> > > > > >
> > > > > >          // set the features
> > > > > >          try{
> > > > > >
> > parser.setFeature("http://xml.org/sax/features/namespaces
> > > > > >  ",true);
> > > > > >
> > > 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-checking",true);
> > > > > >              // convert the xml file name to a URL
> > > > > >              String SystemId = null;
> > > > > >              try{
> > > > > >                  SystemId = new
> > File(Schema).toURL().toExternalForm();
> > > > > >              } catch(java.net.MalformedURLException ex){
> > > > > >                  //ex.printStackTrace();
> > > > > >                  log.error(ex);
> > > > > >              }
> > > > > >              parser.setProperty("
> > > > > >
> > > > >
> > >
> http://apache.org/xml/properties/schema/external-noNamespaceSchemaLocation
> > > > > >  ",SystemId);
> > > > > >              // myErrorHandler is a descendant of ErrorHandler, it
> > > > should
> > > > > >  be set here to be able to catch parse errors
> > > > > >              parser.setErrorHandler(new SchemaErrorHandler());
> > > > > >
> > > > > >          } catch (SAXNotSupportedException ex){
> > > > > >              System.out.println("SAXNotSupportedException
> > Exception");
> > > > > >          } catch (SAXNotRecognizedException ex){
> > > > > >                  System.out.println("SAXNotRecognizedException
> > > > > Exception");
> > > > > >          }
> > > > > >
> > > > > >          // parse the xml file, the errorhandler class has
> > callbacks,
> > > > > >          // so those will be called automatically there is a parse
> > > error
> > > > > >          try{
> > > > > >                  parser.parse(new
> > > > File(XMLfile).toURL().toExternalForm());
> > > > > >                  //System.out.println("Parsed Successfully by DOM
> > > > > Parser");
> > > > > >          } catch (org.xml.sax.SAXException ex){
> > > > > >                  //System.out.println("SAXException Exception");
> > > > > >                  //ex.printStackTrace();
> > > > > >              log.error(ex);
> > > > > >          } catch (java.io.IOException ex){
> > > > > >                  System.out.println("IOException Exception");
> > > > > >     } finally {
> > > > > >     long endTime = System.currentTimeMillis();
> > > > > >           //System.out.println("Total time of DOMValidate:"
> > > > > >  +(endTime-startTime));
> > > > > >
> > > > > >   }
> > > > > >
> > > > > >      }
> > > > > >
> > > > > >  How can I do the validation if the Schema is the actual schema
> > string
> > > > not
> > > > > >  the url. This looks like a common problem. I assume that its not
> > > > > universal
> > > > > >  that schema is not always stored externally.
> > > > > >
> > > > > >  Any suggestions are appreciated.
> > > > > >
> > > > > >  Praveen
> > > > > >
> > > > > >
> > > > > >
> > > > >
> > > ---------------------------------------------------------------------
> > > > > > To unsubscribe, e-mail: xerces-j-user-unsubscribe@(protected)
> > > > > > For additional commands, e-mail: xerces-j-user-help@(protected)
> > > > > >
> > > > > >
> > > > >
> > > > >
> > > >
> > ---------------------------------------------------------------------
> > > > > To unsubscribe, e-mail: xerces-j-user-unsubscribe@(protected)
> > > > > For additional commands, e-mail: xerces-j-user-help@(protected)
> > > > >
> > > > >
> > > >
> > > >
> > > > ---------------------------------------------------------------------
> > > > To unsubscribe, e-mail: xerces-j-user-unsubscribe@(protected)
> > > > For additional commands, e-mail: xerces-j-user-help@(protected)
> > > >
> > > >
> > >
> > >
> > > ---------------------------------------------------------------------
> > > To unsubscribe, e-mail: xerces-j-user-unsubscribe@(protected)
> > > For additional commands, e-mail: xerces-j-user-help@(protected)
> > >
> >
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: xerces-j-user-unsubscribe@(protected)
> > For additional commands, e-mail: xerces-j-user-help@(protected)
> >
> >
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: xerces-j-user-unsubscribe@(protected)
> For additional commands, e-mail: xerces-j-user-help@(protected)
>
>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META http-equiv=Content-Type content="text/html; charset=iso-8859-1">
<META content="MSHTML 6.00.2800.1106" name=GENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY>
<DIV><FONT face=Arial size=2>Hi Jeff,</FONT></DIV>
<DIV><FONT face=Arial size=2>I did exactly what you told and it doesn't seem to
work. Please look at the following code and see if I am doing anything
wrong.</FONT></DIV>
<DIV><FONT face=Arial size=2>The error I get is:</FONT></DIV>
<DIV><FONT color=#ff0000>**Parsing Error**<BR>&nbsp; Line:&nbsp;&nbsp;&nbsp;
1<BR>&nbsp; URI:&nbsp;&nbsp;&nbsp;&nbsp; null<BR>&nbsp; Message: cvc-elt.1:
Cannot find the declaration of element 'content'.<BR>SAXException
Exception<BR>Total time of SAXValidate:3546<BR>org.xml.sax.SAXException: Error
Validating the content XML.<BR>&nbsp;at
XMLValidator.validateXmlAgainstLocalSchema(XMLValidator.java:105)</FONT></DIV>
<DIV><FONT color=#ff0000></FONT>&nbsp;</DIV>
<DIV><FONT face=Arial size=2>My Entity Resolver is:</FONT></DIV>
<DIV><FONT face=Arial color=#0000ff size=2>public class SchemaEntityResolver
implements EntityResolver {<BR>&nbsp;<BR>&nbsp;InputSource source;<BR>&nbsp;
EntityResolver defaultResolver;<BR>&nbsp; String fakeLocationURI;</FONT></DIV>
<DIV><FONT face=Arial color=#0000ff size=2></FONT>&nbsp;</DIV>
<DIV><FONT face=Arial color=#0000ff size=2>&nbsp;<BR>&nbsp;public
SchemaEntityResolver(EntityResolver defaultResolver, String
mySchemaString,<BR>String fakeLocationURI) {<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
source = new InputSource(new
StringReader(mySchemaString));<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
this.defaultResolver = defaultResolver;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
this.fakeLocationURI = fakeLocationURI;<BR>&nbsp; }</FONT></DIV>
<DIV><FONT face=Arial color=#0000ff size=2></FONT>&nbsp;</DIV>
<DIV><FONT face=Arial color=#0000ff size=2>&nbsp;<BR>&nbsp;&nbsp;&nbsp; public
InputSource resolveEntity(String pubId, String
sysId)<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; throws IOException,
SAXException {<BR>&nbsp;&nbsp;if ((pubId != null &amp;&amp;
pubId.equals(fakeLocationURI))<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;
|| (sysId != null &amp;&amp; sysId.equals(fakeLocationURI)))
{<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;return
source;<BR>&nbsp;&nbsp;&nbsp; &nbsp;}<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return
defaultResolver.resolveEntity(pubId, sysId);</FONT></DIV>
<DIV><FONT face=Arial color=#0000ff size=2>&nbsp;&nbsp;&nbsp;
}<BR>&nbsp;}</FONT></DIV>
<DIV><FONT face=Arial size=2></FONT>&nbsp;</DIV>
<DIV><FONT face=Arial size=2>And My validate method is as follows:</FONT></DIV>
<DIV><FONT face=Arial size=2></FONT>&nbsp;</DIV>
<DIV><FONT face=Arial color=#0000ff size=2>public static void
validateXmlAgainstLocalSchema(String XMLString, String schemaString) throws
SAXException{<BR>&nbsp;&nbsp;&nbsp;long startTime =
System.currentTimeMillis();<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;
System.out.println("Files: XML:" + XMLString + " XSD:" +
schemaString);<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;
XMLReader parser =
null;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; //
Instantiate a
parser<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
try{<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp
;&nbsp;&nbsp;&nbsp;
parser =&nbsp;
XMLReaderFactory.createXMLReader("org.apache.xerces.parsers.SAXParser");<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
} catch (org.xml.sax.SAXException
ex){<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp
;&nbsp;&nbsp;&nbsp;
System.out.println("SAXException Exception");<BR>&nbsp;&nbsp;&nbsp;&nbsp;throw
new SAXException("Error Obtaining the
parser.");<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp
;
}</FONT></DIV>
<DIV><FONT color=#0000ff></FONT>&nbsp;</DIV>
<DIV><FONT face=Arial color=#0000ff
size=2>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
try{</FONT></DIV>
<DIV><FONT color=#0000ff></FONT>&nbsp;</DIV>
<DIV><FONT face=Arial color=#0000ff
size=2>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;
// Register the error
handler<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;
parser.setErrorHandler(new SchemaErrorHandler());</FONT></DIV>
<DIV><FONT color=#0000ff></FONT>&nbsp;</DIV>
<DIV><FONT face=Arial size=2><FONT
color=#0000ff>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp
;&nbsp;&nbsp;&nbsp;&nbsp;
//parser.setFeature("</FONT><A
href="http://apache.org/xml/features/continue-after-fatal-error">http://apache
.org/xml/features/continue-after-fatal-error</A><FONT
color=#0000ff>",
true);<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;
// Turn on
validation<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp
;&nbsp;&nbsp;&nbsp;&nbsp;
parser.setFeature("</FONT><A
href='http://xml.org/sax/features/namespaces",true'>http://xml.org/sax/features
/namespaces",true</A><FONT
color=#0000ff>);<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp
;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
parser.setFeature("</FONT><A
href="http://xml.org/sax/features/validation">http://xml.org/sax/features
/validation</A><FONT
color=#0000ff>",
true);<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;
parser.setFeature("</FONT><A
href='http://apache.org/xml/features/validation/schema",true'>http://apache.org
/xml/features/validation/schema",true</A><FONT
color=#0000ff>);<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp
;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
parser.setFeature("</FONT><A
href='http://apache.org/xml/features/validation/schema-full-checking",true'
>http://apache.org/xml/features/validation/schema-full-checking",true</A><FONT
color=#0000ff>);<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp
;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
//parser.setProperty("</FONT><A
href='http://apache.org/xml/properties/schema/external
-noNamespaceSchemaLocation",Schema'>http://apache.org/xml/properties/schema
/external-noNamespaceSchemaLocation",Schema</A><FONT
color=#0000ff>);<BR>&nbsp;&nbsp;&nbsp;&nbsp;parser.setEntityResolver(new
SchemaEntityResolver(parser.getEntityResolver(), schemaString, "</FONT><A
href="http://www.contextmedia.com">http://www.contextmedia.com</A><FONT
color=#0000ff>"));</FONT></FONT></DIV>
<DIV><FONT color=#0000ff></FONT>&nbsp;</DIV><FONT face=Arial size=2>
<DIV><BR><FONT
color=#0000ff>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp
;
} catch (org.xml.sax.SAXNotRecognizedException
ex){<BR>&nbsp;&nbsp;&nbsp;&nbsp;ex.printStackTrace();<BR>&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;
System.out.println("SAXNotRecognizedException
Exception");&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
} catch (org.xml.sax.SAXNotSupportedException
ex){<BR>&nbsp;&nbsp;&nbsp;&nbsp;ex.printStackTrace();<BR>&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;
System.out.println("SAXNotSupportedException
Exception");<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;
}</FONT></DIV>
<DIV><FONT color=#0000ff></FONT>&nbsp;</DIV>
<DIV><FONT
color=#0000ff>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp
;
// Parse the
document<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
try{<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp
;&nbsp;&nbsp;&nbsp;
//String XMLSystemId = new
File(XMLString).toURL().toExternalForm();<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
parser.parse(new InputSource(new
StringReader(XMLString)));<BR>&nbsp;&nbsp;&nbsp;&nbsp;//parser.parse
(XMLSystemId);<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
System.out.println("Parsed Successfully by SAX
Parser");<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
} catch (org.xml.sax.SAXException
ex){<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp
;&nbsp;&nbsp;&nbsp;
System.out.println("SAXException Exception");<BR>&nbsp;&nbsp;&nbsp;&nbsp;throw
new SAXException("Error Validating the content
XML.");<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }
catch (java.io.IOException
ex){<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp
;&nbsp;&nbsp;&nbsp;
System.out.println("IOException Exception");<BR>&nbsp;&nbsp;&nbsp;&nbsp;throw
new SAXException("Error Validating the content
XML.");<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }
finally {<BR>&nbsp;&nbsp;&nbsp;long endTime =
System.currentTimeMillis();<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;System.out.println("Total time of
SAXValidate:"+(endTime-startTime));&nbsp;<BR>&nbsp;&nbsp;&nbsp;}<BR>&nbsp;&nbsp
;&nbsp;
}</FONT></DIV>
<DIV></FONT>&nbsp;</DIV>
<DIV><FONT face=Arial size=2>----- Original Message ----- </FONT></DIV>
<DIV><FONT face=Arial size=2>From: "Jeff Greif" &lt;</FONT><A
href="mailto:jgreif@(protected)"><FONT face=Arial
size=2>jgreif@(protected)</FONT></A><FONT face=Arial
size=2>&gt;</FONT></DIV>
<DIV><FONT face=Arial size=2>To: &lt;</FONT><A
href="mailto:xerces-j-user@(protected)"><FONT face=Arial
size=2>xerces-j-user@(protected)</FONT></A><FONT face=Arial
size=2>&gt;</FONT></DIV>
<DIV><FONT face=Arial size=2>Sent: Thursday, January 23, 2003 3:07
PM</FONT></DIV>
<DIV><FONT face=Arial size=2>Subject: Re: XML validation using xml schema
string</FONT></DIV>
<DIV><FONT face=Arial><BR><FONT size=2></FONT></FONT></DIV><FONT face=Arial
size=2>&gt; Something like this (just typed into mail message, neither compiled
nor<BR>&gt; tested).<BR>&gt; <BR>&gt; in main:<BR>&gt; <BR>&gt;
&nbsp;&nbsp;&nbsp; DomParser parser = new DomParser();<BR>&gt;
&nbsp;&nbsp;&nbsp; parser.setEntityResolver(new<BR>&gt;
MyEntityResolver(parser.getEntityResolver(),<BR>&gt; <BR>&gt; mySchemaString,
myfakeSchemaLocationURI));<BR>&gt; <BR>&gt; class MyEntityResolver {<BR>&gt;
&nbsp; InputSource source;<BR>&gt; &nbsp; EntityResolver
defaultResolver;<BR>&gt; &nbsp; String fakeLocationURI;<BR>&gt; &nbsp;&nbsp;
public MyEntityResolver(EntityResolver default, String mySchemaString,<BR>&gt;
String fakeLocationURI) {<BR>&gt; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; source = new
InputSource(new StringReader(mySchemaString));<BR>&gt;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; defaultResolver = default;<BR>&gt;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; this.fakeLocationURI =
fakeLocationURI;<BR>&gt; &nbsp; }<BR>&gt; &nbsp; public InputSource
resolveEntity(String pubId, String sysId) {<BR>&gt;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if ((pubId != null &amp;&amp;
pubId.equals(fakeLocationURI))<BR>&gt;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; || (sysId != null
&amp;&amp; sysId.equals(fakeLocationURI))) {<BR>&gt;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return source;<BR>&gt;
&nbsp;&nbsp;&nbsp; }<BR>&gt; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return
defaultResolver.resolveEntity(pubId, sysId);<BR>&gt; &nbsp; }<BR>&gt; <BR>&gt;
}<BR>&gt; <BR>&gt; Jeff<BR>&gt; ----- Original Message -----<BR>&gt; From:
"Praveen Peddi" &lt;</FONT><A href="mailto:ppeddi@(protected)"><FONT
face=Arial size=2>ppeddi@(protected)</FONT></A><FONT face=Arial
size=2>&gt;<BR>&gt; To: &lt;</FONT><A
href="mailto:xerces-j-user@(protected)"><FONT face=Arial
size=2>xerces-j-user@(protected)</FONT></A><FONT face=Arial
size=2>&gt;<BR>&gt; Sent: Thursday, January 23, 2003 10:51 AM<BR>&gt; Subject:
Re: XML validation using xml schema string<BR>&gt; <BR>&gt; <BR>&gt; &gt;
Jeff,<BR>&gt; &gt; I think I didn't get you completely.<BR>&gt; &gt;<BR>&gt;
&gt; Could you please write a sample code or modify my code below so that I
can<BR>&gt; &gt; understand what you are syaing.<BR>&gt; &gt;<BR>&gt; &gt;
Thanks<BR>&gt; &gt; Praveen<BR>&gt; &gt; ----- Original Message -----<BR>&gt;
&gt; From: "Jeff Greif" &lt;</FONT><A
href="mailto:jgreif@(protected)"><FONT face=Arial
size=2>jgreif@(protected)</FONT></A><FONT face=Arial
size=2>&gt;<BR>&gt; &gt; To: &lt;</FONT><A
href="mailto:xerces-j-user@(protected)"><FONT face=Arial
size=2>xerces-j-user@(protected)</FONT></A><FONT face=Arial
size=2>&gt;<BR>&gt; &gt; Sent: Thursday, January 23, 2003 11:28 AM<BR>&gt; &gt;
Subject: Re: XML validation using xml schema string<BR>&gt; &gt;<BR>&gt;
&gt;<BR>&gt; &gt; &gt; I'm not able to give information correct in detail, but
here is an<BR>&gt; outline<BR>&gt; &gt; &gt; of what must happen:<BR>&gt; &gt;
&gt;<BR>&gt; &gt; &gt; The entity resolver is called with a namespace URI or a
schema location<BR>&gt; as<BR>&gt; &gt; &gt; an argument, I think.&nbsp; In the
course of parsing your instance document<BR>&gt; &gt; (.xml<BR>&gt; &gt; &gt;
file), it will be called to process your schema's namespace and possibly<BR>&gt
;
&gt; &gt; other namespaces (e.g. the XMLSchema-instance namespace)
mentioned<BR>&gt; &gt; therein.<BR>&gt; &gt; &gt; Probably you should get the
default entity resolver for the parser<BR>&gt; (which<BR>&gt; &gt; &gt; knows
how to handle some things, presumably), and create your own entity<BR>&gt; &gt;
&gt; resolver holding that one as a member.&nbsp; Then when asked for a
particular<BR>&gt; &gt; &gt; schema by its namespace or location, if it's your
schema, return the<BR>&gt; input<BR>&gt; &gt; &gt; source as your code below
does, otherwise, pass the request to the<BR>&gt; member<BR>&gt; &gt; &gt;
resolver which knows better than you what to do.<BR>&gt; &gt; &gt;<BR>&gt; &gt;
&gt; Jeff<BR>&gt; &gt; &gt;<BR>&gt; &gt; &gt; ----- Original Message
-----<BR>&gt; &gt; &gt; From: "Praveen Peddi" &lt;</FONT><A
href="mailto:ppeddi@(protected)"><FONT face=Arial
size=2>ppeddi@(protected)</FONT></A><FONT face=Arial size=2>&gt;<BR>&gt;
&gt; &gt; To: &lt;</FONT><A href="mailto:xerces-j-user@(protected)"><FONT
face=Arial size=2>xerces-j-user@(protected)</FONT></A><FONT face=Arial
size=2>&gt;<BR>&gt; &gt; &gt; Sent: Thursday, January 23, 2003 7:44 AM<BR>&gt;
&gt; &gt; Subject: Re: XML validation using xml schema string<BR>&gt; &gt;
&gt;<BR>&gt; &gt; &gt;<BR>&gt; &gt; &gt; &gt; I posted a question yesterday
about the validation of XML against the<BR>&gt; &gt; &gt; local<BR>&gt; &gt;
&gt; &gt; schema (in memory). Could anyone please look at the message below
and<BR>&gt; &gt; &gt; reply<BR>&gt; &gt; &gt; &gt; if you know the
answer.<BR>&gt; &gt; &gt; &gt;<BR>&gt; &gt; &gt; &gt; Thanks in Advance.<BR>&gt
;
&gt; &gt; &gt;<BR>&gt; &gt; &gt; &gt; Praveen<BR>&gt; &gt; &gt; &gt; -----
Original Message -----<BR>&gt; &gt; &gt; &gt; From: "Praveen Peddi"
&lt;</FONT><A href="mailto:ppeddi@(protected)"><FONT face=Arial
size=2>ppeddi@(protected)</FONT></A><FONT face=Arial size=2>&gt;<BR>&gt;
&gt; &gt; &gt; To: &lt;</FONT><A href="mailto:sandygao@(protected)"><FONT
face=Arial size=2>sandygao@(protected)</FONT></A><FONT face=Arial size=2>&gt;;
&lt;</FONT><A href="mailto:xerces-j-user@(protected)"><FONT face=Arial
size=2>xerces-j-user@(protected)</FONT></A><FONT face=Arial
size=2>&gt;<BR>&gt; &gt; &gt; &gt; Sent: Wednesday, January 22, 2003 1:35
PM<BR>&gt; &gt; &gt; &gt; Subject: Re: XML validation using xml schema
string<BR>&gt; &gt; &gt; &gt;<BR>&gt; &gt; &gt; &gt;<BR>&gt; &gt; &gt; &gt; &gt
;
As you said I wrote an EntityResolver but it didn't work. Could you<BR>&gt; &gt
;
send<BR>&gt; &gt; &gt; &gt; me<BR>&gt; &gt; &gt; &gt; &gt; a sample code (just
the validation code) if u already have one.<BR>&gt; &gt; &gt; &gt; &gt;<BR>&gt;
&gt; &gt; &gt; &gt; My validate method looks as follows:<BR>&gt; &gt; &gt; &gt;
&gt;<BR>&gt; &gt; &gt; &gt; &gt; public static void
validateXmlAgainstLocalSchema(String XMLString,<BR>&gt; &gt; &gt; String<BR>&gt
;
&gt; &gt; &gt; &gt; schemaString) throws SAXException{<BR>&gt; &gt; &gt; &gt;
&gt;&nbsp;&nbsp;&nbsp; long startTime = System.currentTimeMillis();<BR>&gt; &gt
;
&gt; &gt;
&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
System.out.println("Files: XML:" + XMLString + " XSD:" +<BR>&gt; &gt; &gt; &gt;
&gt; schemaString);<BR>&gt; &gt; &gt; &gt;
&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
XMLReader parser = null;<BR>&gt; &gt; &gt; &gt;
&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; //
Instantiate a parser<BR>&gt; &gt; &gt; &gt;
&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
try{<BR>&gt; &gt; &gt; &gt;
&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;
parser =<BR>&gt; &gt; &gt; &gt; &gt;<BR>&gt; &gt;
XMLReaderFactory.createXMLReader("org.apache.xerces.parsers.SAXParser");<BR>&gt
;
&gt; &gt; &gt;
&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }
catch (org.xml.sax.SAXException ex){<BR>&gt; &gt; &gt; &gt;
&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;
System.out.println("SAXException Exception");<BR>&gt; &gt; &gt; &gt;
&gt;&nbsp;&nbsp;&nbsp;&nbsp; throw new SAXException("Error Obtaining the
parser.");<BR>&gt; &gt; &gt; &gt;
&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
}<BR>&gt; &gt; &gt; &gt; &gt;<BR>&gt; &gt; &gt; &gt;
&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
try{<BR>&gt; &gt; &gt; &gt; &gt;<BR>&gt; &gt; &gt; &gt;
&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;
// Register the error handler<BR>&gt; &gt; &gt; &gt;
&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;
parser.setErrorHandler(new SchemaErrorHandler());<BR>&gt; &gt; &gt; &gt;
&gt;<BR>&gt; &gt; &gt; &gt; &gt;<BR>&gt; &gt; &gt; &gt; &gt;<BR>&gt; &gt; &gt;
&gt;<BR>&gt; &gt; &gt;<BR>&gt; &gt;<BR>&gt; //parser.setFeature("</FONT><A
href="http://apache.org/xml/features/continue-after-fatal-err"><FONT face=Arial
size=2>http://apache.org/xml/features/continue-after-fatal-err</FONT></A><BR>
<FONT
face=Arial size=2>&gt; &gt; &gt; &gt; &gt; or", true);<BR>&gt; &gt; &gt; &gt;
&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;
// Turn on validation<BR>&gt; &gt; &gt; &gt; &gt;<BR>&gt; &gt; &gt; &gt; &gt;
parser.setFeature("</FONT><A
href='http://xml.org/sax/features/namespaces",true'><FONT face=Arial
size=2>http://xml.org/sax/features/namespaces",true</FONT></A><FONT face=Arial
size=2>);<BR>&gt; &gt; &gt; &gt; &gt;<BR>&gt; &gt; &gt; &gt;
parser.setFeature("</FONT><A href="http://xml.org/sax/features/validation">
<FONT
face=Arial size=2>http://xml.org/sax/features/validation</FONT></A><FONT
face=Arial size=2>",<BR>&gt; &gt; &gt; &gt; &gt; true);<BR>&gt; &gt; &gt; &gt;
&gt;<BR>&gt; &gt; &gt; &gt; &gt;<BR>&gt; &gt; &gt; &gt;<BR>&gt; &gt;
&gt;<BR>&gt; &gt;<BR>&gt; parser.setFeature("</FONT><A
href='http://apache.org/xml/features/validation/schema",true'><FONT face=Arial
size=2>http://apache.org/xml/features/validation/schema",true</FONT></A><FONT
face=Arial size=2>);<BR>&gt; &gt; &gt; &gt; &gt;<BR>&gt; &gt; &gt; &gt;
&gt;<BR>&gt; &gt; &gt; &gt;<BR>&gt; &gt; &gt;<BR>&gt; &gt;<BR>&gt;
parser.setFeature("</FONT><A
href="http://apache.org/xml/features/validation/schema-full-che"><FONT
face=Arial
size=2>http://apache.org/xml/features/validation/schema-full-che</FONT></A><BR>
<FONT
face=Arial size=2>&gt; &gt; &gt; &gt; &gt; cking",true);<BR>&gt; &gt; &gt; &gt;
&gt;<BR>&gt; &gt; &gt; &gt; &gt;<BR>&gt; &gt; &gt; &gt;<BR>&gt; &gt;
&gt;<BR>&gt; &gt;<BR>&gt; //parser.setProperty("</FONT><A
href="http://apache.org/xml/properties/schema/external-noNam"><FONT face=Arial
size=2>http://apache.org/xml/properties/schema/external-noNam</FONT></A><BR>
<FONT
face=Arial size=2>&gt; &gt; &gt; &gt; &gt;
espaceSchemaLocation",Schema);<BR>&gt; &gt; &gt; &gt;
&gt;&nbsp;&nbsp;&nbsp;&nbsp; parser.setEntityResolver(new<BR>&gt;
SchemaEntityResolver(schemaString));<BR>&gt; &gt; &gt; &gt; &gt;<BR>&gt; &gt;
&gt; &gt; &gt;<BR>&gt; &gt; &gt; &gt;
&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }
catch (org.xml.sax.SAXNotRecognizedException ex){<BR>&gt; &gt; &gt; &gt;
&gt;&nbsp;&nbsp;&nbsp;&nbsp; ex.printStackTrace();<BR>&gt; &gt; &gt; &gt;
&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
System.out.println("SAXNotRecognizedException<BR>&gt; &gt; &gt; &gt; &gt;
Exception");<BR>&gt; &gt; &gt; &gt;
&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }
catch (org.xml.sax.SAXNotSupportedException ex){<BR>&gt; &gt; &gt; &gt;
&gt;&nbsp;&nbsp;&nbsp;&nbsp; ex.printStackTrace();<BR>&gt; &gt; &gt; &gt;
&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
System.out.println("SAXNotSupportedException<BR>&gt; &gt; &gt; &gt; &gt;
Exception");<BR>&gt; &gt; &gt; &gt;
&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
}<BR>&gt; &gt; &gt; &gt; &gt;<BR>&gt; &gt; &gt; &gt;
&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; //
Parse the document<BR>&gt; &gt; &gt; &gt;
&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
try{<BR>&gt; &gt; &gt; &gt;
&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;
//String XMLSystemId = new<BR>&gt; &gt; &gt; &gt; &gt;
File(XMLString).toURL().toExternalForm();<BR>&gt; &gt; &gt; &gt;
&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;
parser.parse(new InputSource(new<BR>&gt; &gt; &gt; &gt;
StringReader(XMLString)));<BR>&gt; &gt; &gt; &gt; &gt;&nbsp;&nbsp;&nbsp;&nbsp;
//parser.parse(XMLSystemId);<BR>&gt; &gt; &gt; &gt;
&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;
System.out.println("Parsed Successfully by SAX<BR>&gt; &gt; Parser");<BR>&gt;
&gt; &gt; &gt;
&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }
catch (org.xml.sax.SAXException ex){<BR>&gt; &gt; &gt; &gt;
&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;
System.out.println("SAXException Exception");<BR>&gt; &gt; &gt; &gt;
&gt;&nbsp;&nbsp;&nbsp;&nbsp; throw new SAXException("Error Validating the
content XML.");<BR>&gt; &gt; &gt; &gt;
&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }
catch (java.io.IOException ex){<BR>&gt; &gt; &gt; &gt;
&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;
System.out.println("IOException Exception");<BR>&gt; &gt; &gt; &gt;
&gt;&nbsp;&nbsp;&nbsp;&nbsp; throw new SAXException("Error Validating the
content XML.");<BR>&gt; &gt; &gt; &gt;
&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }
finally {<BR>&gt; &gt; &gt; &gt; &gt;&nbsp;&nbsp;&nbsp; long endTime =
System.currentTimeMillis();<BR>&gt; &gt; &gt; &gt;
&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
System.out.println("Total time of<BR>&gt; &gt; &gt; &gt; &gt;
SAXValidate:"+(endTime-startTime));<BR>&gt; &gt; &gt; &gt;
&gt;&nbsp;&nbsp;&nbsp; }<BR>&gt; &gt; &gt; &gt; &gt;&nbsp;&nbsp;&nbsp;&nbsp;
}//SAXValidate<BR>&gt; &gt; &gt; &gt; &gt;<BR>&gt; &gt; &gt; &gt; &gt; And
SchemaEntityResolver looks as follows:<BR>&gt; &gt; &gt; &gt; &gt;<BR>&gt; &gt;
&gt; &gt; &gt; public class SchemaEntityResolver implements EntityResolver
{<BR>&gt; &gt; &gt; &gt; &gt;&nbsp; InputSource source = null;<BR>&gt; &gt; &gt
;
&gt; &gt;&nbsp; public SchemaEntityResolver(String schemaString) {<BR>&gt; &gt;
&gt; &gt; &gt;&nbsp;&nbsp; source = new InputSource(new
StringReader(schemaString));<BR>&gt; &gt; &gt; &gt; &gt;&nbsp; }<BR>&gt; &gt;
&gt; &gt; &gt;<BR>&gt; &gt; &gt; &gt; &gt;&nbsp;&nbsp;&nbsp;&nbsp; public
InputSource resolveEntity(String publicID, String<BR>&gt; systemID)<BR>&gt; &gt
;
&gt; &gt; &gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; throws
SAXException {<BR>&gt; &gt; &gt; &gt;
&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
return source;<BR>&gt; &gt; &gt; &gt; &gt;&nbsp;&nbsp;&nbsp;&nbsp; }<BR>&gt;
&gt; &gt; &gt; &gt; }<BR>&gt; &gt; &gt; &gt; &gt;<BR>&gt; &gt; &gt; &gt; &gt;
When I try to validate an xml with the schema string, I get the<BR>&gt; &gt;
&gt; following<BR>&gt; &gt; &gt; &gt; &gt; error:<BR>&gt; &gt; &gt; &gt; &gt;
Line:&nbsp;&nbsp;&nbsp; 1<BR>&gt; &gt; &gt; &gt; &gt;&nbsp;&nbsp;
URI:&nbsp;&nbsp;&nbsp;&nbsp; null<BR>&gt; &gt; &gt; &gt; &gt;&nbsp;&nbsp;
Message: cvc-elt.1: Cannot find the declaration of element<BR>&gt; &gt;
'content'.<BR>&gt; &gt; &gt; &gt; &gt;<BR>&gt; &gt; &gt; &gt; &gt;<BR>&gt; &gt;
&gt; &gt; &gt; Am I doing it wrong? If so please tell me how to use the<BR>&gt;
&gt; entityresolver.<BR>&gt; &gt; &gt; &gt; &gt;<BR>&gt; &gt; &gt; &gt; &gt;
Praveen<BR>&gt; &gt; &gt; &gt; &gt;<BR>&gt; &gt; &gt; &gt; &gt;<BR>&gt; &gt;
&gt; &gt; &gt; ----- Original Message -----<BR>&gt; &gt; &gt; &gt; &gt; From:
&lt;</FONT><A href="mailto:sandygao@(protected)"><FONT face=Arial
size=2>sandygao@(protected)</FONT></A><FONT face=Arial size=2>&gt;<BR>&gt; &gt;
&gt; &gt; &gt; To: &lt;</FONT><A
href="mailto:xerces-j-user@(protected)"><FONT face=Arial
size=2>xerces-j-user@(protected)</FONT></A><FONT face=Arial
size=2>&gt;<BR>&gt; &gt; &gt; &gt; &gt; Sent: Monday, January 20, 2003 10:18
AM<BR>&gt; &gt; &gt; &gt; &gt; Subject: Re: XML validation using xml schema
string<BR>&gt; &gt; &gt; &gt; &gt;<BR>&gt; &gt; &gt; &gt; &gt;<BR>&gt; &gt; &gt
;
&gt; &gt; &gt; Write an entity resolver<BR>&gt; &gt; &gt; &gt; &gt; &gt;<BR>&gt
;
&gt; &gt; &gt; &gt;<BR>&gt; &gt; &gt; &gt;<BR>&gt; &gt; &gt;<BR>&gt;
&gt;<BR>&gt; (</FONT><A
href="http://xml.apache.org/xerces2-j/javadocs/api/org/xml/sax/EntityResolver
.htm"><FONT
face=Arial
size=2>http://xml.apache.org/xerces2-j/javadocs/api/org/xml/sax/EntityResolver
.htm</FONT></A><BR><FONT
face=Arial size=2>&gt; &gt; &gt; &gt; &gt; l),<BR>&gt; &gt; &gt; &gt; &gt;
&gt;<BR>&gt; &gt; &gt; &gt; &gt; &gt; and returned an input source with a
StringReader when the schema<BR>&gt; &gt; &gt; &gt; document<BR>&gt; &gt; &gt;
&gt; &gt; &gt; is asked.<BR>&gt; &gt; &gt; &gt; &gt; &gt;<BR>&gt; &gt; &gt; &gt
;
&gt; &gt; HTH,<BR>&gt; &gt; &gt; &gt; &gt; &gt; Sandy Gao<BR>&gt; &gt; &gt; &gt
;
&gt; &gt; Software Developer, IBM Canada<BR>&gt; &gt; &gt; &gt; &gt; &gt;
(1-905) 413-3255<BR>&gt; &gt; &gt; &gt; &gt; &gt; </FONT><A
href="mailto:sandygao@(protected)"><FONT face=Arial
size=2>sandygao@(protected)</FONT></A><BR><FONT face=Arial size=2>&gt; &gt; &gt;
&gt; &gt; &gt;<BR>&gt; &gt; &gt; &gt; &gt; &gt;<BR>&gt; &gt; &gt; &gt; &gt;
&gt;<BR>&gt; &gt; &gt; &gt; &gt; &gt;<BR>&gt; &gt; &gt; &gt; &gt;
&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
"Praveen Peddi"<BR>&gt; &gt; &gt; &gt; &gt;
&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&lt;</FONT><A href="mailto:ppeddi@(protected)"><FONT face=Arial
size=2>ppeddi@(protected)</FONT></A><FONT face=Arial
size=2>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; To:<BR>&gt; &gt; &gt; &gt;
&gt; &lt;</FONT><A href="mailto:xerces-j-user@(protected)"><FONT face=Arial
size=2>xerces-j-user@(protected)</FONT></A><FONT face=Arial
size=2>&gt;<BR>&gt; &gt; &gt; &gt; &gt;
&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
dia.com&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
cc:<BR>&gt; &gt; &gt; &gt; &gt;
&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
Subject:&nbsp; Re: XML<BR>&gt; &gt; &gt; &gt; &gt; validation using xml schema
string<BR>&gt; &gt; &gt; &gt; &gt;
&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
01/20/2003 09:16<BR>&gt; &gt; &gt; &gt; &gt;
&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
AM<BR>&gt; &gt; &gt; &gt; &gt;
&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
Please respond to<BR>&gt; &gt; &gt; &gt; &gt;
&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
xerces-j-user<BR>&gt; &gt; &gt; &gt; &gt; &gt;<BR>&gt; &gt; &gt; &gt; &gt;
&gt;<BR>&gt; &gt; &gt; &gt; &gt; &gt;<BR>&gt; &gt; &gt; &gt; &gt; &gt;<BR>&gt;
&gt; &gt; &gt; &gt; &gt;<BR>&gt; &gt; &gt; &gt; &gt; &gt; Hi all,<BR>&gt; &gt;
&gt; &gt; &gt; &gt; Last week I sent an email regarding the xml validation
against the<BR>&gt; &gt; &gt; &gt; schema,<BR>&gt; &gt; &gt; &gt; &gt; &gt; but
didn't get any reply. Please reply if any one has answer to my<BR>&gt; &gt; &gt
;
&gt; &gt; &gt; question. Is it possible to validate an xml document using
a<BR>&gt; schema<BR>&gt; &gt; &gt; &gt; &gt; &gt; document (not the schema url)
that is present with in the<BR>&gt; &gt; application.<BR>&gt; &gt; &gt; &gt;
If<BR>&gt; &gt; &gt; &gt; &gt; &gt; its not possible, whats the best way of
achieving it. Please read<BR>&gt; my<BR>&gt; &gt; &gt; &gt; &gt; &gt; previous
email below.<BR>&gt; &gt; &gt; &gt; &gt; &gt;<BR>&gt; &gt; &gt; &gt; &gt; &gt;
Thanks<BR>&gt; &gt; &gt; &gt; &gt; &gt; Praveen<BR>&gt; &gt; &gt; &gt; &gt;
&gt;<BR>&gt; &gt; &gt; &gt; &gt; &gt;&nbsp; Hi all,<BR>&gt; &gt; &gt; &gt; &gt;
&gt;&nbsp; I want to validate an xml document with an existing schema. I<BR>&gt
;
know<BR>&gt; &gt; &gt; &gt; there<BR>&gt; &gt; &gt; &gt; &gt; &gt;&nbsp; is a
code to do it when the schema is present as a URL. BUt in my<BR>&gt; &gt; &gt;
case<BR>&gt; &gt; &gt; &gt; &gt; &gt;&nbsp; schema is present with in the
application memory (since it is<BR>&gt; &gt; stored<BR>&gt; &gt; &gt; in<BR>&gt
;
&gt; &gt; &gt; &gt; &gt;&nbsp; the database) and that is not the url or on the
hard disk.<BR>&gt; &gt; &gt; &gt; &gt; &gt;&nbsp; I have the following method
which validates only when the schema<BR>&gt; is<BR>&gt; &gt; &gt; &gt; &gt;
&gt;&nbsp; present externally. Note that the argument Schema is a URL:<BR>&gt;
&gt; &gt; &gt; &gt; &gt;&nbsp; public static void DOMValidate(String XMLfile,
String Schema){<BR>&gt; &gt; &gt; &gt; &gt; &gt;&nbsp;&nbsp;&nbsp; long
startTime = System.currentTimeMillis();<BR>&gt; &gt; &gt; &gt; &gt; &gt;<BR>&gt
;
&gt; &gt; &gt; &gt; &gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
// Instantiate the DOM parser.<BR>&gt; &gt; &gt; &gt; &gt;
&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; DOMParser parser =
new DOMParser();<BR>&gt; &gt; &gt; &gt; &gt; &gt;<BR>&gt; &gt; &gt; &gt; &gt;
&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // set the
features<BR>&gt; &gt; &gt; &gt; &gt;
&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; try{<BR>&gt; &gt;
&gt; &gt; &gt; &gt;<BR>&gt; &gt; parser.setFeature("</FONT><A
href="http://xml.org/sax/features/namespaces"><FONT face=Arial
size=2>http://xml.org/sax/features/namespaces</FONT></A><BR><FONT face=Arial
size=2>&gt; &gt; &gt; &gt; &gt; &gt;&nbsp; ",true);<BR>&gt; &gt; &gt; &gt; &gt;
&gt;<BR>&gt; &gt; &gt; parser.setFeature("</FONT><A
href="http://xml.org/sax/features/validation"><FONT face=Arial
size=2>http://xml.org/sax/features/validation</FONT></A><FONT face=Arial
size=2>",<BR>&gt; &gt; &gt; &gt; &gt; &gt;&nbsp; true);<BR>&gt; &gt; &gt; &gt;
&gt;
&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;
parser.setFeature("<BR>&gt; &gt; &gt; &gt; &gt; &gt;&nbsp; </FONT><A
href='http://apache.org/xml/features/validation/schema",true'><FONT face=Arial
size=2>http://apache.org/xml/features/validation/schema",true</FONT></A><FONT
face=Arial size=2>);<BR>&gt; &gt; &gt; &gt; &gt;
&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;
parser.setFeature("<BR>&gt; &gt; &gt; &gt; &gt; &gt;<BR>&gt; &gt; &gt; </FONT>
<A
href='http://apache.org/xml/features/validation/schema-full-checking",true'>
<FONT
face=Arial
size=2>http://apache.org/xml/features/validation/schema-full-checking",true<
/FONT></A><FONT
face=Arial size=2>);<BR>&gt; &gt; &gt; &gt; &gt;
&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;
// convert the xml file name to a URL<BR>&gt; &gt; &gt; &gt; &gt;
&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;
String SystemId = null;<BR>&gt; &gt; &gt; &gt; &gt;
&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;
try{<BR>&gt; &gt; &gt; &gt; &gt;
&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
SystemId = new<BR>&gt; &gt; File(Schema).toURL().toExternalForm();<BR>&gt; &gt;
&gt; &gt; &gt;
&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;
} catch(java.net.MalformedURLException ex){<BR>&gt; &gt; &gt; &gt; &gt;
&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
//ex.printStackTrace();<BR>&gt; &gt; &gt; &gt; &gt;
&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
log.error(ex);<BR>&gt; &gt; &gt; &gt; &gt;
&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;
}<BR>&gt; &gt; &gt; &gt; &gt;
&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;
parser.setProperty("<BR>&gt; &gt; &gt; &gt; &gt; &gt;<BR>&gt; &gt; &gt; &gt;
&gt;<BR>&gt; &gt; &gt;<BR>&gt; </FONT><A
href="http://apache.org/xml/properties/schema/external
-noNamespaceSchemaLocation"><FONT
face=Arial
size=2>http://apache.org/xml/properties/schema/external
-noNamespaceSchemaLocation</FONT></A><BR><FONT
face=Arial size=2>&gt; &gt; &gt; &gt; &gt; &gt;&nbsp; ",SystemId);<BR>&gt; &gt;
&gt; &gt; &gt;
&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;
// myErrorHandler is a descendant of ErrorHandler, it<BR>&gt; &gt; &gt; &gt;
should<BR>&gt; &gt; &gt; &gt; &gt; &gt;&nbsp; be set here to be able to catch
parse errors<BR>&gt; &gt; &gt; &gt; &gt;
&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;
parser.setErrorHandler(new SchemaErrorHandler());<BR>&gt; &gt; &gt; &gt; &gt;
&gt;<BR>&gt; &gt; &gt; &gt; &gt;
&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; } catch
(SAXNotSupportedException ex){<BR>&gt; &gt; &gt; &gt; &gt;
&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;
System.out.println("SAXNotSupportedException<BR>&gt; &gt; Exception");<BR>&gt;
&gt; &gt; &gt; &gt; &gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
}
catch (SAXNotRecognizedException ex){<BR>&gt; &gt; &gt; &gt; &gt;
&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
System.out.println("SAXNotRecognizedException<BR>&gt; &gt; &gt; &gt; &gt;
Exception");<BR>&gt; &gt; &gt; &gt; &gt;
&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<BR>&gt; &gt; &gt;
&gt; &gt; &gt;<BR>&gt; &gt; &gt; &gt; &gt;
&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // parse the xml
file, the errorhandler class has<BR>&gt; &gt; callbacks,<BR>&gt; &gt; &gt; &gt;
&gt; &gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // so those
will
be called automatically there is a parse<BR>&gt; &gt; &gt; error<BR>&gt; &gt;
&gt; &gt; &gt; &gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
try{<BR>&gt; &gt; &gt; &gt; &gt;
&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
parser.parse(new<BR>&gt; &gt; &gt; &gt;
File(XMLfile).toURL().toExternalForm());<BR>&gt; &gt; &gt; &gt; &gt;
&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
//System.out.println("Parsed Successfully by DOM<BR>&gt; &gt; &gt; &gt; &gt;
Parser");<BR>&gt; &gt; &gt; &gt; &gt;
&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; } catch
(org.xml.sax.SAXException ex){<BR>&gt; &gt; &gt; &gt; &gt;
&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
//System.out.println("SAXException Exception");<BR>&gt; &gt; &gt; &gt; &gt;
&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
//ex.printStackTrace();<BR>&gt; &gt; &gt; &gt; &gt;
&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;
log.error(ex);<BR>&gt; &gt; &gt; &gt; &gt;
&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; } catch
(java.io.IOException ex){<BR>&gt; &gt; &gt; &gt; &gt;
&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
System.out.println("IOException Exception");<BR>&gt; &gt; &gt; &gt; &gt;
&gt;&nbsp;&nbsp;&nbsp;&nbsp; } finally {<BR>&gt; &gt; &gt; &gt; &gt;
&gt;&nbsp;&nbsp;&nbsp;&nbsp; long endTime = System.currentTimeMillis();<BR>&gt;
&gt; &gt; &gt; &gt;
&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
//System.out.println("Total time of DOMValidate:"<BR>&gt; &gt; &gt; &gt; &gt;
&gt;&nbsp; +(endTime-startTime));<BR>&gt; &gt; &gt; &gt; &gt; &gt;<BR>&gt; &gt;
&gt; &gt; &gt; &gt;&nbsp;&nbsp; }<BR>&gt; &gt; &gt; &gt; &gt; &gt;<BR>&gt; &gt;
&gt; &gt; &gt; &gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<BR>&gt; &gt; &gt; &gt; &gt;
&gt;<BR>&gt; &gt; &gt; &gt; &gt; &gt;&nbsp; How can I do the validation if the
Schema is the actual schema<BR>&gt; &gt; string<BR>&gt; &gt; &gt; &gt;
not<BR>&gt; &gt; &gt; &gt; &gt; &gt;&nbsp; the url. This looks like a common
problem. I assume that its not<BR>&gt; &gt; &gt; &gt; &gt; universal<BR>&gt;
&gt; &gt; &gt; &gt; &gt;&nbsp; that schema is not always stored
externally.<BR>&gt; &gt; &gt; &gt; &gt; &gt;<BR>&gt; &gt; &gt; &gt; &gt;
&gt;&nbsp; Any suggestions are appreciated.<BR>&gt; &gt; &gt; &gt; &gt;
&gt;<BR>&gt; &gt; &gt; &gt; &gt; &gt;&nbsp; Praveen<BR>&gt; &gt; &gt; &gt; &gt;
&gt;<BR>&gt; &gt; &gt; &gt; &gt; &gt;<BR>&gt; &gt; &gt; &gt; &gt; &gt;<BR>&gt;
&gt; &gt; &gt; &gt;<BR>&gt; &gt; &gt;
---------------------------------------------------------------------<BR>&gt;
&gt; &gt; &gt; &gt; &gt; To unsubscribe, e-mail: </FONT><A
href="mailto:xerces-j-user-unsubscribe@(protected)"><FONT face=Arial
size=2>xerces-j-user-unsubscribe@(protected)</FONT></A><BR><FONT face=Arial
size=2>&gt; &gt; &gt; &gt; &gt; &gt; For additional commands, e-mail: </FONT><A
href="mailto:xerces-j-user-help@(protected)"><FONT face=Arial
size=2>xerces-j-user-help@(protected)</FONT></A><BR><FONT face=Arial
size=2>&gt; &gt; &gt; &gt; &gt; &gt;<BR>&gt; &gt; &gt; &gt; &gt; &gt;<BR>&gt;
&gt; &gt; &gt; &gt;<BR>&gt; &gt; &gt; &gt; &gt;<BR>&gt; &gt; &gt; &gt;<BR>&gt;
&gt;
---------------------------------------------------------------------<BR>&gt;
&gt; &gt; &gt; &gt; To unsubscribe, e-mail: </FONT><A
href="mailto:xerces-j-user-unsubscribe@(protected)"><FONT face=Arial
size=2>xerces-j-user-unsubscribe@(protected)</FONT></A><BR><FONT face=Arial
size=2>&gt; &gt; &gt; &gt; &gt; For additional commands, e-mail: </FONT><A
href="mailto:xerces-j-user-help@(protected)"><FONT face=Arial
size=2>xerces-j-user-help@(protected)</FONT></A><BR><FONT face=Arial
size=2>&gt; &gt; &gt; &gt; &gt;<BR>&gt; &gt; &gt; &gt; &gt;<BR>&gt; &gt; &gt;
&gt;<BR>&gt; &gt; &gt; &gt;<BR>&gt; &gt; &gt; &gt;
---------------------------------------------------------------------<BR>&gt;
&gt; &gt; &gt; To unsubscribe, e-mail: </FONT><A
href="mailto:xerces-j-user-unsubscribe@(protected)"><FONT face=Arial
size=2>xerces-j-user-unsubscribe@(protected)</FONT></A><BR><FONT face=Arial
size=2>&gt; &gt; &gt; &gt; For additional commands, e-mail: </FONT><A
href="mailto:xerces-j-user-help@(protected)"><FONT face=Arial
size=2>xerces-j-user-help@(protected)</FONT></A><BR><FONT face=Arial
size=2>&gt; &gt; &gt; &gt;<BR>&gt; &gt; &gt; &gt;<BR>&gt; &gt; &gt;<BR>&gt; &gt
;
&gt;<BR>&gt; &gt; &gt;
---------------------------------------------------------------------<BR>&gt;
&gt; &gt; To unsubscribe, e-mail: </FONT><A
href="mailto:xerces-j-user-unsubscribe@(protected)"><FONT face=Arial
size=2>xerces-j-user-unsubscribe@(protected)</FONT></A><BR><FONT face=Arial
size=2>&gt; &gt; &gt; For additional commands, e-mail: </FONT><A
href="mailto:xerces-j-user-help@(protected)"><FONT face=Arial
size=2>xerces-j-user-help@(protected)</FONT></A><BR><FONT face=Arial
size=2>&gt; &gt; &gt;<BR>&gt; &gt;<BR>&gt; &gt;<BR>&gt; &gt;
---------------------------------------------------------------------<BR>&gt;
&gt; To unsubscribe, e-mail: </FONT><A
href="mailto:xerces-j-user-unsubscribe@(protected)"><FONT face=Arial
size=2>xerces-j-user-unsubscribe@(protected)</FONT></A><BR><FONT face=Arial
size=2>&gt; &gt; For additional commands, e-mail: </FONT><A
href="mailto:xerces-j-user-help@(protected)"><FONT face=Arial
size=2>xerces-j-user-help@(protected)</FONT></A><BR><FONT face=Arial
size=2>&gt; &gt;<BR>&gt; &gt;<BR>&gt; <BR>&gt; <BR>&gt;
---------------------------------------------------------------------<BR>&gt;
To
unsubscribe, e-mail: </FONT><A
href="mailto:xerces-j-user-unsubscribe@(protected)"><FONT face=Arial
size=2>xerces-j-user-unsubscribe@(protected)</FONT></A><BR><FONT face=Arial
size=2>&gt; For additional commands, e-mail: </FONT><A
href="mailto:xerces-j-user-help@(protected)"><FONT face=Arial
size=2>xerces-j-user-help@(protected)</FONT></A><BR><FONT face=Arial
size=2>&gt; <BR>&gt; </FONT></BODY></HTML>