Code example for Element

Methods: appendChild, setAttribute

0
    } 
 
    public void testElementChild() throws Exception { 
        Document doc = getDocument();
        Element e = doc.createElementNS("urn:test", "root");
        e.setAttribute("xmlns", "urn:test");
        Element child = doc.createElementNS("urn:test2", "child");
        child.setAttribute("xmlns:a", "urn:test2");
 
        child.setPrefix("a");
        e.appendChild(child);
        doc.appendChild(e);
 
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        writeXml(doc, baos);
        LOG.info(baos.toString());
 
        W3CDOMStreamReader reader = new W3CDOMStreamReader(e);
        testElementChild(reader);
    } 
 
    protected void writeXml(Document doc, OutputStream out) throws TransformerException {
        TransformerFactory tf = TransformerFactory.newInstance();