0

I am trying to parse through a document using a DOM Parser in java.

For the following line of code--

Element docEle = dom.getDocumentElement();

I am getting the following error message--

2011-10-06 05:03:19,944 ERROR AWT-EventQueue-0 XMLDOMParser.class - Full error Stack     Trace=java.lang.NullPointerException
at com.arvind.googlepatentsdata.XMLDOMParser.parseDocument(XMLDOMParser.java:290)

As I understand, this error occurs whenever the document itself is empty... Is there some way to check (before the dom element is obtained) if the document is empty or not... So that if it is empty then I will not do any further processing and move on to the next file?

1 Answer 1

1

I don't see, that there is a need for a separate check. In getDocumentElement() this check is integrated and it throws an exception if there is no root element.

So all you have to do is to catch that exception and go to the next file.

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

Comments

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.