大家谁会用JAVA写,功能是:能够往Oracle中读写数据,并且能够转换成XML格式的,最好有完整的程序哈 20

 我来答
lxq_yz
2012-07-12 · TA获得超过116个赞
知道答主
回答量:82
采纳率:0%
帮助的人:41.7万
展开全部
public class TestDom4j {
public static void main(String[] args) throws Exception {
input();
}
public static void input() throws Exception {
SAXReader reader = new SAXReader();
Document doc = reader.read(new InputStreamReader(new FileInputStream(
"d:/students.xml")));
Element root = doc.getRootElement();
System.out.println(root.getName());
List<Element> list = root.elements();
for (int i = 0; i < list.size(); i++) {
Element e = list.get(i);
Element nameElement = (Element) e.elements("name").get(0);
Element ageElement = (Element) e.elements("age").get(0);
System.out.println(nameElement.getText() + "," + ageElement.getText());
}
// root.elements("student");
}
public static void output() throws Exception {
Document doc = DocumentHelper.createDocument();
Element root = doc.addElement("students");
for (int i = 0; i < 100; i++) {
Element s1 = root.addElement("student");
s1.addAttribute("id", "" + i);
Element name1 = s1.addElement("name");
Element age1 = s1.addElement("age");
name1.setText("name" + i);
age1.setText("25");
}
OutputFormat opf = OutputFormat.createPrettyPrint();
XMLWriter xmlWriter = new XMLWriter(new OutputStreamWriter(
new FileOutputStream("d:/students.xml")), opf);
xmlWriter.write(doc);
xmlWriter.close();
}
}
戴的天
2012-07-11 · TA获得超过108个赞
知道小有建树答主
回答量:142
采纳率:100%
帮助的人:81.2万
展开全部
简单的实现:用JDBC连接数据库,然后将数据库的数据读出,用dom4j或JDOM(学习比较简单,一般没有太大性能上的需求推荐用JDOM)将数据写到目标XML
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
xieqiuying0907
2012-07-25
知道答主
回答量:28
采纳率:0%
帮助的人:6.9万
展开全部
public class TestDom4j {
public static void main(String[] args) throws Exception {
input();
}
public static void input() throws Exception {
SAXReader reader = new SAXReader();
Document doc = reader.read(new InputStreamReader(new FileInputStream(
"d:/students.xml")));
Element root = doc.getRootElement();
System.out.println(root.getName());
List<Element> list = root.elements();
for (int i = 0; i < list.size(); i++) {
Element e = list.get(i);
Element nameElement = (Element) e.elements("name").get(0);
Element ageElement = (Element) e.elements("age").get(0);
System.out.println(nameElement.getText() + "," + ageElement.getText());
}
// root.elements("student");
}
public static void output() throws Exception {
Document doc = DocumentHelper.createDocument();
Element root = doc.addElement("students");
for (int i = 0; i < 100; i++) {
Element s1 = root.addElement("student");
s1.addAttribute("id", "" + i);
Element name1 = s1.addElement("name");
Element age1 = s1.addElement("age");
name1.setText("name" + i);
age1.setText("25");
}
OutputFormat opf = OutputFormat.createPrettyPrint();
XMLWriter xmlWriter = new XMLWriter(new OutputStreamWriter(
new FileOutputStream("d:/students.xml")), opf);
xmlWriter.write(doc);
xmlWriter.close();
}
}
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
收起 更多回答(1)
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式