constructor is invisible? - jdom - format class

M

mdx

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
 
Z

zero

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

mdx

appreciate the help!..


Howard
@news20.bellglobal.com:




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.




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

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,994
Messages
2,570,223
Members
46,810
Latest member
Kassie0918

Latest Threads

Top