使用如下代码:
OutputStream os = new FileOutputStream( "nosferatu.xml" );
m.marshal( element, os );
生成的xml文件是一串东西,不像标准xml文件中有换行和缩进。请问如何解决啊?
OutputStream os = new FileOutputStream( "nosferatu.xml" );
m.marshal( element, os );
生成的xml文件是一串东西,不像标准xml文件中有换行和缩进。请问如何解决啊?
嗯,是的。帮助文档里是这么描述的:
假定以下安装代码适用于下列所有代码片段: JAXBContext jc = JAXBContext.newInstance( "com.acme.foo" );
Unmarshaller u = jc.createUnmarshaller();
Object element = u.unmarshal( new File( "foo.xml" ) );
Marshaller m = jc.createMarshaller();
编组到 File 中: OutputStream os = new FileOutputStream( "nosferatu.xml" );
m.marshal( element, os );是呀,有个xml文件我修改了后要生成一个新的文件,要给人看的。