Document document = node.getOwnerDocument(); DOMImplementationLS domImplLS = (DOMImplementationLS) document .getImplementation(); LSSerializer serializer = domImplLS.createLSSerializer(); String str = serializer.writeToString(node);
public String getStringFromDoc(org.w3c.dom.Document doc) { DOMImplementationLS domImplementation = (DOMImplementationLS) doc.getImplementation(); LSSerializer lsSerializer = domImplementation.createLSSerializer(); return lsSerializer.writeToString(doc); }
private String elementToString(Element root) { DOMImplementationLS domImplLS = (DOMImplementationLS) root.getOwnerDocument().getImplementation(); return domImplLS.createLSSerializer().writeToString(root); } }
/** * This method throws a CanonicalizationException if the supplied Document * is not able to be traversed using a TreeWalker. * * @param document * @throws CanonicalizationException */ public static void checkTraversability(Document document) throws CanonicalizationException { if (!document.isSupported("Traversal", "2.0")) { Object exArgs[] = {document.getImplementation().getClass().getName() }; throw new CanonicalizationException( "c14n.Canonicalizer.TraversalNotSupported", exArgs ); } }
/** * Determines the Input Encoding of the Document Node to serialize. If the Document Node * is not a DOM Level 3 Node, then null is returned. * * @param nodeArg The Node to serialize * @return A String containing the input encoding. */ protected String getInputEncoding(Node nodeArg) { Document doc = null; // Determine the Input Encoding of the document if (nodeArg != null) { if (nodeArg.getNodeType() == Node.DOCUMENT_NODE) { // The Document node is the Node argument doc = (Document)nodeArg; } else { // The Document node is the Node argument's ownerDocument doc = nodeArg.getOwnerDocument(); } // Determine the DOM Version. if (doc != null && doc.getImplementation().hasFeature("Core","3.0")) { return doc.getInputEncoding(); } } // The default encoding returned is null return null; }
/** * Determines the XML Encoding of the Document Node to serialize. If the Document Node * is not a DOM Level 3 Node, then the default encoding "UTF-8" is returned. * * @param nodeArg The Node to serialize * @return A String containing the encoding pseudo-attribute of the XMLDecl. * @throws Throwable if the DOM implementation does not implement Document.getXmlEncoding() */ protected String getXMLEncoding(Node nodeArg) { Document doc = null; // Determine the XML Encoding of the document if (nodeArg != null) { if (nodeArg.getNodeType() == Node.DOCUMENT_NODE) { // The Document node is the Node argument doc = (Document)nodeArg; } else { // The Document node is the Node argument's ownerDocument doc = nodeArg.getOwnerDocument(); } // Determine the XML Version. if (doc != null && doc.getImplementation().hasFeature("Core","3.0")) { return doc.getXmlEncoding(); } } // The default encoding is UTF-8 except for the writeToString method return "UTF-8"; }
/** * Determines the Input Encoding of the Document Node to serialize. If the Document Node * is not a DOM Level 3 Node, then null is returned. * * @param nodeArg The Node to serialize * @return A String containing the input encoding. */ protected String getInputEncoding(Node nodeArg) { Document doc = null; // Determine the Input Encoding of the document if (nodeArg != null) { if (nodeArg.getNodeType() == Node.DOCUMENT_NODE) { // The Document node is the Node argument doc = (Document)nodeArg; } else { // The Document node is the Node argument's ownerDocument doc = nodeArg.getOwnerDocument(); } // Determine the DOM Version. if (doc != null && doc.getImplementation().hasFeature("Core","3.0")) { return doc.getInputEncoding(); } } // The default encoding returned is null return null; }
if (doc != null && doc.getImplementation().hasFeature("Core","3.0")) { return doc.getXmlVersion();
/** * Determines the XML Encoding of the Document Node to serialize. If the Document Node * is not a DOM Level 3 Node, then the default encoding "UTF-8" is returned. * * @param nodeArg The Node to serialize * @return A String containing the encoding pseudo-attribute of the XMLDecl. * @throws Throwable if the DOM implementation does not implement Document.getXmlEncoding() */ protected String getXMLEncoding(Node nodeArg) { Document doc = null; // Determine the XML Encoding of the document if (nodeArg != null) { if (nodeArg.getNodeType() == Node.DOCUMENT_NODE) { // The Document node is the Node argument doc = (Document)nodeArg; } else { // The Document node is the Node argument's ownerDocument doc = nodeArg.getOwnerDocument(); } // Determine the XML Version. if (doc != null && doc.getImplementation().hasFeature("Core","3.0")) { return doc.getXmlEncoding(); } } // The default encoding is UTF-8 except for the writeToString method return "UTF-8"; }
if (doc != null && doc.getImplementation().hasFeature("Core","3.0")) { return doc.getXmlVersion();
DOMImplementation impl=doc.getImplementation(); if(impl!=null && impl.hasFeature("Core","2.0"))
DOMImplementation impl=doc.getImplementation(); if(impl!=null && impl.hasFeature("Core","2.0"))
Document ownerDoc = pos.getOwnerDocument(); if (ownerDoc != null && ownerDoc.getImplementation().hasFeature("Core", "3.0")) { fIsLevel3DOM = true; .getImplementation() .hasFeature("Core", "3.0")) { fIsLevel3DOM = true;
Document ownerDoc = pos.getOwnerDocument(); if (ownerDoc != null && ownerDoc.getImplementation().hasFeature("Core", "3.0")) { fIsLevel3DOM = true; .getImplementation() .hasFeature("Core", "3.0")) { fIsLevel3DOM = true;
Document ownerDoc = pos.getOwnerDocument(); if (ownerDoc != null && ownerDoc.getImplementation().hasFeature("Core", "3.0")) { fIsLevel3DOM = true; .getImplementation() .hasFeature("Core", "3.0")) { fIsLevel3DOM = true;
Document ownerDoc = pos.getOwnerDocument(); if (ownerDoc != null && ownerDoc.getImplementation().hasFeature("Core", "3.0")) { fIsLevel3DOM = true; .getImplementation() .hasFeature("Core", "3.0")) { fIsLevel3DOM = true;
private static String prettyPrintXmlDocument(Document document) { // Pretty-prints a DOM document to XML using DOM Load and Save's LSSerializer. // Note that the "format-pretty-print" DOM configuration parameter can only be set in JDK 1.6+. DOMImplementation domImplementation = document.getImplementation(); if (domImplementation.hasFeature("LS", "3.0") && domImplementation.hasFeature("Core", "2.0")) { DOMImplementationLS domImplementationLS = (DOMImplementationLS) domImplementation.getFeature("LS", "3.0"); LSSerializer lsSerializer = domImplementationLS.createLSSerializer(); DOMConfiguration domConfiguration = lsSerializer.getDomConfig(); if (domConfiguration.canSetParameter("format-pretty-print", Boolean.TRUE)) { lsSerializer.getDomConfig().setParameter("format-pretty-print", Boolean.TRUE); LSOutput lsOutput = domImplementationLS.createLSOutput(); lsOutput.setEncoding("UTF-8"); StringWriter stringWriter = new StringWriter(); lsOutput.setCharacterStream(stringWriter); lsSerializer.write(document, lsOutput); return stringWriter.toString(); } else { throw new RuntimeException("DOMConfiguration 'format-pretty-print' parameter isn't settable."); } } else { throw new RuntimeException("DOM 3.0 LS and/or DOM 2.0 Core not supported."); } }
DOMImplementationLS ls = (DOMImplementationLS) doc.getImplementation().getFeature("LS", "3.0"); // NOI18N assert ls != null : "No DOM 3 LS supported in " + doc.getClass().getName(); LSOutput output = ls.createLSOutput();
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); }
private String getString(Document config) { DOMImplementationLS impl = (DOMImplementationLS) config.getImplementation(); LSSerializer serializer = impl.createLSSerializer(); LSOutput out = impl.createLSOutput(); out.setEncoding("UTF-8"); Writer stringWriter = new StringWriter(); out.setCharacterStream(stringWriter); serializer.write(config, out); return stringWriter.toString(); }