为什么DOM文档在实际有效时显示为null?

编程入门 行业动态 更新时间:2024-10-11 15:17:04
本文介绍了为什么DOM文档在实际有效时显示为null?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

在我的一种方法中,我有一个实例化的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?

本文发布于:2023-07-21 06:07:48,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1174864.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:文档   在实际   DOM   null

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!