本文整理汇总了Java中javax.xml.bind.Marshaller.setSchema方法的典型用法代码示例。如果您正苦于以下问题:Java Marshaller.setSchema方法的具体用法?Java Marshaller.setSchema怎么用?Java Marshaller.setSchema使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.xml.bind.Marshaller
的用法示例。
在下文中一共展示了Marshaller.setSchema方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: toXML
import javax.xml.bind.Marshaller; //导入方法依赖的package包/类
@Override
public String toXML(T obj) {
try {
JAXBContext context = JAXBContext.newInstance(type);
Marshaller m = context.createMarshaller();
if(schemaLocation != null) {
SchemaFactory schemaFactory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
StreamSource source = new StreamSource(getClass().getResourceAsStream(schemaLocation));
Schema schema = schemaFactory.newSchema(source);
m.setSchema(schema);
}
StringWriter writer = new StringWriter();
m.marshal(obj, writer);
String xml = writer.toString();
return xml;
} catch (Exception e) {
System.out.println("ERROR: "+e.toString());
return null;
}
}
示例2: saveDialogRoot
import javax.xml.bind.Marshaller; //导入方法依赖的package包/类
public static void saveDialogRoot(File dialogFile, Level root) throws JAXBException, SAXException
{
Marshaller marshaller = getJaxbContext().createMarshaller();
marshaller.setSchema(getSchema());
marshaller.setProperty(Marshaller.JAXB_ENCODING, "UTF-8");
marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE);
marshaller.marshal(root, dialogFile);
}
示例3: saveTenants
import javax.xml.bind.Marshaller; //导入方法依赖的package包/类
private void saveTenants(final Tenants tenants) throws JAXBException {
final Marshaller marshaller = JAXB_TENANTS_CONTEXT.createMarshaller();
marshaller.setSchema(tenantsSchema);
marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
marshaller.marshal(tenants, tenantsFile);
}
示例4: saveAuthorizations
import javax.xml.bind.Marshaller; //导入方法依赖的package包/类
private void saveAuthorizations(final Authorizations authorizations) throws JAXBException {
final Marshaller marshaller = JAXB_AUTHORIZATIONS_CONTEXT.createMarshaller();
marshaller.setSchema(authorizationsSchema);
marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
marshaller.marshal(authorizations, authorizationsFile);
}