W/o changing APIs you could do something like this:
final String xsd =
| "<xsd:schema" +
| "
xmlns:jbxb='http://www.jboss.org/xml/ns/jbxb'" +
| "
xmlns:xsd='http://www.w3.org/2001/XMLSchema'>" +
| " <xsd:element name='root'
type='root-type'/>" +
| " <xsd:complexType name='root-type'>" +
| " <xsd:annotation>" +
| " <xsd:appinfo>" +
| " <jbxb:class impl='" + E.class.getName() +
"'/>" +
| " </xsd:appinfo>" +
| " </xsd:annotation>" +
| " <xsd:attribute name='unqualified'
type='xsd:string' use='required'/>" +
| " </xsd:complexType>" +
| "</xsd:schema>";
|
| String xml = "<root
xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'
xsi:noNamespaceSchemaLocation='testns'/>";
|
| org.xml.sax.EntityResolver resolver = new org.xml.sax.EntityResolver()
| {
| public InputSource resolveEntity(String publicId, String systemId) throws
SAXException, IOException
| {
| if(systemId != null && systemId.endsWith("testns"))
| return new org.xml.sax.InputSource(new StringReader(xsd));
| return null;
| }
| };
|
| /*
| Validator.assertValidXml(xml, new org.xml.sax.EntityResolver()
| {
| public InputSource resolveEntity(String publicId, String systemId) throws
SAXException, IOException
| {
| if(systemId != null && systemId.endsWith("testns"))
| return new org.xml.sax.InputSource(new StringReader(xsd));
| return null;
| }
| });
| */
|
| SchemaBinding schema = XsdBinder.bind(new StringReader(xsd), null);
| Unmarshaller unmarshaller =
UnmarshallerFactory.newInstance().newUnmarshaller();
| unmarshaller.setEntityResolver(resolver);
| unmarshaller.setSchemaValidation(true);
|
| Object o = unmarshaller.unmarshal(new StringReader(xml), schema);
| assertTrue(o instanceof E);
This will throw the exception you expect. The difference is that I had to add
noNamespaceSchemaLocation into the xml instead of setting it on the parser.
It might still be useful to expose setProperty() or the parser itself though.
View the original post :
http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4133243#...
Reply to the post :
http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&a...