一个目录下面有许多的子目录,每个子目录下有一个html文件和一个和html文件关联的pdf文件,我想用java编个程序把所有的.html格式文件检索出来并且应用jtidy转换为xml格式的,再使用jdom解析xml文件(除去无用的冗余的显示信息)只需要得到里面的有用信息,生成另外一个标准的xml文件,把最后得到的xml和原来的pdf文件批量放到oracle数据库中,请问高手
1.如果可能的话程序应该如何编写?(给出分步代码也可)
2.如何解决使用jtidy转换成xml文件的中文字符问题?
3.解析xml文件使用jdom恰不恰当,如何使用?
4.最后的xml文件和pdf文件怎么一起入库?
拜托,多谢!
1.如果可能的话程序应该如何编写?(给出分步代码也可)
2.如何解决使用jtidy转换成xml文件的中文字符问题?
3.解析xml文件使用jdom恰不恰当,如何使用?
4.最后的xml文件和pdf文件怎么一起入库?
拜托,多谢!
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
public class Text { public static void main(String[] args) {
getFile(new File("src"));
} private static void getFile(File file) {
if (file.isFile()){
String fileName = file.getName();
if (fileName.indexOf("java") != -1){
try {
StringBuffer sb = new StringBuffer();
FileInputStream fis = new FileInputStream(file);
byte[] b = new byte[8192];
while (fis.read(b) != -1){
sb.append(new String(b));
}
System.out.println(file.getName());
System.out.println(sb.toString().trim());
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
} else if (file.isDirectory()){
File[] files = file.listFiles();
for (int i = 0; i < files.length; i++) {
getFile(files[i]);
}
}
}
}
回Neil_Dang(C∞l Dog):谢谢你的代码,对我很有帮助,不过还有一个问题,你知道我需要批量转换怎么可以把html转换后的文件自动生成以xml为后缀的的xml文件?
<?xml version="1.0" encoding="utf-8"?>
<html>
<body>
<table>
<tr>
<td>姓 名:</td>
<td>张三</td>
</tr>
<tr>
<td>年 龄:</td>
<td>20</td>
</tr>
</table>
</body>
</html>
怎么能转换成
<?xml version="1.0" encoding="utf-8"?>
<介绍>
<姓名>张三</姓名>
<年龄>20</年龄>
</介绍>
只需要把“张三”和“20”从原来的xml文件中提取出来就好了
<body>
<table>
<table>
<tr>
a
</tr>
<tr>
</tr>
<tr>
<td>
b
</td>
</tr>
</table>
<table>
</body>
<body>
</br>
</body>
和
<body>
</body>
我认为这两个网页格式不同,你是否认为他们是相同的呢?只要有一个标签的位置或者类型不同就算格式不同。