[jboss-dev-forums] [Design of JBossXB] - How to force strict validation?
rob.stryker@jboss.com
do-not-reply at jboss.com
Mon Feb 25 19:21:55 EST 2008
I've been trying this out for a while... no success.
Schema:
<xsd:schema xmlns:jbxb="http://www.jboss.org/xml/ns/jbxb" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<xsd:element name="garbageRoot" type="root-type"/>
<xsd:complexType name="root-type">
<xsd:annotation>
<xsd:appinfo>
<jbxb:class impl="garbage.XbGarbageRoot"/>
</xsd:appinfo>
</xsd:annotation>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:schema>
XbGarbageRoot (POJO):
public class XbGarbageRoot {
private String name;
public XbGarbageRoot() {
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}
Test case:
public class ParseTest extends TestCase {
private static final String SCHEMA = "/home/rob/apps/eclipse/workspaces/work/garbage/src/schema.xsd";
private static final String DATA = "/home/rob/apps/eclipse/workspaces/work/garbage/data/test.xml";
public void testABC() {
try {
File f = new File(SCHEMA);
InputStream stream = new FileInputStream(f);
SchemaBinding binding = XsdBinder.bind(stream, "UTF-8", null);
stream.close();
Unmarshaller unmarshaller = UnmarshallerFactory.newInstance().newUnmarshaller();
binding.setStrictSchema(true);
FileInputStream dataStream = new FileInputStream(new File(DATA));
Object xmlObject = unmarshaller.unmarshal(dataStream, binding);
System.out.println("object is " + xmlObject);
} catch( Exception e ) {
// GOOD! I want XB to fail!
return;
}
fail("data file should not have validated!");
}
}
Clearly, i'm setting that it should use a strict schema... but it's not throwing an exception. Any ideas?
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4132014#4132014
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4132014
More information about the jboss-dev-forums
mailing list