用dom4j解析xml文件写入记事本时,解决换行问题

import org.dom4j.*;
import org.dom4j.io.*;
import java.io.*;
public class xmlAnalyze {
 
 
 public static void main(String[] args)
 {
  Document dc = DocumentHelper.createDocument();
  Element root = dc.addElement("students");

  String studentName[] = {"lzh","zj","a","b","c"};
  for ( int i = 1 ; i < 6 ; i ++ )
  {
     Element student = root.addElement("student");
     student.addAttribute("sn", Integer.toString(i));
     Element name = student.addElement("name");
     name.setText(studentName[i-1] );

  }
  try
  {
  
    OutputFormat   format  = new OutputFormat("  ",true);
    format.setLineSeparator("/n/r");
       XMLWriter xmlWriter = new XMLWriter(new FileOutputStream("C://students.xml"),format);
       xmlWriter.write(dc);
  }
  catch(Exception e)
  {
   System.out.println(e);
   
   
  }

你可能感兴趣的:(c,exception,xml,String,Class,import)