List of utility methods to do XML Transform Usage
boolean | verifySignature(Element element, PublicKey validatingKey) verify Signature XMLSignatureFactory fac = initXMLSigFactory(); NodeList nl = element.getElementsByTagNameNS(XMLSignature.XMLNS, "Signature"); if (nl.getLength() == 0) { throw new RuntimeException("Cannot find Signature element"); DOMValidateContext valContext = new DOMValidateContext(validatingKey, nl.item(0)); try { valContext.setProperty("javax.xml.crypto.dsig.cacheReference", Boolean.TRUE); ... |
void | writeElementContent(XMLInputFactory inputFactory, XMLStreamWriter writer, Element element) write Element Content DOMSource domSource = new DOMSource(element); XMLEventReader parser = inputFactory.createXMLEventReader(domSource); StartElement startElement; Characters characters; while (parser.hasNext()) { XMLEvent event = parser.nextEvent(); switch (event.getEventType()) { case XMLStreamConstants.START_ELEMENT: ... |
void | writeXhtml(InputStream inputStream, Writer writer, Templates... templates) write Xhtml try { XMLFilter filter = null; for (Templates tplt : templates) { XMLFilter nextFilter = saxTf.newXMLFilter(tplt); if (filter != null) nextFilter.setParent(filter); filter = nextFilter; Transformer htmlTransformer = saxTf.newTransformer(); SAXSource transformSource = new SAXSource(filter, new InputSource(inputStream)); htmlTransformer.setOutputProperty(OutputKeys.METHOD, "xml"); htmlTransformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes"); htmlTransformer.setOutputProperty(OutputKeys.DOCTYPE_PUBLIC, "-//W3C//DTD XHTML 1.0 Strict//EN"); htmlTransformer.setOutputProperty(OutputKeys.DOCTYPE_SYSTEM, "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"); htmlTransformer.transform(transformSource, new StreamResult(writer)); } catch (TransformerConfigurationException e) { throw new RuntimeException(e); } catch (TransformerException e) { throw new RuntimeException(e); |
void | xsl(File inFile, File outFile, InputStream xslStream) xsl try { TransformerFactory factory = TransformerFactory.newInstance(); Templates template = factory.newTemplates(new StreamSource(xslStream)); Transformer xformer = template.newTransformer(); Source source = new StreamSource(new FileInputStream(inFile)); Result result = new StreamResult(new FileOutputStream(outFile)); xformer.transform(source, result); } catch (TransformerException e) { ... |