本文整理匯總了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);
}