ElementImpl extends NodeImpl implements Element { @Override public String toString() { if (documentBuilder == null) { return super.toString(); } Document document; synchronized (documentBuilder) { document = documentBuilder.newDocument(); } org.w3c.dom.Node node = asXmlNode(document); StringWriter writer = new StringWriter(); DOMSource domSource = new DOMSource(node); DOMResult domResult = new DOMResult(); synchronized (nullTransformer) { try { nullTransformer.transform(domSource, domResult); } catch (TransformerException e) { return super.toString(); } } domSource = new DOMSource(domResult.getNode()); StreamResult streamResult = new StreamResult(writer); synchronized (prettyPrintTransformer) { try { prettyPrintTransformer.transform(domSource, streamResult); } catch (TransformerException e) { return super.toString(); } } return writer.toString(); } protected  ElementImpl(String namespaceUri, String prefix, String name); protected  ElementImpl(String namespaceUri, String name,
			org.w3c.dom.Element xmlElement); String getNamespaceUri(); String getPrefix(); String getName(); Map<String, String> getNamespacePrefixMapping(); void setNamespacePrefixMapping(Map<String, String> namespace2Prefix); Collection<? extends Attribute> getAttributes(); abstract List<? extends Node> getChildren(); org.w3c.dom.Element asXmlNode(Document document); Object clone(); @Override int hashCode(); @Override boolean equals(Object obj); @Override String toString();  }
@Test public void testToString() { Document doc = Utils.createDocument(); org.w3c.dom.Element elem = doc.createElementNS("ns", "pre:name"); elem.setAttributeNS(XMLNS_NAMESPACE, "xmlns:xyz", "xyzns"); elem.setAttributeNS(XMLNS_NAMESPACE, "xmlns", "ijkns"); elem.setAttributeNS("ns", "name", "value"); elem.appendChild(doc.createElementNS("ns", "pre:child")); elem.appendChild(doc.createTextNode("text")); ConcreteElementImpl cei = null; try { cei = new ConcreteElementImpl("ns", "name", elem); } catch (ConstraintViolationException e) { fail("Did not expect ConstraintViolationException"); } cei.toString(); }