Reputation: 23413
I need to pass XML
string from JSF
textarea. The problem is that XML
gets encoded and the I can not pass it into validation. My validation method looks like this:
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;
}
}
The input parameter data
is the XML
String
. When schemaFactory
invokes method newSchema
I get the error:
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
Is there some way to pass the XML
from JSF
textArea that it do not get encoded?
I am using JSF 2.0
, application is deployed on Tomcat 6.
Upvotes: 0
Views: 257
Reputation: 23413
Sorry for the false alarm. The problem was not JSF textarea, but this line:
URL kenexaSchema = getClass().getClassLoader().getResource("KenexaXMLConfiguration.xsd");
I find the way to get XSD in different way and now it is working.
Upvotes: 1