Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/336.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jsf-2/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 详细信息格式化程序:代码段无法引用未声明导入的其他类_Java_Eclipse - Fatal编程技术网

Java 详细信息格式化程序:代码段无法引用未声明导入的其他类

Java 详细信息格式化程序:代码段无法引用未声明导入的其他类,java,eclipse,Java,Eclipse,我正在使用Eclipse氧气 我有一个类,它是XML文件的表示形式。此类没有重写toString()。我想使用detailformatter来显示它所表示的XML的漂亮打印格式 详细格式化程序代码片段: try{ String xml = getXmlString(); // This method returns single line string representation of the XML final InputSource src = new In

我正在使用Eclipse氧气

我有一个类,它是XML文件的表示形式。此类没有重写
toString()
。我想使用
detailformatter
来显示它所表示的XML的漂亮打印格式

详细格式化程序代码片段:

try{
        String xml = getXmlString(); // This method returns single line string representation of the XML
        final InputSource src = new InputSource(new StringReader(xml));
        final Node document = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(src).getDocumentElement();
        final Boolean keepDeclaration = Boolean.valueOf(xml.startsWith("<?xml"));
        final DOMImplementationRegistry registry = DOMImplementationRegistry.newInstance();
        final DOMImplementationLS impl = (DOMImplementationLS) registry.getDOMImplementation("LS");
        final LSSerializer writer = impl.createLSSerializer();

        writer.getDomConfig().setParameter("format-pretty-print", Boolean.TRUE); // Set this to true if the output needs to be beautified.
        writer.getDomConfig().setParameter("xml-declaration", keepDeclaration); // Set this to true if the declaration is needed to be outputted.

        return writer.writeToString(document);
    }
    catch (Exception e) {
        return getXmlString();
    }
如何做到这一点?如果详细信息格式化程序无法支持此功能,是否有其他方法实现此功能

注意,这个类是一个遗留类,我正试图为其编写详细信息格式化程序。我有源代码,但无法对此类进行任何更改。

使用完整类路径。
例如:

java.lang.String xml = getXmlString();
使用完整类路径。
例如:

java.lang.String xml = getXmlString();

在eclipse中:Ctrl+Shift+O将提供导入。@JoopEggen Ctrl+Shift+O将在类本身中提供导入。如何在详细信息格式化程序的代码段框中获取导入?eclipse中的可能重复项:Ctrl+Shift+O将提供导入。@JoopEggen Ctrl+Shift+O将在类本身中提供导入。如何在详细信息格式化程序的“代码段”框中获取导入?可能重复