dfactory.setAttribute(JAXP_SCHEMA_LANGUAGE, new File(schemaSource));
===>
dfactory.setAttribute(JAXP_SCHEMA_SOURCE, new File(schemaSource));see
http://xml.apache.org/~edwingo/jaxp-ri-1.2.0-fcs/docs/samples.html#Schema

解决方案 »

  1.   

    to Saucer :我修改了这个笔误,然后运行测试,虽然成功校验了Schema,但从Log中看出还有两个问题,如下:
    1. 仍旧出现了No attributes are implemented的异常
    2. Warning: validation was turned on but an org.xml.sax.ErrorHandler was not
    set, which is probably not what is desired.  Parser will use a default
    ErrorHandler to print the first 10 errors.  Please call
    the 'setErrorHandler' method to fix this.
    这个警告的问题如何解决呢,Log说用setErrorHandler方法来fix,请问具体如何操作呢? 
    // log如下:
    java.lang.IllegalArgumentException: No attributes are implemented
            at org.apache.crimson.jaxp.DocumentBuilderFactoryImpl.setAttribute(Docum
    entBuilderFactoryImpl.java:93)
            at xml.util.XmlAPI.getNodeList2(XmlAPI.java:611)
            at xml.util.XmlAPI.main(XmlAPI.java:589)
    Warning: validation was turned on but an org.xml.sax.ErrorHandler was not
    set, which is probably not what is desired.  Parser will use a default
    ErrorHandler to print the first 10 errors.  Please call
    the 'setErrorHandler' method to fix this.
    Error: URI=null Line=2: 组件类型“Movies”未被声明。
    Error: URI=null Line=3: 属性“xmlns:xsi”未被声明为组件“Movies”。
    Error: URI=null Line=3: 属性“xsi:noNamespaceSchemaLocation”未被声明为组件“Mov
    ies”。
    Error: URI=null Line=4: 组件类型“Movie”未被声明。
    Error: URI=null Line=5: 组件类型“ID”未被声明。
    Error: URI=null Line=6: 组件类型“Title”未被声明。
    Error: URI=null Line=7: 组件类型“Length”未被声明。
    Error: URI=null Line=8: 组件类型“Description”未被声明。
    Error: URI=null Line=9: 组件类型“Genre”未被声明。
    Error: URI=null Line=10: 组件类型“Directory”未被声明。
      

  2.   

    1. download the latest JAXP2. play with the example code in
    Validating with XML Schema
    http://java.sun.com/j2ee/1.4/docs/tutorial/doc/JAXPDOM9.html
      

  3.   

    The schema validation must run on JAXP 1.2 and later version.
      

  4.   

    为什么我在尝试上面例子的时候报这个错误,什么意思啊?
    Provider org.apache.xerces.jaxp.DocumentBuilderFactoryImpl not found
    at javax.xml.parsers.DocumentBuilderFactory.newInstance(Unknown Source)