public DOMSerializer() { super(Node.class); DOMImplementationRegistry registry; try { registry = DOMImplementationRegistry.newInstance(); } catch (Exception e) { throw new IllegalStateException("Could not instantiate DOMImplementationRegistry: "+e.getMessage(), e); } _domImpl = (DOMImplementationLS)registry.getDOMImplementation("LS"); }
public DOMSerializer() { super(Node.class); DOMImplementationRegistry registry; try { registry = DOMImplementationRegistry.newInstance(); } catch (Exception e) { throw new IllegalStateException("Could not instantiate DOMImplementationRegistry: "+e.getMessage(), e); } _domImpl = (DOMImplementationLS)registry.getDOMImplementation("LS"); }
public DOMSerializer() { super(Node.class); DOMImplementationRegistry registry; try { registry = DOMImplementationRegistry.newInstance(); } catch (Exception e) { throw new IllegalStateException("Could not instantiate DOMImplementationRegistry: "+e.getMessage(), e); } _domImpl = (DOMImplementationLS)registry.getDOMImplementation("LS"); }
public DOMSerializer() { super(Node.class); DOMImplementationRegistry registry; try { registry = DOMImplementationRegistry.newInstance(); } catch (Exception e) { throw new IllegalStateException("Could not instantiate DOMImplementationRegistry: "+e.getMessage(), e); } _domImpl = (DOMImplementationLS)registry.getDOMImplementation("LS"); }
private static String prettyFormat(Document document, boolean keepXmlDeclaration) { try { DOMImplementationRegistry registry = DOMImplementationRegistry.newInstance(); DOMImplementationLS domImplementation = (DOMImplementationLS) registry.getDOMImplementation("LS"); Writer stringWriter = new StringWriter(); LSOutput formattedOutput = domImplementation.createLSOutput(); formattedOutput.setCharacterStream(stringWriter); LSSerializer domSerializer = domImplementation.createLSSerializer(); domSerializer.getDomConfig().setParameter("format-pretty-print", true); // Set this to true if the declaration is needed to be in the output. domSerializer.getDomConfig().setParameter("xml-declaration", keepXmlDeclaration); domSerializer.write(document, formattedOutput); return stringWriter.toString(); } catch (Exception e) { throw new RuntimeException(FORMAT_ERROR, e); } }
DOMImplementationRegistry registry = DOMImplementationRegistry.newInstance(); DOMImplementationLS impl = (DOMImplementationLS) registry.getDOMImplementation("XML 3.0 LS 3.0"); if (impl == null) {
final DOMImplementationRegistry registry = DOMImplementationRegistry.newInstance(); final DOMImplementationLS impl = (DOMImplementationLS) registry.getDOMImplementation("LS"); final LSSerializer writer = impl.createLSSerializer();
private static String prettyFormat(Document document, boolean keepXmlDeclaration) { try { DOMImplementationRegistry registry = DOMImplementationRegistry.newInstance(); DOMImplementationLS domImplementation = (DOMImplementationLS) registry.getDOMImplementation("LS"); Writer stringWriter = new StringWriter(); LSOutput formattedOutput = domImplementation.createLSOutput(); formattedOutput.setCharacterStream(stringWriter); LSSerializer domSerializer = domImplementation.createLSSerializer(); domSerializer.getDomConfig().setParameter("format-pretty-print", true); // Set this to true if the declaration is needed to be in the output. domSerializer.getDomConfig().setParameter("xml-declaration", keepXmlDeclaration); domSerializer.write(document, formattedOutput); return stringWriter.toString(); } catch (Exception e) { throw new RuntimeException(FORMAT_ERROR, e); } }
public static String getIndented(String inXml) throws IOException { try { final InputSource src = new InputSource(new StringReader(inXml)); final Document domDoc = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(src); String encoding = domDoc.getXmlEncoding(); if (encoding == null) { // defaults to UTF-8 encoding = "UTF-8"; } final Node document = domDoc.getDocumentElement(); final boolean keepDeclaration = inXml.startsWith("<?xml"); final DOMImplementationRegistry registry = DOMImplementationRegistry.newInstance(); final DOMImplementationLS impl = (DOMImplementationLS) registry.getDOMImplementation("LS"); final LSSerializer writer = impl.createLSSerializer(); writer.setNewLine("\n"); writer.getDomConfig().setParameter("format-pretty-print", true); // Set this to true if the output needs to be beautified. writer.getDomConfig().setParameter("xml-declaration", keepDeclaration); // Set this to true if the declaration is needed to be outputted. LSOutput lsOutput = impl.createLSOutput(); lsOutput.setEncoding(encoding); Writer stringWriter = new StringWriter(); lsOutput.setCharacterStream(stringWriter); writer.write(document, lsOutput); return stringWriter.toString(); } catch (ParserConfigurationException | SAXException | ClassNotFoundException | InstantiationException | IllegalAccessException ex) { throw new XMLException(null, ex); } }
private Document getDocument(InputStream is) throws InstantiationException, IllegalAccessException, ClassNotFoundException { DOMImplementationRegistry registry = DOMImplementationRegistry.newInstance(); DOMImplementationLS impl = (DOMImplementationLS)registry.getDOMImplementation("LS"); LSParser parser = impl.createLSParser(DOMImplementationLS.MODE_SYNCHRONOUS, null); // we need to ignore whitespace here so the nodeToString() method will be able to indent it properly: parser.setFilter(new IgnoreWhitespaceFilter()); LSInput domInput = impl.createLSInput(); domInput.setByteStream(is); return parser.parse(domInput); }
private static DOMImplementationRegistry createDOMRegistry() { try { return DOMImplementationRegistry.newInstance(); } catch (ClassNotFoundException e) { throw new IllegalStateException(e); } catch (InstantiationException e) { throw new IllegalStateException(e); } catch (IllegalAccessException e) { throw new IllegalStateException(e); } } }
DOMImplementationLS domImplLS = null; try { DOMImplementation implementation = DOMImplementationRegistry.newInstance().getDOMImplementation("XML 3.0"); if (implementation != null) { domImplLS = (DOMImplementationLS) implementation.getFeature("LS", "3.0");
DOMImplementationLS domImplLS = null; try { DOMImplementation implementation = DOMImplementationRegistry.newInstance().getDOMImplementation("XML 3.0"); if (implementation != null) { domImplLS = (DOMImplementationLS) implementation.getFeature("LS", "3.0");
public DOMSerializer() { super(Node.class); DOMImplementationRegistry registry; try { registry = DOMImplementationRegistry.newInstance(); } catch (Exception e) { throw new IllegalStateException("Could not instantiate DOMImplementationRegistry: "+e.getMessage(), e); } _domImpl = (DOMImplementationLS)registry.getDOMImplementation("LS"); }
@SuppressWarnings("unchecked") public synchronized static <T> T getDOMImpl() { if (IMPL == null) { try { DOMImplementationRegistry registry = DOMImplementationRegistry.newInstance(); IMPL = registry.getDOMImplementation("LS 3.0"); } catch (Exception e) { throw new RuntimeException(e); } } return (T) IMPL; }
@SuppressWarnings("unchecked") public static <T> T getDOMImplUncached() { try { DOMImplementationRegistry registry = DOMImplementationRegistry.newInstance(); return (T) registry.getDOMImplementation("LS 3.0"); } catch (Exception e) { throw new RuntimeException(e); } }
public static String format(String xml) { try { final InputSource src = new InputSource(new StringReader(xml)); final Node document = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(src).getDocumentElement(); final Boolean keepDeclaration = Boolean.valueOf(xml.startsWith("<?xml")); //May need this: System.setProperty(DOMImplementationRegistry.PROPERTY,"com.sun.org.apache.xerces.internal.dom.DOMImplementationSourceImpl"); final DOMImplementationRegistry registry = DOMImplementationRegistry.newInstance(); final DOMImplementationLS impl = (DOMImplementationLS) registry.getDOMImplementation("LS"); final LSSerializer writer = impl.createLSSerializer(); writer.getDomConfig().setParameter("format-pretty-print", Boolean.TRUE); // Set this to true if the output needs to be beautified. writer.getDomConfig().setParameter("xml-declaration", keepDeclaration); // Set this to true if the declaration is needed to be outputted. return writer.writeToString(document); } catch (Exception e) { throw new RuntimeException(e); } }
final Boolean keepDeclaration = Boolean.valueOf(xml.startsWith("<?xml")); final DOMImplementationRegistry registry = DOMImplementationRegistry.newInstance(); final DOMImplementationLS impl = (DOMImplementationLS) registry.getDOMImplementation("LS"); final LSSerializer writer = impl.createLSSerializer();
final DOMImplementationRegistry registry = DOMImplementationRegistry.newInstance(); final DOMImplementationLS impl = (DOMImplementationLS) registry.getDOMImplementation("LS"); final LSSerializer writer = impl.createLSSerializer();
registry = DOMImplementationRegistry.newInstance(); } catch (final Exception e) {