The list of methods to do XML Transform Usage are organized into topic(s).
Node
bytesToXml(final byte[] body) bytes To Xml
final Transformer transformer = FACTORY.newTransformer();
final Source source = new StreamSource(new ByteArrayInputStream(body));
final DOMResult result = new DOMResult();
transformer.transform(source, result);
return result.getNode();
StreamSource
castResultToSource(StreamResult result) cast Result To Source
StreamSource ss = new StreamSource(new StringReader(result.getWriter().toString()));
String systemId = result.getSystemId();
if (systemId != null) {
ss.setSystemId(new File(systemId));
return ss;
void
closeSource(final Source source) close Source
if (!(source instanceof StreamSource)) {
return;
StreamSource stream = (StreamSource) source;
try {
if (stream.getInputStream() != null) {
stream.getInputStream().close();
} catch (IOException e) {
try {
if (stream.getReader() != null) {
stream.getReader().close();
} catch (IOException e) {
boolean
compareSource(Source src, Source target) compare Source
Transformer t1 = TransformerFactory.newInstance().newTransformer();
Transformer t2 = TransformerFactory.newInstance().newTransformer();
DOMResult srcResult = new DOMResult();
DOMResult tarResult = new DOMResult();
t1.transform(src, srcResult);
Node n1 = srcResult.getNode();
t2.transform(target, tarResult);
Node n2 = tarResult.getNode();
...
boolean
compareStreamSource(StreamSource src1, StreamSource src2) compare Stream Source
if (src1 == null || src2 == null) {
System.out.println("compareStreamSource - src1 or src2 null!");
return false;
InputStream is1 = src1.getInputStream();
InputStream is2 = src2.getInputStream();
if ((is1 == null) || (is2 == null)) {
System.out.println("InputStream of - src1 or src2 null!");
...
String
convert(final Element element) convert
if (null == element) {
throw new NullPointerException("connot convert null DOM Element");
TransformerFactory transFactory = TransformerFactory.newInstance();
Transformer transformer = transFactory.newTransformer();
StringWriter stringWriter = new StringWriter();
transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes");
transformer.transform(new DOMSource(element), new StreamResult(stringWriter));
...
String
convertDisplay(Object object) convert Display
try {
String result;
if (object instanceof ByteArrayInputStream) {
InputStream is = (InputStream) object;
byte[] data = new byte[is.available()];
is.mark(0);
is.read(data);
is.reset();
...
InputStream
convertMessageToInputStream(Source src) convert Message To Input Stream
final Transformer transformer = TRANSFORMER_FACTORY.newTransformer();
ByteArrayOutputStream baos = new ByteArrayOutputStream();
StreamResult result = new StreamResult(baos);
transformer.transform(src, result);
return new ByteArrayInputStream(baos.toByteArray());
DocumentBuilderFactory
createAndGetFactory(Collection schemaSources) create And Get Factory
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
factory.setNamespaceAware(true);
factory.setIgnoringComments(true);
factory.setIgnoringElementContentWhitespace(true);
factory.setSchema(newSchema(schemaSources.toArray(new Source[schemaSources.size()])));
return factory;
Properties
createDefaultPropertiesForXML(boolean omitXMLDeclaration) Method for static initializer
final Properties format = new Properties();
format.put(OutputKeys.METHOD, "xml");
format.put(OutputKeys.OMIT_XML_DECLARATION, (omitXMLDeclaration ? "yes" : "no"));
format.put(OutputKeys.INDENT, "yes");
return format;