The Great Gatsby F. Scott Fitzgerald To Kill a Mockingbird Harper Lee
import org.jdom.Document; import org.jdom.Element; import org.jdom.input.SAXBuilder; import java.io.File; import java.util.List; public class BookParser { public static void main(String[] args) { try { File inputFile = new File("books.xml"); SAXBuilder saxBuilder = new SAXBuilder(); Document document = saxBuilder.build(inputFile); Element library = document.getRootElement(); ListIn this example, we use the getChildren() method to retrieve all the book elements as a list. Then, for each book element, we retrieve its title and author child elements using the getChild() method. The org.jdom package library is used in this example.books = library.getChildren("book"); for (Element book : books) { Element title = book.getChild("title"); Element author = book.getChild("author"); System.out.println("Title: " + title.getText()); System.out.println("Author: " + author.getText()); } } catch (Exception e) { e.printStackTrace(); } } }