如何在Eclipse中的调试下更改变量或表达式视图中的Java对象的字符串表示形式

时间:2012-09-28 16:38:24

标签: java eclipse

如何在Variables或Expressions视图中更改字符串表示对象?

enter image description here

1 个答案:

答案 0 :(得分:2)

Eclipse具有调用详细格式化程序

的特殊功能

enter image description here

对于 org.w3c.dom.Node 界面,需要添加以下代码:

if (this == null) return null;  

javax.xml.transform.TransformerFactory tf = javax.xml.transform.TransformerFactory.newInstance();   

javax.xml.transform.Transformer transformer = tf.newTransformer();  

transformer.setOutputProperty(javax.xml.transform.OutputKeys.METHOD, "xml");  
transformer.setOutputProperty(javax.xml.transform.OutputKeys.INDENT, "yes");  
transformer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "3");  


javax.xml.transform.dom.DOMSource source = new javax.xml.transform.dom.DOMSource(this);  
if (source == null) return "Corrupted XML document: " + this.toString();  

java.io.StringWriter os = new java.io.StringWriter();  
javax.xml.transform.stream.StreamResult result = new   javax.xml.transform.stream.StreamResult(os);  
transformer.transform(source,result);  

return os.toString ();