Eclipse插件开发AndroidXmlFormatter

时间:2012-08-08 10:33:43

标签: eclipse eclipse-plugin eclipse-adt xml-formatting

我正在构建一个修改android XML(布局)文件的eclipse插件。我在内部使用dom解析器来生成输出XML。但是XML格式混乱了。

我想使用android xml格式化机制。我试过了 -

//xmlFile is a IFile
    IDocumentProvider provider = new TextFileDocumentProvider(); provider.connect(xmlFile); 
    IDocument document = provider.getDocument(xmlFile); 
    xmlFile.setContents(inputStream, IFile.ENCODING_UTF_8, new NullProgressMonitor());
    AndroidXmlFormatter a=new AndroidXmlFormatter();
    IFormattingContext context=new FormattingContext();
    context.setProperty(FormattingContextProperties.CONTEXT_DOCUMENT, Boolean.TRUE);
    a.format(document, context);

但是,文档没有格式化。 :( 可能是什么问题呢?我的问题还有替代方案吗?

1 个答案:

答案 0 :(得分:0)

仍然没有找到确定的答案。就格式化而言,我使用了包com.android.ide.eclipse.adt.internal.editors.formatting来格式化xml默认的android-style。

        XmlFormatPreferences xfp=XmlFormatPreferences.create();
        xfp.joinLines=true;
        xfp.removeEmptyLines=true;
        xfp.useEclipseIndent=true;
        return XmlPrettyPrinter.prettyPrint(xmlAsWriter.toString(), xfp, XmlFormatStyle.FILE, "\n");
相关问题