List of usage examples for org.w3c.dom.ls DOMImplementationLS createLSSerializer
public LSSerializer createLSSerializer();
LSSerializer
object. From source file:Main.java
public static String lsSerialize(Document doc) { DOMImplementationLS domImplementation = (DOMImplementationLS) doc.getImplementation(); LSSerializer lsSerializer = domImplementation.createLSSerializer(); return lsSerializer.writeToString(doc); }
From source file:Main.java
public static String elementToString(Element el) { if (el == null) return ""; Document document = el.getOwnerDocument(); DOMImplementationLS domImplLS = (DOMImplementationLS) document.getImplementation(); LSSerializer serializer = domImplLS.createLSSerializer(); return serializer.writeToString(el); }
From source file:Main.java
public static String serializeNode(Node node) throws LSException, IllegalAccessException, DOMException, InstantiationException, ClassNotFoundException, ClassCastException { System.setProperty(DOMImplementationRegistry.PROPERTY, "org.apache.xerces.dom.DOMImplementationSourceImpl"); DOMImplementationRegistry registry = DOMImplementationRegistry.newInstance(); DOMImplementationLS impl = (DOMImplementationLS) registry.getDOMImplementation("LS"); LSSerializer writer = impl.createLSSerializer(); String serializedElement = writer.writeToString(node); return serializedElement; }
From source file:Main.java
/** * Node to string.//from w w w. j a v a2s. c o m * * @param node * the node * @return the string */ public static String nodeToString(Node node) { Document doc = node.getOwnerDocument(); DOMImplementationLS domImplLS = (DOMImplementationLS) doc.getImplementation(); LSSerializer serializer = domImplLS.createLSSerializer(); serializer.getDomConfig().setParameter("xml-declaration", false); String string = serializer.writeToString(node); return string.trim(); }
From source file:Main.java
/** * Serializes a DOM Document to XML/*ww w.j a v a2 s . c o m*/ * * @param document * a DOM document * @return the Document serialized to XML */ public static String toXML(Document document) { DOMImplementationLS domLS = (DOMImplementationLS) implementation; LSSerializer serializer = domLS.createLSSerializer(); String s = serializer.writeToString(document); return s; }
From source file:Main.java
public static String elementToString(Element element) { Document document = element.getOwnerDocument(); DOMImplementationLS domImplLS = (DOMImplementationLS) document.getImplementation(); LSSerializer serializer = domImplLS.createLSSerializer(); // Client assumes/requires UTF-8 response. LSOutput lsOutput = domImplLS.createLSOutput(); lsOutput.setEncoding("UTF-8"); StringWriter stringWriter = new StringWriter(); lsOutput.setCharacterStream(stringWriter); serializer.write(element, lsOutput); return stringWriter.toString(); }
From source file:Main.java
private static String parseXmlDocToString(Document xmlDoc) throws ClassNotFoundException, InstantiationException, IllegalAccessException { // Add formatting to the xml document in case we want to save to a file 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", true); // Set this to true if the declaration is needed to be outputted return writer.writeToString(xmlDoc); }
From source file:Main.java
public static String lsSerializeDom(Node doc) throws Exception { if (doc == null) return null; DOMImplementationRegistry registry = DOMImplementationRegistry.newInstance(); DOMImplementationLS impl = (DOMImplementationLS) registry.getDOMImplementation("LS"); LSSerializer writer = impl.createLSSerializer(); return writer.writeToString(doc); }
From source file:Main.java
/** * Serialises the XML node into a string. * /* www . j a v a 2 s. c o m*/ * @param node the XML node * @return the corresponding string */ public static String serialise(Node node) { try { DOMImplementationRegistry registry = DOMImplementationRegistry.newInstance(); DOMImplementationLS lsImpl = (DOMImplementationLS) registry.getDOMImplementation("LS"); LSSerializer serializer = lsImpl.createLSSerializer(); return serializer.writeToString(node); } catch (Exception e) { log.fine("could not serialise XML node: " + e); return ""; } }
From source file:Main.java
public static String nodeToString(Node node) { DOMImplementationLS ls = (DOMImplementationLS) node.getOwnerDocument().getImplementation().getFeature("LS", "3.0"); LSSerializer seri = ls.createLSSerializer(); return seri.writeToString(node); }