Why is the DOM document displayed as null when it is really valid?

In one of my methods, I have a DOM instance org.w3c.dom.Documentthat seems to be initializing correctly, because when I unload it using:

LOG.info("DOM: " + doc.getDocumentElement().getTextContent());

It displays the actual and current contents of the SOAP message that should be there.

But there is only one expression before (and after), it is displayed as null:

LOG.info("doc BEFORE = " + doc);
LOG.info("DOM: " + doc.getDocumentElement().getTextContent());
LOG.info("doc AFTER: = " + doc);

Both of them show nullwith fully valid content between .

It makes no sense to me ... What am I missing?


Update on suggestions in the comments: I changed the log statements to

LOG.info("doc BEFORE/AFTER = " + doc + ", " + doc.toString() + ", " + (doc==null));

And the result:

INFO: doc BEFORE = [#document: null], [#document: null], false

Therefore, I conclude that @qqilihq is right: the document is not null, but doc.toString () is.

+4
1

, @qqilihq . System.out.println(doc.getClass());, google , Document, . , toString(). , null.

+3

Source: https://habr.com/ru/post/1526792/


All Articles