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-20       - By McEvoy, Peter
Reply:     1     2     3     4     5     6     7     8     9     10     >>  

I saw a thing in the ant documentation which you may be able to pick up a few
tips from - it sounds like what you are trying to do (although they validate
against DTDs).  You may need to peek at their code to see how to do it...

http://jakarta.apache.org/ant/manual/OptionalTasks/xmlvalidate.html

Pete

-----Original Message-----
From: Praveen Peddi [mailto:ppeddi@(protected)]
Sent: 20 January 2003 14:17
To: xerces-j-user@(protected)
Subject: Re: XML validation using xml schema string


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
<http://xml.org/sax/features/namespaces> );
           parser.setFeature(" http://xml.org/sax/features/validation", true);
           parser.setFeature(" http://apache.org/xml/features/validation
/schema",true <http://apache.org/xml/features/validation/schema> );
           parser.setFeature(" http://apache.org/xml/features/validation
/schema-full-checking",true <http://apache.org/xml/features/validation/schema
-full-checking> );
           // 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 <http://apache.org/xml/properties
/schema/external-noNamespaceSchemaLocation> );
           // 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


<!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.2722.900" name=GENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY bgColor=#ffffff>
<DIV><SPAN class=023095314-20012003><FONT face=Arial color=#0000ff size=2>I saw
a thing in the ant documentation which you may be able to pick up a few tips
from - it sounds like what you are trying to do (although they validate against
DTDs).&nbsp; You may need to peek at their code to see how to do
it...</FONT></SPAN></DIV>
<DIV><SPAN class=023095314-20012003><FONT face=Arial color=#0000ff
size=2></FONT></SPAN>&nbsp;</DIV>
<DIV><SPAN class=023095314-20012003><FONT face=Arial color=#0000ff size=2><A
href="http://jakarta.apache.org/ant/manual/OptionalTasks/xmlvalidate.html">http
://jakarta.apache.org/ant/manual/OptionalTasks/xmlvalidate.html</A></FONT></SPAN
></DIV>
<DIV><SPAN class=023095314-20012003><FONT face=Arial color=#0000ff
size=2></FONT></SPAN>&nbsp;</DIV>
<DIV><SPAN class=023095314-20012003><FONT face=Arial color=#0000ff
size=2>Pete</FONT></SPAN></DIV>
<BLOCKQUOTE dir=ltr
style="PADDING-LEFT: 5px; MARGIN-LEFT: 5px; BORDER-LEFT: #0000ff 2px solid;
MARGIN-RIGHT: 0px">
 <DIV class=OutlookMessageHeader dir=ltr align=left><FONT face=Tahoma
 size=2>-----Original Message-----<BR><B>From:</B> Praveen Peddi
 [mailto:ppeddi@(protected)]<BR><B>Sent:</B> 20 January 2003
 14:17<BR><B>To:</B> xerces-j-user@(protected)<BR><B>Subject:</B> Re: XML
 validation using xml schema string<BR><BR></FONT></DIV>
 <DIV><FONT face=Arial size=2>Hi all,</FONT></DIV>
 <DIV><FONT face=Arial size=2>Last week I sent an email regarding the xml
 validation against the schema, but didn't get any reply. Please&nbsp;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.</FONT></DIV>
 <DIV><FONT face=Arial size=2></FONT>&nbsp;</DIV>
 <DIV><FONT face=Arial size=2>Thanks</FONT></DIV>
 <DIV><FONT face=Arial size=2>Praveen</FONT></DIV>
 <DIV><BR></DIV>
 <BLOCKQUOTE dir=ltr
 style="PADDING-RIGHT: 0px; PADDING-LEFT: 5px; MARGIN-LEFT: 5px; BORDER-LEFT:
#000000 2px solid; MARGIN-RIGHT: 0px">
   <DIV><FONT face=Arial size=2>
   <DIV><FONT face=Arial size=2>Hi all,</FONT></DIV>
   <DIV><FONT face=Arial size=2>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.</FONT></DIV>
   <DIV><FONT face=Arial size=2>I have the following method which validates
   only when the schema is present externally. Note that the argument Schema
