日期:2014-05-18  浏览次数:20638 次

jdom操作xml文件出现很多奇怪的回车符?
方法如下:
public   static   void   AddXML(DeptVO   vo)   throws   Exception   {
                FileInputStream   fi   =   null;
                FileOutputStream   fo   =   null;
                try   {
                        String   path   =   "1.xml ";
                        fi   =   new   FileInputStream(path);
                        SAXBuilder   sb   =   new   SAXBuilder();//建立构造器
                        Document   doc   =   sb.build(fi);
                        Element   root   =   doc.getRootElement();//得到根元素
                        List   roots   =   root.getChildren();//得到根元素所有子元素的集合

                        int   deptno   =   vo.getDeptno();
                        String   dname   =   vo.getDname();
                        String   loc   =   vo.getLoc();

                        Element   newroot   =   new   Element( "dept ");

                        Element   newdeptno   =   new   Element( "deptno ");
                        newdeptno.setText(Integer.toString(deptno));
                        newroot.addContent(newdeptno);

                        Element   newdname   =   new   Element( "dname ");
                        newdname.setText(dname);
                        newroot.addContent(newdname);

                        Element   newloc   =   new   Element( "loc ");
                        newloc.setText(loc);
                        newroot.addContent(newloc);

                        roots.add(newroot);//增加子元素

                        String   indent   =   "   ";
                        boolean   newLines   =   true;
              &n