TransformerFactory fact = new net.sf.saxon.TransformerFactoryImpl()
javax.xml.transform.TransformerFactory factory = new javax.xml.transform.TransformerFactory(); javax.xml.transform.Transformer transformer = factory.newTransformer(); javax.xml.transform.dom.DOMSource domSource = new javax.xml.transform.dom.DOMSource(rootNode); javax.xml.transform.stream.StreamResult result = new javax.xml.transform.stream.StreamResult(outputStream); transformer(domSource, result);
TransformerFactory factory = new net.sf.saxon.TransformerFactoryImpl();
TransformerFactory tfactory = new net.sf.saxon.TransformerFactoryImpl();
TransformerFactory transFact = new net.sf.saxon.TransformerFactoryImpl();
TransformerFactory factory = new net.sf.saxon.TransformerFactoryImpl()
private TransformerFactory _factory = new TransformerFactoryImpl();
TransformerFactory factory = new net.sf.saxon.TransformerFactoryImpl();
public static String getInnerHTML(Node node) throws TransformerConfigurationException, TransformerException { StringWriter sw = new StringWriter(); Result result = new StreamResult(sw); TransformerFactory factory = new net.sf.saxon.TransformerFactoryImpl(); Transformer proc = factory.newTransformer(); proc.setOutputProperty(OutputKeys.METHOD, "html"); for (int i = 0; i < node.getChildNodes().getLength(); i++) { proc.transform(new DOMSource(node.getChildNodes().item(i)), result); } return sw.toString(); }
// Create your document and it's root element. DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); DocumentBuilder builder = factory.newDocumentBuilder(); Document doc = builder.newDocument(); Element root = doc.createElement("root"); doc.appendChild(root); // Loop through your list and create an xml element for each list element. for(Integer i : yourList){ Element listItem = doc.createElement("integer"); listItem.setAttribute("value", i.toString()); root.appendChild(listItem); } // write the the Document to where-ever you want. FileOutputStream fos = yourContext.openFileOutput("data_store.xml", Context.MODE_PRIVATE); TransformerFactory factory = new TransformerFactory(); Transformer transformer = factory.newTransformer(); DOMSource source = new DOMSource(root); StreamResult result = new StreamResult(fos); transformer(source, result);
public static String getStringFromDocument(Document dom, boolean indented) { String signedContent = null; try { StringWriter sw = new StringWriter(); DOMSource domSource = new DOMSource(dom); TransformerFactory tf = new TransformerFactoryImpl(); Transformer trans = tf.newTransformer(); trans = tf.newTransformer(); trans.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes"); trans.setOutputProperty(OutputKeys.INDENT, indented ? "yes" : "no"); trans.transform(domSource, new StreamResult(sw)); sw.flush(); signedContent = sw.toString(); } catch (TransformerException e) { e.printStackTrace(); } return signedContent; }
//First create the resolver MapEntryResolver uriResolver = new MapEntryResolver(); //pass your map uriResolver.setMap(yourMap); //and attach it to the factory TransformerFactory factory = new TransformerFactoryImpl(); factory.setURIResolver(uriResolver); Transformer transformer = factory.newTransformer(new StreamSource(this.getClass().getResourceAsStream(pathToYourXsl)); //start transform and store result ByteArrayOutputstream result = new ByteArrayOutputstream(); transformer.transform(new StreamSource(pathToYourInputXml), new StreamResult(result));
public static void main(String[] args) throws TransformerException { final StringWriter messageOut = new StringWriter(); try { TransformerFactory fact = new net.sf.saxon.TransformerFactoryImpl(); Transformer newTransformer = fact.newTransformer(new StreamSource(new File("throw.xslt"))); ((net.sf.saxon.jaxp.TransformerImpl)newTransformer).getUnderlyingController().setRecoveryPolicy(Configuration.DO_NOT_RECOVER); ((net.sf.saxon.jaxp.TransformerImpl)newTransformer).getUnderlyingController().setMessageEmitter(new MessageEmitter() { @Override public void open() throws XPathException { setWriter(messageOut); super.open(); } }); newTransformer.transform(new StreamSource(new File("input.xml")), new StreamResult(new File("output.xml"))); } catch (TransformerException e) { System.out.println("THIS IS EXCEPTION: " + e.getMessage() + " <<<"); String message = messageOut.toString(); // this is the "exception message\n" that you want // not sure why it has a \n on it System.out.println("THIS IS THE MESSAGE WE WANT: " + message); throw new TransformerException(message, e); // rethrow using the captured message, if you really want that "exception message" available to a caller in e.getMessage() } }
"</xsl:stylesheet>"; TransformerFactory transFactory = new TransformerFactoryImpl();