下面列出了javax.xml.transform.dom.DOMResult#setSystemId ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
@Test(expected = MarshalException.class)
public void generatesAndUsesSchema() throws JAXBException, IOException,
SAXException {
final JAXBContext context = JAXBContext.newInstance(A.class);
final DOMResult result = new DOMResult();
result.setSystemId("schema.xsd");
context.generateSchema(new SchemaOutputResolver() {
@Override
public Result createOutput(String namespaceUri,
String suggestedFileName) {
return result;
}
});
@SuppressWarnings("deprecation")
final SchemaFactory schemaFactory = SchemaFactory
.newInstance(WellKnownNamespace.XML_SCHEMA);
final Schema schema = schemaFactory.newSchema(new DOMSource(result
.getNode()));
final Marshaller marshaller = context.createMarshaller();
marshaller.setSchema(schema);
// Works
marshaller.marshal(new A("works"), System.out);
// Fails
marshaller.marshal(new A(null), System.out);
}
private Result nonGlassfishSchemaResult(String namespaceUri, String suggestedFileName) throws IOException {
DOMResult result = new DOMResult();
result.setSystemId("");
nonGlassfishSchemas.add(result);
return result;
}
private Result nonGlassfishSchemaResult(String namespaceUri, String suggestedFileName) throws IOException {
DOMResult result = new DOMResult();
result.setSystemId("");
nonGlassfishSchemas.add(result);
return result;
}
private Result nonGlassfishSchemaResult(String namespaceUri, String suggestedFileName) throws IOException {
DOMResult result = new DOMResult();
result.setSystemId("");
nonGlassfishSchemas.add(result);
return result;
}
private Result nonGlassfishSchemaResult(String namespaceUri, String suggestedFileName) throws IOException {
DOMResult result = new DOMResult();
result.setSystemId("");
nonGlassfishSchemas.add(result);
return result;
}
private Result nonGlassfishSchemaResult(String namespaceUri, String suggestedFileName) throws IOException {
DOMResult result = new DOMResult();
result.setSystemId("");
nonGlassfishSchemas.add(result);
return result;
}
private Result nonGlassfishSchemaResult(String namespaceUri, String suggestedFileName) throws IOException {
DOMResult result = new DOMResult();
result.setSystemId("");
nonGlassfishSchemas.add(result);
return result;
}
private Result nonGlassfishSchemaResult(String namespaceUri, String suggestedFileName) throws IOException {
DOMResult result = new DOMResult();
result.setSystemId("");
nonGlassfishSchemas.add(result);
return result;
}
private Result nonGlassfishSchemaResult(String namespaceUri, String suggestedFileName) throws IOException {
DOMResult result = new DOMResult();
result.setSystemId("");
nonGlassfishSchemas.add(result);
return result;
}