Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/xml/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在Java中根据XSD 1.1验证XML时出错_Java_Xml_Validation_Xsd_Xsd 1.1 - Fatal编程技术网

在Java中根据XSD 1.1验证XML时出错

在Java中根据XSD 1.1验证XML时出错,java,xml,validation,xsd,xsd-1.1,Java,Xml,Validation,Xsd,Xsd 1.1,我正试图用Java中的XSD1.1验证XML。如所述 我得到一个例外,说: java.lang.IllegalArgumentException:无法加载实现由指定的架构语言的SchemaFactory 然后我尝试了SchemaFactory.setProperty(“http://saxon.sf.net/feature/xsd-version“,”1.1“,错误是: 无法从类型SchemaFactory对非静态方法setProperty(字符串、对象)进行静态引用 我包括的这些罐子仍然没有错

我正试图用Java中的XSD1.1验证XML。如所述

我得到一个例外,说:

java.lang.IllegalArgumentException:无法加载实现由指定的架构语言的SchemaFactory

然后我尝试了
SchemaFactory.setProperty(“http://saxon.sf.net/feature/xsd-version“,”1.1“
,错误是:

无法从类型SchemaFactory对非静态方法setProperty(字符串、对象)进行静态引用

我包括的这些罐子仍然没有错误的变化

java-cup-10k.jar

org.eclipse.wst.xml.xpath2.processor-2.1.100.jar

xercesImpl-2.11.0.jar

xml-apis-xerces-2.7.1.jar
有人能帮我用Java中的XSD1.1验证XML吗

import javax.xml.validation.SchemaFactory;
import javax.xml.validation.Schema;
import javax.xml.XMLConstants;
import javax.xml.transform.sax.SAXSource;
import org.xml.sax.InputSource;
import javax.xml.validation.Validator;
import java.io.*;
import org.xml.sax.SAXException;
import org.xml.sax.SAXParseException;
import org.xml.sax.ErrorHandler;
class Xsd11SchemaValidator {
  private static int errorCount = 0;
  public static void main(String[] a) {
    if (a.length<2) {
      System.out.println("Usage:");
      System.out.println("java Xsd11SchemaValidator schema_file_name "
        + "xml_file_name");
    } 
      String schemaName ="C:\\Ankit\\tempFiles\\test1.xsd";
      String xmlName ="C:\\Ankit\\tempFiles\\test1.xml";
      Schema schema = loadSchema(schemaName);
      validateXml(schema, xmlName);

  }
  public static void validateXml(Schema schema, String xmlName) {
    try {
      // creating a Validator instance
      Validator validator = schema.newValidator();

      // setting my own error handler
      validator.setErrorHandler(new MyErrorHandler());

      // preparing the XML file as a SAX source
      SAXSource source = new SAXSource(
        new InputSource(new java.io.FileInputStream(xmlName)));

      // validating the SAX source against the schema
      validator.validate(source);
      System.out.println();
      if (errorCount>0) {
        System.out.println("Failed with errors: "+errorCount);
      } else {
        System.out.println("Passed.");
      } 

    } catch (Exception e) {
      // catching all validation exceptions
      System.out.println();
      System.out.println(e.toString());
    }
  }
  public static Schema loadSchema(String name) {
    Schema schema = null;
    try {
需要更改为:

SchemaFactory factory = SchemaFactory.newInstance(language);
factory.setProperty("http://saxon.sf.net/feature/xsd-version", "1.1");
需要更改为:

SchemaFactory factory = SchemaFactory.newInstance(language);
factory.setProperty("http://saxon.sf.net/feature/xsd-version", "1.1");
SchemaFactory factory = SchemaFactory.newInstance(language);
factory.setProperty("http://saxon.sf.net/feature/xsd-version", "1.1");