List of usage examples for javax.xml.transform.dom DOMResult getNode
public Node getNode()
From source file:Main.java
private static Document transformToDomResult(Document document, Transformer transformer) throws TransformerConfigurationException, TransformerException { DOMResult domResult = new DOMResult(); synchronized (transformer) { transformer.transform(new DOMSource(document), domResult); }/*from ww w . j ava 2 s. c om*/ Document transformedDocument = (Document) domResult.getNode(); return transformedDocument; }
From source file:Main.java
public static Node xsltTransform(InputStream styleSheet, Document response, Map<String, String> params) { TransformerFactory tFactory = TransformerFactory.newInstance(); Transformer transformer = null; try {/*from www. j a v a 2 s. c om*/ javax.xml.transform.stream.StreamSource streamSource = new javax.xml.transform.stream.StreamSource( styleSheet); transformer = tFactory.newTransformer(streamSource); } catch (TransformerConfigurationException e) { // TODO Auto-generated catch block e.printStackTrace(); } for (Iterator<String> iterator = params.keySet().iterator(); iterator.hasNext();) { String key = iterator.next(); String value = params.get(key); transformer.setParameter(key, value); } Source xmlSource = new DOMSource(response); DOMResult result = new DOMResult(); try { transformer.transform(xmlSource, result); } catch (TransformerException e) { // TODO Auto-generated catch block e.printStackTrace(); } return result.getNode(); }
From source file:XMLUtils.java
public static Node fromSource(Source src) throws Exception { Transformer trans = TransformerFactory.newInstance().newTransformer(); DOMResult res = new DOMResult(); trans.transform(src, res);// w w w . jav a 2s . com return res.getNode(); }
From source file:org.biopax.validator.api.ValidatorUtils.java
/** * Converts one validation result //from ww w.jav a 2 s . co m * into the DOM element. * * @param validationResult * @return */ public static Element asElement(Validation validationResult) { DOMResult domResult = marshal(validationResult); Element validation = (Element) domResult.getNode().getFirstChild(); return validation; }
From source file:org.biopax.validator.api.ValidatorUtils.java
/** * Converts a validator response (contains one or * several validation results) into the document. * /* w w w .j av a 2 s . c o m*/ * @param validatorResponse * @return */ public static Document asDocument(ValidatorResponse validatorResponse) { DOMResult domResult = marshal(validatorResponse); Document validation = (Document) domResult.getNode(); return validation; }
From source file:com.cisco.dvbu.ps.common.adapters.util.XmlUtils.java
public static Document xslTransform(Node xmlData, StreamSource xslSource) throws Exception { TransformerFactory tFactory = new TransformerFactoryImpl(); Transformer transformer;/*from w w w.ja v a 2s. c o m*/ DOMResult domRes; Document doc = null; try { transformer = tFactory.newTransformer(xslSource); domRes = new DOMResult(); // perform transformation transformer.transform(new DOMSource(xmlData), domRes); doc = (Document) domRes.getNode(); // log.debug(XmlUtils.nodeToString(doc)); } catch (Exception e) { log.error("Xslt Transformation error! " + e.getMessage()); throw e; } return doc; }
From source file:Main.java
/** * //from ww w .ja va 2 s .com * <B>Purpose:</B> XML transformation using XSL * * @param doc * @param xslInput * @param systemid * @return * @throws TransformerException */ public static Node transform(Document doc, StreamSource xslInput, String systemid) throws TransformerException { TransformerFactory tFactory = TransformerFactory.newInstance(); Transformer transformer = tFactory.newTransformer(xslInput); DOMResult domResult = new DOMResult(); DOMSource xmlDomSource = null; xmlDomSource = new DOMSource(doc); xmlDomSource.setSystemId(systemid); transformer.setOutputProperty(OutputKeys.INDENT, "yes"); transformer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "2"); transformer.setOutputProperty("{http://xml.apache.org/xalan}line-separator", "\n"); transformer.transform(xmlDomSource, domResult); return domResult.getNode(); }
From source file:com.wandrell.example.swss.test.util.factory.SecureSoapMessages.java
private static final Document toDocument(SOAPMessage soapMsg) throws TransformerConfigurationException, TransformerException, SOAPException, IOException { Source src = soapMsg.getSOAPPart().getContent(); TransformerFactory tf = TransformerFactory.newInstance(); Transformer transformer = tf.newTransformer(); DOMResult result = new DOMResult(); transformer.transform(src, result);/*from w ww .ja v a2 s . c om*/ return (Document) result.getNode(); }
From source file:com.bernardomg.example.swss.test.util.factory.SecureSoapMessages.java
private static final Document toDocument(final SOAPMessage soapMsg) throws TransformerConfigurationException, TransformerException, SOAPException, IOException { final Source src = soapMsg.getSOAPPart().getContent(); final TransformerFactory tf = TransformerFactory.newInstance(); final Transformer transformer = tf.newTransformer(); final DOMResult result = new DOMResult(); transformer.transform(src, result);//from www. j a v a 2s . co m return (Document) result.getNode(); }
From source file:com.googlecode.jgenhtml.JGenHtmlTestUtils.java
/** * Get an HTML page as a DOM object/*from w w w. jav a 2 s . co m*/ * @param location The path to the HTML file. */ public static Node parse(String location) { try { XMLReader reader = new Parser(); reader.setFeature(Parser.namespacesFeature, false); reader.setFeature(Parser.namespacePrefixesFeature, false); Transformer transformer = TransformerFactory.newInstance().newTransformer(); DOMResult result = new DOMResult(); transformer.transform(new SAXSource(reader, new InputSource(new FileReader(new File(location)))), result); return result.getNode(); } catch (TransformerConfigurationException ex) { TestCase.fail(ex.getLocalizedMessage()); } catch (SAXNotRecognizedException ex) { TestCase.fail(ex.getLocalizedMessage()); } catch (SAXNotSupportedException ex) { TestCase.fail(ex.getLocalizedMessage()); } catch (TransformerException ex) { TestCase.fail(ex.getLocalizedMessage()); } catch (IOException ex) { TestCase.fail(ex.getLocalizedMessage()); } return null; }