Element element = doc.createElement("myElement"); String name = element.getName(); System.out.println("Element name: " + name);
Element element = doc.createElement("myElement"); element.setAttribute("id", "123"); String attributeName = element.getAttributeNode("id").getName(); System.out.println("Attribute name: " + attributeName);Output: Attribute name: id This method is part of the Java DOM (Document Object Model) API and is located in the org.w3c.dom package library.