I am trying to ouput some XML. I read the XMLOutputter
API(http://www.jdom.org/docs/apidocs/org/jdom/output/XMLOutputter.html),
and the contructor indicated that I can pass in a Format object.
So, I try to do this
Format XMLOutFormat = new Format();
XMLOutFormat.setIndent(" ");
XMLOutFormat.setLineSeparator("\n");
outputter = new XMLOutputter(XMLOutFormat);
However, the compiler says "the constructor Format()" is not visible.
How do I instantiate a Format object then? Please advise.
Thanks.
Howard
> Hi all
>
> I am trying to ouput some XML. I read the XMLOutputter
> API
(http://www.jdom.org/docs/apidocs/org/jdom/output/XMLOutputter.html),
> and the contructor indicated that I can pass in a Format object.
>
> So, I try to do this
>
> Format XMLOutFormat = new Format();
First off, you don't want to use XMLOutFormat as variable name. Variable
names should not start with a capital letter, to avoid confusion. Class
names start with a capital.
> XMLOutFormat.setIndent(" ");
> XMLOutFormat.setLineSeparator("\n");
>
> outputter = new XMLOutputter(XMLOutFormat);
>
> However, the compiler says "the constructor Format()" is not visible.
> How do I instantiate a Format object then? Please advise.
>
> Thanks.
>
>
> Howard
>
Format does not have a public constructor, so you need one of the
"factory" methods getCompactFormat(), getPrettyFormat() or getRawFormat
().
For example:
Format format = Format.getRawFormat();
format.setIndent(" ");
format.setLineSeparator("\n");
XMLOutPutter xmlOut = new XMLOutPutter(format);
Note that the setIndent and setLineSeparator return a Format object as
well, so you can use the compact notation:
Format.getRawFormat().setIndent(" ").setLineSeparator("\n");
Howard