Eclipse plugin development AndroidXmlFormatter

57 views Asked by At

I am building an eclipse plugin which modifies an android XML(layout) file. I use a dom parser internally to produce the output XML. However the XML formatting is messed up.

I want to use the android xml-formatting mechanism. I tried this -

//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);

But, the document isn't formatted. :( What could be the problem? Are there alternatives for my problem?

1

There are 1 answers

0
Akshaya Shanbhogue On BEST ANSWER

Still did not find a definitive answer. As far as formatting goes, I used package com.android.ide.eclipse.adt.internal.editors.formatting to format xml default android-style.

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