Java Programming John Smith C++ Programming Jane Doe
import org.w3c.dom.Document; import org.w3c.dom.Element; import org.w3c.dom.NodeList; import javax.xml.parsers.DocumentBuilder; import javax.xml.parsers.DocumentBuilderFactory; import java.io.File; public class LibraryParser { public static void main(String[] args) { try { File xmlFile = new File("library.xml"); DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance(); DocumentBuilder dBuilder = dbFactory.newDocumentBuilder(); Document doc = dBuilder.parse(xmlFile); doc.getDocumentElement().normalize(); NodeList bookNodes = doc.getElementsByTagName("book"); Element firstBook = (Element) bookNodes.item(0); System.out.println(firstBook.getNodeName()); } catch (Exception e) { e.printStackTrace(); } } }In this example, we first create a `Document` object by parsing the XML file using a `DocumentBuilder`. We then retrieve all the `book` elements using `getElementsByTagName()` and get the first one using `item(0)`. We can then access the properties of the `Element`, such as its `nodeName`. Overall, the `getElement()` method is part of the Java XML API and is used to retrieve elements from an XML document. It is included in the `org.w3c.dom` package, which is used to represent and manipulate XML documents in Java.