You are viewing a plain text version of this content. The canonical link for it is here.
Posted to j-users@xerces.apache.org by Keith Welch <kw...@flamencocorp.com> on 2001/03/06 22:26:43 UTC

XML Schema Validation

Should validation of an XML document with an XML schema fire any of the handler events? I have successfully been using EntityResolver (among other facilities), to trap references to DTD loads for validation. Using an XML schema does not seem to fire the events handled to validate with a schema. Is this my mistake, a sign that the schema support is not mature, or a gross conceptual error on how to provide custom handlers (so that I can pull the XML schema file from another machine). Is anyone else doing anything like this?

Thanks,

Keith Welch

RE: XML Schema Validation

Posted by Leonardo Battagli <ba...@sdb.it>.
At 09.27 07/03/01 -0500, you wrote:
>Hi Leo,
>
>         Thanks for ur reply. The xml file i sent to you is not a valid 
> XML file.
>That is, that xml document is not according to the XML schema i sent. When i
>validate the same XML document with the schema i sent, using XMLSpy 3.5, it
>gives me the error. In the XML document, there is a element named "cna" and
>that element can have a maximum of 3 characters. Even i parsed the same in
>the serlvet. But it is getting validated. But i do the same in a standalone
>application, it throws me error. I don't know why it is not working in
>servlet environment... Any ideas????

about a month ago we started a discussion on comp.text.xml about xmlschema, 
it could be good
to re-start it again, I don't think is a problem of our code

Leonardo


