Code example for Document

Methods: getElementsByTagName, getFirstChild

0
			System.out.println("Document Builder Factory.");
			DocumentBuilder db = dbf.newDocumentBuilder();
			System.out.println("Document Builder");
			Document d = db.parse("src/com/sumit/xml/sorc.xml");
			System.out.println("file parse.");
			NodeList tree = d.getElementsByTagName("book");
			// Node tree1 = d.getChildNodes(tree.item(1)); 
			Node tree1 = d.getFirstChild();
			Node tree2 = tree1.getFirstChild();
			Node tree3 = tree2.getNextSibling();
			System.out.println("Node List:" + tree.getLength() + tree3.getNodeName());
		} catch (Exception e) {
			System.out.println("Exception catched");
		} 
 
	} 
 
}