Java Code Examples for javax.xml.bind.Marshaller.setSchema()

The following are Jave code examples for showing how to use setSchema() of the javax.xml.bind.Marshaller class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
Example 1
Project: testing_security_development_enterprise_systems   File: ConverterImpl.java   Source Code and License Vote up 6 votes
@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;
    }
}
 
Example 2
Project: school-game   File: DialogDataHelper.java   Source Code and License Vote up 5 votes
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);
}
 
Example 3
Project: nifi-registry   File: FileUserGroupProvider.java   Source Code and License Vote up 4 votes
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);
}
 
Example 4
Project: nifi-registry   File: FileAccessPolicyProvider.java   Source Code and License Vote up 4 votes
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);
}