@Override protected DOMWriter initialValue() { return new DOMWriter(); } };
public org.w3c.dom.Document write(Document document) throws DocumentException { if (document instanceof org.w3c.dom.Document) { return (org.w3c.dom.Document) document; } resetNamespaceStack(); org.w3c.dom.Document domDocument = createDomDocument(document); appendDOMTree(domDocument, domDocument, document.content()); namespaceStack.clear(); return domDocument; }
protected void writeNamespace(org.w3c.dom.Element domElement, Namespace namespace) { String attributeName = attributeNameForNamespace(namespace); // domElement.setAttributeNS("", attributeName, namespace.getURI()); domElement.setAttribute(attributeName, namespace.getURI()); }
protected org.w3c.dom.Document createDomDocument(Document document) throws DocumentException { org.w3c.dom.Document result = null; // use the given domDocumentClass (if not null) if (domDocumentClass != null) { try { result = (org.w3c.dom.Document) domDocumentClass.newInstance(); } catch (Exception e) { throw new DocumentException( "Could not instantiate an instance " + "of DOM Document with class: " + domDocumentClass.getName(), e); } } else { // lets try JAXP first before using the hardcoded default parsers result = createDomDocumentViaJAXP(); if (result == null) { Class<?> theClass = getDomDocumentClass(); try { result = (org.w3c.dom.Document) theClass.newInstance(); } catch (Exception e) { throw new DocumentException("Could not instantiate an " + "instance of DOM Document " + "with class: " + theClass.getName(), e); } } } return result; }
if (isNamespaceDeclaration(elementNamespace)) { namespaceStack.push(elementNamespace); writeNamespace(domElement, elementNamespace); Namespace namespace = (Namespace) declaredNamespaces.get(i); if (isNamespaceDeclaration(namespace)) { namespaceStack.push(namespace); writeNamespace(domElement, namespace); appendDOMTree(domDocument, domElement, element.content());
public static org.w3c.dom.Node write(Document d4jDoc) throws Throwable { DOMWriter domWriter = new DOMWriter(); org.w3c.dom.Document w3cDoc = domWriter.write(d4jDoc); org.w3c.dom.Element w3cEl = w3cDoc.getDocumentElement(); return w3cEl; } public static void writePretty (Node d4jNode, OutputStream outStream) throws Throwable {
protected void appendDOMTree(org.w3c.dom.Document domDocument, org.w3c.dom.Node domCurrent, List<Node> content) { for (Node node : content) { if (node instanceof Element) { appendDOMTree(domDocument, domCurrent, (Element) node); } else if (node instanceof Text) { Text text = (Text) node; appendDOMTree(domDocument, domCurrent, text.getText()); } else if (node instanceof CDATA) { appendDOMTree(domDocument, domCurrent, (CDATA) node); } else if (node instanceof Comment) { appendDOMTree(domDocument, domCurrent, (Comment) node); } else if (node instanceof Entity) { appendDOMTree(domDocument, domCurrent, (Entity) node); } else if (node instanceof ProcessingInstruction) { appendDOMTree(domDocument, domCurrent, (ProcessingInstruction) node); } } }
final org.dom4j.Document doc = this.fac.createDocument(copy); doc.normalize(); layoutDom = this.writer.get().write(doc); person.setAttribute(Constants.PLF, layoutDom);
if (isNamespaceDeclaration(elementNamespace)) { namespaceStack.push(elementNamespace); writeNamespace(domElement, elementNamespace); Namespace namespace = (Namespace) declaredNamespaces.get(i); if (isNamespaceDeclaration(namespace)) { namespaceStack.push(namespace); writeNamespace(domElement, namespace); appendDOMTree(domDocument, domElement, element.content());
protected org.w3c.dom.Document createDomDocument(Document document) throws DocumentException { org.w3c.dom.Document result = null; // use the given domDocumentClass (if not null) if (domDocumentClass != null) { try { result = (org.w3c.dom.Document) domDocumentClass.newInstance(); } catch (Exception e) { throw new DocumentException( "Could not instantiate an instance " + "of DOM Document with class: " + domDocumentClass.getName(), e); } } else { // lets try JAXP first before using the hardcoded default parsers result = createDomDocumentViaJAXP(); if (result == null) { Class<?> theClass = getDomDocumentClass(); try { result = (org.w3c.dom.Document) theClass.newInstance(); } catch (Exception e) { throw new DocumentException("Could not instantiate an " + "instance of DOM Document " + "with class: " + theClass.getName(), e); } } } return result; }
protected void appendDOMTree(org.w3c.dom.Document domDocument, org.w3c.dom.Node domCurrent, List<Node> content) { for (Node node : content) { if (node instanceof Element) { appendDOMTree(domDocument, domCurrent, (Element) node); } else if (node instanceof Text) { Text text = (Text) node; appendDOMTree(domDocument, domCurrent, text.getText()); } else if (node instanceof CDATA) { appendDOMTree(domDocument, domCurrent, (CDATA) node); } else if (node instanceof Comment) { appendDOMTree(domDocument, domCurrent, (Comment) node); } else if (node instanceof Entity) { appendDOMTree(domDocument, domCurrent, (Entity) node); } else if (node instanceof ProcessingInstruction) { appendDOMTree(domDocument, domCurrent, (ProcessingInstruction) node); } } }
public org.w3c.dom.Document write(Document document, org.w3c.dom.DOMImplementation domImpl) throws DocumentException { if (document instanceof org.w3c.dom.Document) { return (org.w3c.dom.Document) document; } resetNamespaceStack(); org.w3c.dom.Document domDocument = createDomDocument(document, domImpl); appendDOMTree(domDocument, domDocument, document.content()); namespaceStack.clear(); return domDocument; }
if (isNamespaceDeclaration(elementNamespace)) { namespaceStack.push(elementNamespace); writeNamespace(domElement, elementNamespace); Namespace namespace = (Namespace) declaredNamespaces.get(i); if (isNamespaceDeclaration(namespace)) { namespaceStack.push(namespace); writeNamespace(domElement, namespace); appendDOMTree(domDocument, domElement, element.content());
protected org.w3c.dom.Document createDomDocument(Document document) throws DocumentException { org.w3c.dom.Document result = null; // use the given domDocumentClass (if not null) if (domDocumentClass != null) { try { result = (org.w3c.dom.Document) domDocumentClass.newInstance(); } catch (Exception e) { throw new DocumentException( "Could not instantiate an instance " + "of DOM Document with class: " + domDocumentClass.getName(), e); } } else { // lets try JAXP first before using the hardcoded default parsers result = createDomDocumentViaJAXP(); if (result == null) { Class theClass = getDomDocumentClass(); try { result = (org.w3c.dom.Document) theClass.newInstance(); } catch (Exception e) { throw new DocumentException("Could not instantiate an " + "instance of DOM Document " + "with class: " + theClass.getName(), e); } } } return result; }
protected void writeNamespace(org.w3c.dom.Element domElement, Namespace namespace) { String attributeName = attributeNameForNamespace(namespace); // domElement.setAttributeNS("", attributeName, namespace.getURI()); domElement.setAttribute(attributeName, namespace.getURI()); }
protected void appendDOMTree(org.w3c.dom.Document domDocument, org.w3c.dom.Node domCurrent, List<Node> content) { for (Node node : content) { if (node instanceof Element) { appendDOMTree(domDocument, domCurrent, (Element) node); } else if (node instanceof Text) { Text text = (Text) node; appendDOMTree(domDocument, domCurrent, text.getText()); } else if (node instanceof CDATA) { appendDOMTree(domDocument, domCurrent, (CDATA) node); } else if (node instanceof Comment) { appendDOMTree(domDocument, domCurrent, (Comment) node); } else if (node instanceof Entity) { appendDOMTree(domDocument, domCurrent, (Entity) node); } else if (node instanceof ProcessingInstruction) { appendDOMTree(domDocument, domCurrent, (ProcessingInstruction) node); } } }
public org.w3c.dom.Document write(Document document) throws DocumentException { if (document instanceof org.w3c.dom.Document) { return (org.w3c.dom.Document) document; } resetNamespaceStack(); org.w3c.dom.Document domDocument = createDomDocument(document); appendDOMTree(domDocument, domDocument, document.content()); namespaceStack.clear(); return domDocument; }