Code example for Element

Methods: setAttributegetAttributes

0
    private static final Logger LOG = LoggerFactory.getLogger(W3CDOMStreamReaderTest.class); 
 
    public void testSingleElement() throws Exception { 
        Document doc = getDocument();
        Element e = doc.createElementNS("urn:test", "root");
        e.setAttribute("xmlns", "urn:test");
        doc.appendChild(e);
 
        assertEquals(1, e.getAttributes().getLength());
        LOG.info("start: " + XMLStreamReader.START_ELEMENT); 
        LOG.info("attr: " + XMLStreamReader.ATTRIBUTE); 
        LOG.info("ns: " + XMLStreamReader.NAMESPACE); 
        LOG.info("chars: " + XMLStreamReader.CHARACTERS); 
        LOG.info("end: " + XMLStreamReader.END_ELEMENT); 
 
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        writeXml(doc, baos);
        LOG.info(baos.toString());
        W3CDOMStreamReader reader = new W3CDOMStreamReader(doc.getDocumentElement());
        testSingleElement(reader);
Experience pair programming with AI  Get Codota for Java