以下程序将 schemaLanguage 设置为“ http://www.w3.org/XML/XMLSchema/v1.1 ”,newSchema() 返回类型为 {org.apache.xerces.jaxp.validation.SimpleXMLSchema} 的 Schema。我无法导入类,错误是 - org.apache.xerces.jaxp.validation.SimpleXMLSchema 类型不可见
我的意图是将 XSD(Ver 1.1)断言值(如下所示)解析为 XPath 表达式,并且在 SimpleXMLSchema 对象中可用。
Example: <assert test="starts-with(@partnumber,../@partnumber)"/>
有没有其他方法可以获取 XSD1.1 Schema 对象?
使用的jar:xercesImpl-xsd11-2.12-beta-r1667115.jar、org.eclipse.wst.xml.xpath2.processor-2.1.100.jar
任何建议/帮助都将帮助我解决问题。谢谢。
/*
* Xsd11SchemaValidator.java
import javax.xml.validation.SchemaFactory;*/
import javax.xml.validation.Schema;
import javax.xml.validation.SchemaFactory;
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;
import org.apache.xerces.impl.xs.SchemaGrammar;
import org.apache.xerces.jaxp.validation.*;
class Xsd11SchemaValidator {
private static int errorCount = 0;
public static void main() {
String schemaName = "Path to XSD 1.1 File";;
Schema schema = loadSchema(schemaName);
}
}
public static Schema loadSchema(String name) {
Schema schema = null;
try {
String language = "http://www.w3.org/XML/XMLSchema/v1.1";
SchemaFactory factory = SchemaFactory.newInstance(language);
schema = factory.newSchema(new File(name));
} catch (Exception e) {
System.out.println(e.toString());
}
return schema;
}
}