Document d = new Document();
Element root = d.createElement("", "parent");
root.setName("catalog");
Element book = d.createElement("", "child");
book.setName("book");
book.setAttribute(null, "id", "1");
Element author = d.createElement("", "child");
author.setName("author");
author.addChild(0, Node.TEXT, "1");
book.addChild(0, Node.ELEMENT, author);
Element title = d.createElement("", "child");
title.setName("title");
title.addChild(0, Node.TEXT, "2");
book.addChild(1, Node.ELEMENT, title);
Element genre = d.createElement("", "child");
genre.setName("genre");
genre.addChild(0, Node.TEXT, "3l");
book.addChild(2, Node.ELEMENT, genre);
Element publishDate = d.createElement("", "child");
publishDate.setName("publish-date");
publishDate.addChild(0, Node.TEXT, "4");
book.addChild(3, Node.ELEMENT, publishDate);
root.addChild(0, Node.ELEMENT, book);
d.addChild(root.ELEMENT, root);
No comments:
Post a Comment