开发者

java dom xml parser- how to check if the document is empty (or not)

开发者 https://www.devze.com 2023-04-11 16:31 出处:网络
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 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 proce开发者_如何学JAVAssing and move on to the next file?


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号