is
   a URL:</FONT></DIV>
   <DIV><FONT face=Arial size=2>public static void DOMValidate(String XMLfile,
   String Schema){<BR>&nbsp;&nbsp;long startTime =
   System.currentTimeMillis();&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
   </FONT></DIV>
   <DIV>&nbsp;</DIV>
   <DIV><FONT face=Arial size=2>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; //
   Instantiate the DOM parser.<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
   DOMParser parser = new DOMParser();</FONT></DIV>
   <DIV>&nbsp;</DIV>
   <DIV><FONT face=Arial size=2>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; //
   set the features<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
   try{<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
   parser.setFeature("<A
   href='http://xml.org/sax/features/namespaces",true'>http://xml.org/sax
/features/namespaces",true</A>);<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;
   parser.setFeature("<A
   href="http://xml.org/sax/features/validation">http://xml.org/sax/features
/validation</A>",
   true);<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp
;
   parser.setFeature("<A
   href='http://apache.org/xml/features/validation/schema",true'>http://apache
.org/xml/features/validation/schema",true</A>);<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp
;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
   parser.setFeature("<A
   href='http://apache.org/xml/features/validation/schema-full-checking",true'
>http://apache.org/xml/features/validation/schema-full-checking",true</A>);<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
   // convert the xml file name to a
   URL<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
   String SystemId =
   null;<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;
   SystemId = new
   File(Schema).toURL().toExternalForm();<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
   } catch(java.net.MalformedURLException
   ex){<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;
   //ex.printStackTrace();<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
   log.error(ex);<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;
   }<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
   parser.setProperty("<A
   href='http://apache.org/xml/properties/schema/external
-noNamespaceSchemaLocation",SystemId'>http://apache.org/xml/properties/schema
/external-noNamespaceSchemaLocation",SystemId</A>);<BR>&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
   // myErrorHandler is a descendant of ErrorHandler, it should be set here to
   be able to catch parse
   errors<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp
;
   parser.setErrorHandler(new SchemaErrorHandler());</FONT></DIV>
   <DIV>&nbsp;</DIV>
   <DIV><FONT face=Arial size=2>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }
   catch (SAXNotSupportedException
   ex){<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
   System.out.println("SAXNotSupportedException
   Exception");<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; } catch
   (SAXNotRecognizedException
   ex){<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;
   System.out.println("SAXNotRecognizedException
   Exception");<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }</FONT></DIV>
   <DIV>&nbsp;</DIV>
   <DIV><FONT face=Arial size=2>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; //
   parse the xml file, the errorhandler class has
   callbacks,<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // so those will
be
   called automatically there is a parse
   error<BR>&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.parse(new
   File(XMLfile).toURL().toExternalForm());<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
   //System.out.println("Parsed Successfully by DOM
   Parser");<BR>&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;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp
;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
   //ex.printStackTrace();<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;
   log.error(ex);<BR>&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;} finally
   {<BR>&nbsp;&nbsp;&nbsp;long endTime =
   System.currentTimeMillis();<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
   &nbsp;//System.out.println("Total time of
   DOMValidate:"+(endTime-startTime));<BR>&nbsp;<BR>&nbsp;}</FONT></DIV>
   <DIV>&nbsp;</DIV>
   <DIV><FONT face=Arial size=2>&nbsp;&nbsp;&nbsp; }</FONT></DIV>
   <DIV><FONT face=Arial size=2></FONT>&nbsp;</DIV>
   <DIV><FONT face=Arial size=2>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.</FONT></DIV>
   <DIV><FONT face=Arial size=2></FONT>&nbsp;</DIV>
   <DIV><FONT face=Arial size=2>Any suggestions are appreciated.</FONT></DIV>
   <DIV><FONT face=Arial size=2></FONT>&nbsp;</DIV>
   <DIV><FONT face=Arial
size=2>Praveen</FONT></DIV></FONT></DIV></BLOCKQUOTE></BLOCKQUOTE></BODY></HTML>