[英]Eclipse plugin development AndroidXmlFormatter
我正在构建一个eclipse插件,该插件可以修改android XML(layout)文件。 我在内部使用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);
但是,该文档未格式化。 :(可能是什么问题?我的问题有替代方法吗?
仍然没有找到明确的答案。 就格式化而言,我使用了com.android.ide.eclipse.adt.internal.editors.formatting包来格式化xml默认android样式。
XmlFormatPreferences xfp=XmlFormatPreferences.create();
xfp.joinLines=true;
xfp.removeEmptyLines=true;
xfp.useEclipseIndent=true;
return XmlPrettyPrinter.prettyPrint(xmlAsWriter.toString(), xfp, XmlFormatStyle.FILE, "\n");
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.