What am I doing wrong while parsing this XML
I'm trying to parse an xml that has the following structure
And here's the code snippet Ive written to parse it
doc.getDocumentElement().normalize();
System.out.println ("Root element: " +
doc.getDocumentElement().getNodeName());//prints
GoodReadsResponse correctly
NodeList bk = doc.getElementsByTagName("book");// single all
encompassing element in response
Node n= bk.item(1);// since the 0th node is id the 1st must be the
title
System.out.println("Node value"+n.getLocalName());
Element e=(Element)n;
NodeList titleList= e.getElementsByTagName("title");//get the title
Element titleElem = (Element) titleList.item(1);
Node titleNode = titleElem.getChildNodes().item(0);// get the node
value
book.setTitle(titleNode.getLocalName());// this prints null
instead of printing Hamlet--why??
System.out.println("Title in
parser"+titleNode.getLocalName());//null again
Any idea why this is happening? Pointers would be appreciated!
No comments:
Post a Comment