格式化输出XML字符串

一、主要的类

 

public class OutputFormat

extends Object

implements Cloneable

 

OutputFormat represents the format configuration used by XMLWriter and its base classes to 

format the XML output

 

 

(1).public static OutputFormat createPrettyPrint()

A static helper method to create the default pretty printing format. This format consists of an 

indent of 2 spaces, newlines after each element and all other whitespace trimmed, and XMTML is 

false.

Returns:

DOCUMENT ME!

 

(2).createCompactFormat

public static OutputFormat createCompactFormat()

A static helper method to create the default compact format. This format does not have any 

indentation or newlines after an alement and all other whitespace trimmed

Returns:

DOCUMENT ME!

 

 

二、例子:

 

OutputFormat format=OutputFormat.createPrettyPrint();

format.setEncoding("UTF-8");

FileOutputStream fos=new FileOutputStream(new File(newFile));

XMLWriter writer=new XMLWriter(fos,format);

writer.write(document);

writer.close();

fos.close();

你可能感兴趣的:(xml)