Results 1 to 4 of 4
  1. #1
    oregon is offline Member
    Join Date
    Jul 2007
    Posts
    41
    Rep Power
    0

    Default how to validate a xml file with schemas via SAX

    I want to validate XML documents with schemas via SAX
    I have problems when asigning an *.xsd file to *.xml document

    My code:
    Java Code:
    <p:user xmlns:p="http://www.google.com"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://www.wsf.net user.xsd">
    It works in my computer but don't in others.
    The SAX parser fails to recognize that user.xsd is located in the same folder as XMl document.

    So I decided to assign the schema document programmatically:

    Java Code:
    static final String = JAXP_SCHEMA_SOURCE =
    "http://java.sun.com/xml/jaxp/properties/schemaSource";
    theParser.setProperty(JAXP_SCHEMA_SOURCE, new File(...some *.xsd file full path));
    But this has thrown NotRecognizedException.

    any ideas?
    thanks

  2. #2
    brianhks is offline Senior Member
    Join Date
    Jul 2007
    Posts
    135
    Rep Power
    0

    Default

    I don't think that the standard SAX parser can validate a file against a schema. They can using DTD's but, I do not think against schemas. You can use the MSV project to validate your documents though. I use it a lot in unit tests for XML validation.

  3. #3
    oregon is offline Member
    Join Date
    Jul 2007
    Posts
    41
    Rep Power
    0

    Default

    why does sax can't validate a file?
    anyway I will try to use MSV project
    thanks

  4. #4
    brianhks is offline Senior Member
    Join Date
    Jul 2007
    Posts
    135
    Rep Power
    0

    Default

    Validating XML with the schema is a very arduous task that is not for the faint of project. SAX can validate against DTD's because DTD's are simple. Schemas are complex creatures that are not to be trifled with. That is why there exists the MSV project.

Similar Threads

  1. How to validate date using SampleDateFormat
    By Java Tip in forum java.text
    Replies: 0
    Last Post: 04-04-2008, 02:38 PM
  2. repaint validate doLayout
    By Gajesh Tripathi in forum AWT / Swing
    Replies: 1
    Last Post: 10-27-2007, 06:53 PM
  3. How to validate date using SampleDateFormat
    By JavaBean in forum Java Tip
    Replies: 0
    Last Post: 10-04-2007, 09:31 PM
  4. validate hex character
    By paul in forum New To Java
    Replies: 1
    Last Post: 07-25-2007, 09:08 PM
  5. Replies: 2
    Last Post: 07-02-2007, 05:07 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •