在线等 进行schemacheck时,java程序中怎样关联上xsd文件
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
factory.setNamespaceAware(true);
factory.setValidating(true);
factory.setAttribute( "http://apache.org/xml/features/validation/schema ", new Boolean(true));
factory.setAttribute( "http://java.sun.com/xml/jaxp/properties/schemaLanguage ", "http://www.w3.org/2001/XMLSchema ");
factory.setAttribute( "http://java.sun.com/xml/jaxp/properties/schemaSource ", "http://gyosei/Projects/wba/schema/ver0.5/Wbamm01_DetailSerach.xsd ");
try{
DocumentBuilder builder = factory.newDocumentBuilder();
builder.parse(doms);
。。。。
想实现在程序中通过factory.setAttribute设定xsd的名称空间,来进行schema检查,但是报出了以下异常,该怎么解决?
org.xml.sax.SAXParseException: schema_reference.4: Failed to read schema document 'http://gyosei/Projects/wba/schema/ver0.5/Wbamm01_DetailSerach.xsd ', because 1) could not find the document; 2) the document could not be read; 3) the root element of the document is not <xsd:schema> .
[解决办法]
先确定http://gyosei/Projects/wba/schema/ver0.5/Wbamm01_DetailSerach.xsd是否存在,并且能读取,而且是正确的。
[解决办法]
xsd如果有错误要先解决, 那是你代码执行的前提条件
或者, 你不要加上这个有错误的XSD.