2

I have coding below:

            try{                                
            address = "http://isbndb.com//api/books.xml? 
            access_key=CKEHIG4D&index1=isbn&value1=" +barcode;
            URL url = new URL(address);
            URLConnection conn = url.openConnection();

            DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
            DocumentBuilder builder = factory.newDocumentBuilder();
            Document doc = builder.parse(conn.getInputStream());

            NodeList nodes = doc.getElementsByTagName("BookData");
            for (int i = 0; i < nodes.getLength(); i++) {
                Element element = (Element) nodes.item(i);
                NodeList title = element.getElementsByTagName("LongTitle");
                Element line = (Element) title.item(0);
                titleList.add(line.getTextContent());
            }
        }
        catch (Exception e) {
            e.printStackTrace();
        }

and theXML format is

http://isbndb.com//api/books.xml?access_key=CKEHIG4D&index1=isbn&value1=1593270615

the error is the line --> NodeList title = element.getElementsByTagName("LongTitle");

Actually what's wrong with that?

4
  • the method getElementsByTagName(String)is undefined for the type Element Commented Oct 21, 2012 at 9:04
  • NodeList title = element.getElementsByTagName("TitleLong"); Commented Oct 21, 2012 at 9:04
  • Change "LongTitle" --> "TitleLong" Commented Oct 21, 2012 at 9:08
  • changed...but still the same error Commented Oct 21, 2012 at 9:10

2 Answers 2

3

Make sure you are importing the right Element class (org.w3c.dom.Element).

Sign up to request clarification or add additional context in comments.

Comments

0

Change "LongTitle" --> "TitleLong"

in

NodeList title = element.getElementsByTagName("LongTitle");

3 Comments

NodeList nodes = doc.getElementsByTagName("BookData"); this already declare it...am i correct?
No, the node list in the problematic line
still cant run~ the same erro

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.