以文本方式查看主题 - 中文XML论坛 - 专业的XML技术讨论区 (http://bbs.xml.org.cn/index.asp) -- 『 DOM/SAX/XPath 』 (http://bbs.xml.org.cn/list.asp?boardid=11) ---- 各位请帮忙,JDOM的问题 (http://bbs.xml.org.cn/dispbbs.asp?boardid=11&rootid=&id=16236) |
-- 作者:ldb621 -- 发布时间:3/30/2005 10:56:00 AM -- 各位请帮忙,JDOM的问题 程序如下: import java.io.*; import java.lang.*; import org.jdom.*; import org.jdom.output.*; import org.jdom.input.*; { 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(format);//在元素后换行,每一层元素缩排四格 XMLOut.output(doc, new FileOutputStream("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!"); }
} javac时不出错, |
-- 作者:菜籽 -- 发布时间:3/30/2005 11:19:00 AM -- jdom 包引进了么? 为什么不用集成开发工具,那样会简单一些 eclipse jbuilder |
-- 作者:xique -- 发布时间:4/12/2005 3:49:00 PM -- Format对象的原因 |
-- 作者:xiaoyun5109 -- 发布时间:4/14/2005 4:06:00 PM -- 我用eclipse运行了你写的程序,没问题的啊,唯一只是你引入的org.jdom.input.*;没用上 我用的是jdom1.0 是不是你的环境变量里面设置的classpath中的?:\jdom-1.0\lib\xerces.jar;设在其他的jdom lib后面了啊,这样可能就会出你那样的错 我也是看网上有人这么说的哦 |
W 3 C h i n a ( since 2003 ) 旗 下 站 点 苏ICP备05006046号《全国人大常委会关于维护互联网安全的决定》《计算机信息网络国际联网安全保护管理办法》 |
46.875ms |