Skip to content

Instantly share code, notes, and snippets.

@xkr47
Last active August 29, 2015 13:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save xkr47/9595446 to your computer and use it in GitHub Desktop.
Save xkr47/9595446 to your computer and use it in GitHub Desktop.
Eclipse detail formatters for org.w3c.dom.*
// org.w3c.dom.Node
org.w3c.dom.bootstrap.DOMImplementationRegistry registry = org.w3c.dom.bootstrap.DOMImplementationRegistry.newInstance();
org.w3c.dom.ls.DOMImplementationLS impl = (org.w3c.dom.ls.DOMImplementationLS) registry.getDOMImplementation("XML 3.0 LS 3.0");
org.w3c.dom.ls.LSSerializer serializer = impl.createLSSerializer();
((org.w3c.dom.DOMConfiguration) serializer).setParameter("xml-declaration", Boolean.FALSE);
java.io.StringWriter out = new java.io.StringWriter();
org.w3c.dom.ls.LSOutput output = impl.createLSOutput();
output.setCharacterStream(out);
serializer.write(this, output);
return out.toString();
// org.w3c.dom.NodeList
org.w3c.dom.bootstrap.DOMImplementationRegistry registry = org.w3c.dom.bootstrap.DOMImplementationRegistry.newInstance();
org.w3c.dom.ls.DOMImplementationLS impl = (org.w3c.dom.ls.DOMImplementationLS) registry.getDOMImplementation("XML 3.0 LS 3.0");
org.w3c.dom.ls.LSSerializer serializer = impl.createLSSerializer();
((org.w3c.dom.DOMConfiguration) serializer).setParameter("xml-declaration", Boolean.FALSE);
java.io.StringWriter out = new java.io.StringWriter();
org.w3c.dom.ls.LSOutput output = impl.createLSOutput();
output.setCharacterStream(out);
if (this instanceof org.w3c.dom.Node) {
serializer.write(this, output);
} else for (int i=0; i<getLength(); ++i) {
org.w3c.dom.Node n = item(i);
serializer.write(n, output);
}
return out.toString();
@xkr47
Copy link
Author

xkr47 commented Sep 30, 2014

updated to drop the xml declaration

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment