Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

constructor is invisible? - jdom - format class

0 views
Skip to first unread message

mdx

unread,
Nov 13, 2005, 4:00:37 PM11/13/05
to
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();
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

zero

unread,
Nov 13, 2005, 4:19:42 PM11/13/05
to
mdx <j8s...@gmail.com> wrote in news:OPNdf.233$KP5.41061
@news20.bellglobal.com:

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

mdx

unread,
Nov 13, 2005, 4:27:08 PM11/13/05
to
appreciate the help!..


Howard

0 new messages