T
tremalnaik
Hello,
I'm trying to validate the xml string which root follows:
<ScenarioResponse
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xsi:noNamespaceSchemaLocation="ScenarioResponse.xsd">
...............
</ScenarioResponse>
with the schema file ScenarioResponse.xsd:
<xs:schema
xmlns:xs="http://www.w3.org/2001/XMLSchema"elementFormDefault="qualified">
........
</xs:schema>
My code:
private void validate(String schemaPath, String xml) throws
SAXException,
ParserConfigurationException, IOException
{
// parse document
DocumentBuilderFactory dbf =
DocumentBuilderFactory.newInstance();
DocumentBuilder db = dbf.newDocumentBuilder();
Document doc = db.parse(new InputSource(new
StringReader(xml)));
// create schema
SchemaFactory sf =
SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
sf.setErrorHandler(new myErrorHandler());
InputStream iStream =
Thread.currentThread().getContextClassLoader().getResourceAsStream(schemaPath);
StreamSource ss = new StreamSource(iStream);
Schema schema = sf.newSchema(ss);
// validate
Validator validator = schema.newValidator();
validator.setErrorHandler(new myErrorHandler());
validator.validate(source);
}
executing the last instruction I get
org.xml.sax.SAXParseException: cvc-complex-type.3.2.2: Attribute
'xsi:noNamespaceSchemaLocation' is not allowed to appear in element
'ScenarioResponse'.
I try to use another instance of the SchemaFactory so I try the
following:
SchemaFactory sf =
SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_INSTANCE_NS_URI);
the result is:
2005-10-27 16:17:17,932 [http-0.0.0.0-8080-1] ERROR [ROM] [THREAD: 1]
java.lang.IllegalArgumentException:
http://www.w3.org/2001/XMLSchema-instance
at
javax.xml.validation.SchemaFactory.newInstance(SchemaFactory.java:181)
so I suppose an instance for this schema is not implemented.
Can someone give me a direction, please?
TREMALNAIK
I'm trying to validate the xml string which root follows:
<ScenarioResponse
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xsi:noNamespaceSchemaLocation="ScenarioResponse.xsd">
...............
</ScenarioResponse>
with the schema file ScenarioResponse.xsd:
<xs:schema
xmlns:xs="http://www.w3.org/2001/XMLSchema"elementFormDefault="qualified">
........
</xs:schema>
My code:
private void validate(String schemaPath, String xml) throws
SAXException,
ParserConfigurationException, IOException
{
// parse document
DocumentBuilderFactory dbf =
DocumentBuilderFactory.newInstance();
DocumentBuilder db = dbf.newDocumentBuilder();
Document doc = db.parse(new InputSource(new
StringReader(xml)));
// create schema
SchemaFactory sf =
SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
sf.setErrorHandler(new myErrorHandler());
InputStream iStream =
Thread.currentThread().getContextClassLoader().getResourceAsStream(schemaPath);
StreamSource ss = new StreamSource(iStream);
Schema schema = sf.newSchema(ss);
// validate
Validator validator = schema.newValidator();
validator.setErrorHandler(new myErrorHandler());
validator.validate(source);
}
executing the last instruction I get
org.xml.sax.SAXParseException: cvc-complex-type.3.2.2: Attribute
'xsi:noNamespaceSchemaLocation' is not allowed to appear in element
'ScenarioResponse'.
I try to use another instance of the SchemaFactory so I try the
following:
SchemaFactory sf =
SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_INSTANCE_NS_URI);
the result is:
2005-10-27 16:17:17,932 [http-0.0.0.0-8080-1] ERROR [ROM] [THREAD: 1]
java.lang.IllegalArgumentException:
http://www.w3.org/2001/XMLSchema-instance
at
javax.xml.validation.SchemaFactory.newInstance(SchemaFactory.java:181)
so I suppose an instance for this schema is not implemented.
Can someone give me a direction, please?
TREMALNAIK