0

XMLtextareaから文字列を渡す必要がありますJSF。問題は、XMLエンコードされて検証に渡すことができないことです。私の検証方法は次のようになります。

public boolean validate(String data) {
    Source xmlFile = new StreamSource(data);
    SchemaFactory schemaFactory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
    try {
        URL kenexaSchema = getClass().getClassLoader().getResource("KenexaXMLConfiguration.xsd");
        Schema schema = schemaFactory.newSchema(kenexaSchema);
        Validator validator = schema.newValidator();
        validator.validate(xmlFile);
        LOGGER.debug(xmlFile.getSystemId() + " is valid");
        return true;
    } catch (SAXException ex) {
        LOGGER.error(xmlFile.getSystemId() + " is not valid.", ex);
        LOGGER.error("Reason: " + ex.getLocalizedMessage());
        return false;
    } catch (IOException ex) {
        LOGGER.error("IO Exception occurred while validating proivder data.", ex);
        LOGGER.error("Reason: " + ex.getLocalizedMessage());
        return false;
    }
}

入力パラメータdataXML Stringです。schemaFactoryメソッドを呼び出すと、次newSchemaのエラーが発生します。

java.net.MalformedURLException: no protocol: %3C?xml%20version=%221.0%22%20encoding=%22UTF-8%22?%3E%0D%0A%3Cxmlresults%3E%0D%0A%20%20%20%20%3Cdata%3E%0D%0A%20%20%20%20%20%20%20%20%3Cid%3E%0D%0A%20%20%20%20%20%20%20%20%20%20%20%20%3Crespondentdata%3E%0D%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%3Ctestid%3E22000%3C/testid%3E%0D%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%3Crespondentid%3Ermtest13%3C/respondentid%3E%0D%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%3Ctestsessionid%3E5981%3C/testsessionid%3E%0D%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%3Ctestinstanceid%3E136485%3C/testinstanceid%3E%0D%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%3Cexample%3E0%3C/example%3E%0D%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%3Cstatus_code%3E0%3C/status_code%3E%0D%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%3Cstatus_desc%3ECOMPLETED%20SUCCESSFULLY%3C/status_desc%3E%0D%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%3Cstart_time%3E14/08/06%2016:22:32%3C/start_time%3E%0D%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%3Cend_time%3E14/08/06%2016:23:42%3C/end_time%3E%0D%0A%20%20%20%20%20%20%20%20%20%20%20%20%3C/respondentdata%3E%0D%0A%20%20%20%20%20%20%20%20%20%20%20%20%3Cresultdata%3E%0D%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%3Cscale%3E%0D%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%3Cscalename%3ESocial%3C/scalename%3E%0D%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%3Craw_score%3E28.00%3C/raw_score%3E%0D%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%3Ct-score%3E44%3C/t-score%3E%0D%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%3Csten_scrore%3E4%3C/sten_scrore%3E%0D%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%3Ctime_taken%3E65686%3C/time_taken%3E%0D%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%3Citems_attempted%3E80%3C/items_attempted%3E%0D%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%3Cfinal_score%3E26%3C/final_score%3E%0D%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%3C/scale%3E%0D%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%3Cscale%3E%0D%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%3Cscalename%3ELeader%3C/scalename%3E%0D%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%3Craw_score%3E23.00%3C/raw_score%3E%0D%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%3Ct-score%3E27%3C/t-score%3E%0D%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%3Csten_scrore%3E1%3C/sten_scrore%3E%0D%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%3Ctime_taken%3E658654%3C/time_taken%3E%0D%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%3Citems_attempted%3E80%3C/items_attempted%3E%0D%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%3Cfinal_score%3E26%3C/final_score%3E%0D%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%3C/scale%3E%0D%0A%20%20%20%20%20%20%20%20%20%20%20%20%3C/resultdata%3E%0D%0A%20%20%20%20%20%20%20%20%3C/id%3E%0D%0A%20%20%20%20%3C/data%3E%0D%0A%3C/xmlresults%3E

XMLエンコードさJSFれないfromtextAreaを渡す方法はありますか?私が使用してJSF 2.0いるのは、アプリケーションがTomcat6にデプロイされていることです。

4

1 に答える 1

1

誤警報でごめんなさい。問題はJSFtextareaではなく、次の行です。

URL kenexaSchema = getClass().getClassLoader().getResource("KenexaXMLConfiguration.xsd");

XSDを別の方法で取得する方法を見つけましたが、現在は機能しています。

于 2012-08-14T15:13:53.693 に答える