2012-08-08 142 views
0

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

我想使用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); 

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

回答

0

仍然没有找到一个明确的答案。至于格式化,我用包com.android.ide.eclipse.adt.internal.editors .formatting格式xml默认安卓风格。

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