1

WEB-INF 内の xsd フォルダーの下にあるプロジェクトの xsd を検証しようとしています。私が開発したコードを見つけてください

JAXBContext jc = JAXBContext.newInstance(OTAHotelResRQ.class);

JAXBSource source = new JAXBSource(jc, reqJAXB);

SchemaFactory sf =SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI); 

Schema schema = sf.newSchema(new File("XSD/OTA_HotelResRQ.xsd"));

Validator validator = schema.newValidator();

validator.validate(source);

しかし、XSDから読み取ることができません。次の例外が表示されています

java.lang.RuntimeException: org.apache.cxf.interceptor.Fault: schema_reference.4: Failed to read schema document 'file:///D:/hayyat/softwares/jboss-4.2.3.GA/bin/XSD/OTA_HotelResRQ.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>.
    at org.apache.cxf.interceptor.AbstractFaultChainInitiatorObserver.onMessage(AbstractFaultChainInitiatorObserver.java:116)
    at org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:322)
    at org.apache.cxf.transport.ChainInitiationObserver.onMessage(ChainInitiationObserver.java:122)
    at org.apache.cxf.transport.http.AbstractHTTPDestination.invoke(AbstractHTTPDestination.java:211)
    at org.apache.cxf.transport.servlet.ServletController.invokeDestination(ServletController.java:213)
    at org.apache.cxf.transport.servlet.ServletController.invoke(ServletController.java:154)

だから私の問題を解決してください。

よろしくナルシ

4

1 に答える 1

2

XSD をクラスパス (WEB-INF/classes または lib の jar) に配置し、クラスパスから読み取ります。

Web アプリケーションでプロパティ ファイルを読み取るには?

クラスパス リソース (XML ファイル) から入力ストリームを取得する

于 2012-08-22T14:27:51.043 に答える