>Thanks and Have a great day!!!!
>
>Ragunath
>
>
>
>
>
>
>
>
>-----Original Message-----
>From: Leonardo Battagli [mailto:battagli@sdb.it]
>Sent: Wednesday, March 07, 2001 4:14 AM
>To: xerces-j-user@xml.apache.org
>Subject: RE: XML Schema Validation
>
>
>At 17.25 06/03/01 -0500, you wrote:
> >Hi Keith,
> >
> >Thanks for your reply. Even i thought in the way you thought. So i
> >configured my webserver and i gave the XSD path as
> ><http://localhost/cv_enterprise.xml>http://localhost/cv_enterprise.xml.
> >(My localhost was pointing to the directory where the XSD is. I checked it
> >with browser and i'm able to open the XSD file thru browser giving the
> >above url). But even then the parser is not validating the xml document.
> >Do u think is there any other reason??
> >
> >Ragunath
>
>I merged your code in the doGet method, after executing the servlet I have
>this message from the browser
>
>IXX EXISTS is EXISTS its working
>
>does it means the .XML is valid against the schema ???
>
>
>    /**Process the HTTP Get request*/
>    public void doGet(HttpServletRequest request, HttpServletResponse
>response) throws ServletException, IOException {
>      try{
>      PrintWriter out = response.getWriter();
>      DOMParser pt = new DOMParser();
>      String sxx = new
>String("C://jboss_tomcat/tomcat-3.2-b7/webapps/xslt/WEB-INF/cv_enterprise.xm
>l");
>      FileInputStream ixx = null;
>      try{
>        ixx = new FileInputStream(sxx);
>      }
>      catch(Exception e){ System.out.println("error is  "+
>etMessage());    }
>      out.println("<html><body>");
>      if (ixx != null) {out.println("IXX EXISTS");  } else
>{  out.println("IXX NON EXISTS");    }
>      InputSource is = new InputSource(ixx);
>      if (is != null) {   out.println("is EXISTS");   } else
>{   out.println("is NON EXISTS");  }
>      pt.setFeature("http://xml.org/sax/features/validation", true);
>      pt.setFeature("http://apache.org/xml/features/validation/schema",
>true);
>//      pt.setValidation(true);
>//      pt.setValidationSchema(true);
>      try{
>        pt.parse(is);
>      }
>      catch (Exception e) {
>        System.out.println("NonParserException: " + e.getMessage());
>        out.println("QUALCOSA NON VA");
>      }
>      out.println("its working");
>      out.println("</body></html>");
>      }catch(Exception e){}
>    }
>
>
>Thks,
>Leonardo
>
>
>==============================================
>Lulli Informatica S.r.l.
>http://www.lulliinformatica.com
>----------------------------------------------
>Leonardo Battagli: Java/XML Developer at battagli@sdb.it
>==============================================
>Out of the office email address: leonardobattagli@usa.net
>==============================================
>
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: xerces-j-user-unsubscribe@xml.apache.org
>For additional commands, e-mail: xerces-j-user-help@xml.apache.org
>
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: xerces-j-user-unsubscribe@xml.apache.org
>For additional commands, e-mail: xerces-j-user-help@xml.apache.org

==============================================
Lulli Informatica S.r.l.
http://www.lulliinformatica.com
----------------------------------------------
Leonardo Battagli: Java/XML Developer at battagli@sdb.it
==============================================
Out of the office email address: leonardobattagli@usa.net
==============================================


RE: XML Schema Validation

Posted by Ragunath Marudhachalam <rm...@circuitvision.com>.
Hi Leo,

	Thanks for ur reply. The xml file i sent to you is not a valid XML file.
That is, that xml document is not according to the XML schema i sent. When i
validate the same XML document with the schema i sent, using XMLSpy 3.5, it
gives me the error. In the XML document, there is a element named "cna" and
that element can have a maximum of 3 characters. Even i parsed the same in
the serlvet. But it is getting validated. But i do the same in a standalone
application, it throws me error. I don't know why it is not working in
servlet environment... Any ideas????

Thanks and Have a great day!!!!

Ragunath








-----Original Message-----
From: Leonardo Battagli [mailto:battagli@sdb.it]
Sent: Wednesday, March 07, 2001 4:14 AM
To: xerces-j-user@xml.apache.org
Subject: RE: XML Schema Validation


At 17.25 06/03/01 -0500, you wrote:
>Hi Keith,
>
>Thanks for your reply. Even i thought in the way you thought. So i
>configured my webserver and i gave the XSD path as
><http://localhost/cv_enterprise.xml>http://localhost/cv_enterprise.xml.
>(My localhost was pointing to the directory where the XSD is. I checked it
>with browser and i'm able to open the XSD file thru browser giving the
>above url). But even then the parser is not validating the xml document.
>Do u think is there any other reason??
>
>Ragunath

I merged your code in the doGet method, after executing the servlet I have
this message from the browser

IXX EXISTS is EXISTS its working

does it means the .XML is valid against the schema ???


   /**Process the HTTP Get request*/
   public void doGet(HttpServletRequest request, HttpServletResponse
response) throws ServletException, IOException {
     try{
     PrintWriter out = response.getWriter();
     DOMParser pt = new DOMParser();
     String sxx = new
String("C://jboss_tomcat/tomcat-3.2-b7/webapps/xslt/WEB-INF/cv_enterprise.xm
l");
     FileInputStream ixx = null;
     try{
       ixx = new FileInputStream(sxx);
     }
     catch(Exception e){ System.out.println("error is  "+
etMessage());    }
     out.println("<html><body>");
     if (ixx != null) {out.println("IXX EXISTS");  } else
{  out.println("IXX NON EXISTS");    }
     InputSource is = new InputSource(ixx);
     if (is != null) {   out.println("is EXISTS");   } else
{   out.println("is NON EXISTS");  }
     pt.setFeature("http://xml.org/sax/features/validation", true);
     pt.setFeature("http://apache.org/xml/features/validation/schema",
true);
//      pt.setValidation(true);
//      pt.setValidationSchema(true);
     try{
       pt.parse(is);
     }
     catch (Exception e) {
       System.out.println("NonParserException: " + e.getMessage());
       out.println("QUALCOSA NON VA");
     }
     out.println("its working");
     out.println("</body></html>");
     }catch(Exception e){}
   }


Thks,
Leonardo


==============================================
Lulli Informatica S.r.l.
http://www.lulliinformatica.com
----------------------------------------------
Leonardo Battagli: Java/XML Developer at battagli@sdb.it
==============================================
Out of the office email address: leonardobattagli@usa.net
==============================================


---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-j-user-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-j-user-help@xml.apache.org


RE: XML Schema Validation

Posted by Leonardo Battagli <ba...@sdb.it>.
At 17.25 06/03/01 -0500, you wrote:
>Hi Keith,
>
>Thanks for your reply. Even i thought in the way you thought. So i 
>configured my webserver and i gave the XSD path as 
><http://localhost/cv_enterprise.xml>http://localhost/cv_enterprise.xml. 
>(My localhost was pointing to the directory where the XSD is. I checked it 
>with browser and i'm able to open the XSD file thru browser giving the 
>above url). But even then the parser is not validating the xml document. 
>Do u think is there any other reason??
>
>Ragunath

I merged your code in the doGet method, after executing the servlet I have 
this message from the browser

IXX EXISTS is EXISTS its working

does it means the .XML is valid against the schema ???


   /**Process the HTTP Get request*/
   public void doGet(HttpServletRequest request, HttpServletResponse 
response) throws ServletException, IOException {
     try{
     PrintWriter out = response.getWriter();
     DOMParser pt = new DOMParser();
     String sxx = new 
String("C://jboss_tomcat/tomcat-3.2-b7/webapps/xslt/WEB-INF/cv_enterprise.xml");
     FileInputStream ixx = null;
     try{
       ixx = new FileInputStream(sxx);
     }
     catch(Exception e){ System.out.println("error is  "+ e.getMessage());    }
     out.println("<html><body>");
     if (ixx != null) {out.println("IXX EXISTS");  } else 
{  out.println("IXX NON EXISTS");    }
     InputSource is = new InputSource(ixx);
     if (is != null) {   out.println("is EXISTS");   } else 
{   out.println("is NON EXISTS");  }
     pt.setFeature("http://xml.org/sax/features/validation", true);
     pt.setFeature("http://apache.org/xml/features/validation/schema", true);
//      pt.setValidation(true);
//      pt.setValidationSchema(true);
     try{
       pt.parse(is);
     }
     catch (Exception e) {
       System.out.println("NonParserException: " + e.getMessage());
       out.println("QUALCOSA NON VA");
     }
     out.println("its working");
     out.println("</body></html>");
     }catch(Exception e){}
   }


Thks,
Leonardo


==============================================
Lulli Informatica S.r.l.
http://www.lulliinformatica.com
----------------------------------------------
Leonardo Battagli: Java/XML Developer at battagli@sdb.it
==============================================
Out of the office email address: leonardobattagli@usa.net
==============================================


Idea for the ErrorHandler

Posted by Brad O'Hearne <ca...@megapathdsl.net>.
In the ErrorHandler class, it would be very handy to have some additional
information sent to the error, fatalError, and warning methods, such as a
reference to the element stack, the element name, and/or a byte offset in
the stream, if that is being maintained.  Take for instance the following
Exception I report from my ErrorHandler:

org.xml.sax.SAXParseException: An invalid XML character (Unicode: 0x19) was
found in the element content of the document.
 at org.apache.xerces.framework.XMLParser.reportError(XMLParser.java:969)
 at
org.apache.xerces.framework.XMLDocumentScanner.reportFatalXMLError(XMLDocume
ntScanner.java:643)
 at
org.apache.xerces.framework.XMLDocumentScanner$ContentDispatcher.dispatch(XM
LDocumentScanner.java:1355)
 at
org.apache.xerces.framework.XMLDocumentScanner.parseSome(XMLDocumentScanner.
java:380)
 at org.apache.xerces.framework.XMLParser.parse(XMLParser.java:861)

It would be really nice to know what element caused this problem, and
further, which occurrence of that element caused the problem.  I actually am
maintaining my own element stack for handling purposes, and so it looks like
I will probably store a reference to this stack in my ErrorHandler class.
However, I would think this type of information would be wanted by everyone,
and hence, possibly a helpful change to the source.

BradO

Re: XML Schema Validation

Posted by Keith Welch <kw...@flamencocorp.com>.
No, I am also servlet-based. Fortunately, I only have to support DTDs until the XML Schema support is stable.
  ----- Original Message ----- 
  From: Ragunath Marudhachalam 
  To: xerces-j-user@xml.apache.org 
  Sent: Tuesday, March 06, 2001 5:27 PM
  Subject: RE: XML Schema Validation


  And Keith do u want to validate your XML file from a standalone application?? If so i think probably u can use the code of the standalone class i sent to you.

RE: XML Schema Validation

Posted by Ragunath Marudhachalam <rm...@circuitvision.com>.
And Keith do u want to validate your XML file from a standalone
application?? If so i think probably u can use the code of the standalone
class i sent to you.

RE: XML Schema Validation

Posted by Ragunath Marudhachalam <rm...@circuitvision.com>.
Hi Keith,

Thanks for your reply. Even i thought in the way you thought. So i
configured my webserver and i gave the XSD path as
http://localhost/cv_enterprise.xml. (My localhost was pointing to the
directory where the XSD is. I checked it with browser and i'm able to open
the XSD file thru browser giving the above url). But even then the parser is
not validating the xml document. Do u think is there any other reason??

Ragunath

Re: XML Schema Validation

Posted by Keith Welch <kw...@flamencocorp.com>.
Well, Ragunath, I may be able to help with your problem, I hope you can help with mine! You are referencing the XSD from your XML file, which you are opening from an InputStream. From an application, it appears to me that the reference to your files is relative from the directory where the process started. It appears to be that coincidence that is allowing the parser to look in the correct place for any other required files. That's where you put them, isn't it! Your servlet engine is probably running from it's bin directory, however.

As I recall, the InputSource was created to maintain the link between file contents and location. In my experience, however, it does not - by itself - keep the URIs for the various input sources straight by any set of rules that I could discern. I don't exactly get how it works from the javadoc. I'd love to hear how exactly how InputSource works. Does this help?

RKW
  ----- Original Message ----- 
  From: Ragunath Marudhachalam 
  To: xerces-j-user@xml.apache.org 
  Sent: Tuesday, March 06, 2001 4:31 PM
  Subject: RE: XML Schema Validation


  hi Keith,
   
  I'm trying to validate XML schema with a xml document. I'm just trying to parse the xml schema. When i parse the same in a standalone application, it is working fine. That is it throws me error when the xml document is not according to schema.. But if i use the same code in a servlet it is not working properly. I'm attaching my test files(one is standalone and other is servlet) alongwith xml and xsl files. U go thru it, and if u find any errors plz let me know...
   
  Thanks,
  Ragu
   
   
   


------------------------------------------------------------------------------


  ---------------------------------------------------------------------
  To unsubscribe, e-mail: xerces-j-user-unsubscribe@xml.apache.org
  For additional commands, e-mail: xerces-j-user-help@xml.apache.org

RE: XML Schema Validation

Posted by Ragunath Marudhachalam <rm...@circuitvision.com>.
hi Keith,

I'm trying to validate XML schema with a xml document. I'm just trying to
parse the xml schema. When i parse the same in a standalone application, it
is working fine. That is it throws me error when the xml document is not
according to schema.. But if i use the same code in a servlet it is not
working properly. I'm attaching my test files(one is standalone and other is
servlet) alongwith xml and xsl files. U go thru it, and if u find any errors
plz let me know...

Thanks,
Ragu