<%--List8_12_1.jsp--%>
<%@ page import="org.w3c.tidy.Tidy,
                 java.io.*,
                 java.net.URL,
                 java.util.Properties,
                 org.w3c.tidy.Configuration"%>
<%@ page contentType="text/html;charset=GB2312" language="java" %>
<html>
  <head><title>将HTML文件转换成XML文件</title></head>
  <body>
  <%

      FileInputStream src;
      FileOutputStream dest;
      Properties pros = new Properties();
      pros.setProperty("tidy-mark", "yes");
      pros.setProperty("output-xml", "yes");
      pros.setProperty("uppercase-tags", "yes");
      pros.setProperty("char-encoding", "raw");
      pros.setProperty("makeclean", "yes");
      pros.setProperty("show-warnings", "no");
      pros.setProperty("drop-font-tags", "yes");
      pros.setProperty("clean", "yes");
      pros.setProperty("quiet", "yes");
      pros.setProperty("enclose-text", "yes");
      pros.setProperty("enclose-block-text", "yes");
      Tidy tidy = new Tidy();
     // tidy.setCharEncoding();

      //设置输出格式
      tidy.setConfigurationFromProps(pros);

      //设置错误消息的输出文件
      tidy.setErrout(new PrintWriter(new FileWriter(pageContext.getServletContext().getRealPath("8_12_error.txt")), true));
      //设置输出XML处理指令
      tidy.setXmlPi(true);
      tidy.setXmlPIs(true);
      //设置自动缩进
      tidy.setSmartIndent(true);

      //创建输入输出流
      src = new FileInputStream(pageContext.getServletContext().getRealPath("student.html"));
      dest = new FileOutputStream(pageContext.getServletContext().getRealPath("out.xml"));

      //执行转换
      tidy.parse(src, dest);

      //关闭流
      src.close();
      dest.close();
  %>
  </body>
</html>