/** * Encodes an object, element name pair. * * @param object The object to encode. * @param element The name of the element to encode. * * @return The object encoded. * @throws Exception */ protected Document encode(Object object, QName element) throws Exception { Configuration configuration = createConfiguration(); XSDSchema schema = configuration.getXSD().getSchema(); Encoder encoder = new Encoder(configuration, schema); ByteArrayOutputStream output = new ByteArrayOutputStream(); encoder.write(object, element, output); DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); dbf.setNamespaceAware(true); return dbf.newDocumentBuilder().parse(new ByteArrayInputStream(output.toByteArray())); }
/** * Encodes an object, element name pair. * * @param object The object to encode. * @param element The name of the element to encode. * * @return The object encoded. * @throws Exception */ protected Document encode( Object object, QName element ) throws Exception { Configuration configuration = createConfiguration(); XSDSchema schema = configuration.getSchemaLocator().locateSchema( null, configuration.getNamespaceURI(), null, null ); Encoder encoder = new Encoder( configuration, schema ); ByteArrayOutputStream output = new ByteArrayOutputStream(); encoder.write( object, element, output ); DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); dbf.setNamespaceAware( true ); return dbf.newDocumentBuilder().parse( new ByteArrayInputStream( output.toByteArray() ) ); }
encoder.write(object, element, output);