Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- try {
- final ByteArrayOutputStream bos = new ByteArrayOutputStream();
- final XMLStreamWriter writer = XMLOutputFactory.newInstance().createXMLStreamWriter(bos);
- writer.writeStartDocument("UTF-8", "1.0");
- writer.writeStartElement("a");
- writer.writeDefaultNamespace(NS);
- writer.writeStartElement("b");
- writer.writeStartElement("c");
- writer.writeCharacters("d");
- writer.writeEndElement();
- writer.writeStartElement("e");
- writer.writeStartElement("f");
- writer.writeCharacters("g");
- writer.writeEndElement();
- writer.writeEndElement();
- writer.writeEndElement();
- writer.writeEndElement();
- //System.out.println(new String(bos.toByteArray(), StandardCharsets.UTF_8));
- return new ByteArrayInputStream(bos.toByteArray());
- } catch (Exception e) {
- throw new RuntimeException(e);
- }
- try {
- final Document doc = DocumentBuilderFactory.newInstance().newDocumentBuilder().newDocument();
- final Node policyClause = doc
- .appendChild(doc.createElementNS(NS, "a"))
- .appendChild(doc.createElementNS(NS, "b"));
- policyClause
- .appendChild(doc.createElementNS(NS, "c"))
- .setTextContent("d");
- policyClause
- .appendChild(doc.createElementNS(NS, "e"))
- .appendChild(doc.createElementNS(NS, "f"))
- .setTextContent("g");
- final ByteArrayOutputStream bos = new ByteArrayOutputStream();
- TransformerFactory.newInstance().newTransformer().transform(new DOMSource(doc), new StreamResult(bos));
- //System.out.println(new String(bos.toByteArray(), StandardCharsets.UTF_8));
- return new ByteArrayInputStream(bos.toByteArray());
- } catch (Exception e) {
- throw new RuntimeException(e);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement