在我的一种方法中,我有一个实例化的DOM org.w3c.dom.Document ,似乎被正确初始化,因为当我使用以下方式转储它时:
In one of my methods I have a DOM org.w3c.dom.Document instantiated and seems to be initialized properly since when I dump it using:
LOG.info("DOM: " + doc.getDocumentElement().getTextContent());它输出应该存在的SOAP消息的有效和最新内容。
It outputs a valid and current content of a SOAP message that should be there.
但是之前(和之后)只有一个声明,它显示为 null :
But only one statement before (and after), it shows as null:
LOG.info("doc BEFORE = " + doc); LOG.info("DOM: " + doc.getDocumentElement().getTextContent()); LOG.info("doc AFTER: = " + doc);他们都显示 null ,总共
They both show null with totally valid content in between.
这对我没有意义...我还缺少什么?
This doesn't make sense to me... What am I missing?
根据意见中的建议更新,我将日志语句更改为
Update, per the suggestions in the comments: I changed the log statements to
LOG.info("doc BEFORE/AFTER = " + doc + ", " + doc.toString() + ", " + (doc==null));输出为:
INFO:doc BEFORE = [#document:null],[#document:null],false
INFO: doc BEFORE = [#document: null], [#document: null], false
因此,@qqilihq是正确的:该文档不为空,但doc.toString()是。
I therefore conclude that @qqilihq is right: The doc is not null, but doc.toString() is.
推荐答案qqilihq有正确的想法。做一个 System.out.println(doc.getClass()); ,然后google实现文档它打印出来。找到源代码后,查找 toString()方法。我会打赌它只是返回 null 。
I bet @qqilihq has the right idea. Do a System.out.println(doc.getClass());, then google the source code of the class implementing Document that it prints out. Once you find the source code, look for the toString() method. I would bet it's just returning null.
更多推荐
为什么DOM文档在实际有效时显示为null?
发布评论