以文本方式查看主题

-  中文XML论坛 - 专业的XML技术讨论区  (http://bbs.xml.org.cn/index.asp)
--  『 DOM/SAX/XPath 』  (http://bbs.xml.org.cn/list.asp?boardid=11)
----  求助:生成xml时format的使用出现错误  (http://bbs.xml.org.cn/dispbbs.asp?boardid=11&rootid=&id=25636)


--  作者:mouoce
--  发布时间:12/19/2005 11:24:00 AM

--  求助:生成xml时format的使用出现错误
import java.io.*;

import java.lang.*;

import org.jdom.*;

import org.jdom.output.*;

import org.jdom.input.*;

public class WriteXML

{

 public void BuildXML() throws Exception

 {

  Element root, student, number, name, age;

  root = new Element("student-info"); // 生成根元素:student-info

  student = new Element("student"); // 生成元素:student,该元素中将包含元素number,name,age

  number = new Element("number");

  name = new Element("name");

  age = new Element("age");

  Document doc = new Document(root); // 将根元素植入文档doc中

  number.setText("001");

  name.setText("lnman");

  age.setText("24");

  student.addContent(number);

  student.addContent(name);

  student.addContent(age);

  root.addContent(student);

//  Format format = Format.getCompactFormat();
//
//  format.setEncoding("gb2312"); // 设置xml文件的字符为gb2312
//
//  format.setIndent("    "); // 设置xml文件的缩进为4个空格

  XMLOutputter XMLOut = new XMLOutputter();// 在元素后换行,每一层元素缩排四格

  XMLOut.output(doc, new FileOutputStream("ks/c5/studentinfo.xml"));

 }

 public static void main(String[] args) throws Exception

 {

  WriteXML w = new WriteXML();

  System.out.println("Now we build an XML document .....");

  w.BuildXML();

  System.out.println("finished!");

 }

}
上面的代码中,
提示不能解决Format这个类型


W 3 C h i n a ( since 2003 ) 旗 下 站 点
苏ICP备05006046号《全国人大常委会关于维护互联网安全的决定》《计算机信息网络国际联网安全保护管理办法》
27.344ms