当前位置: 技术问答>java相关
JDOM或DOM高手请进,关于生成XML的问题
来源: 互联网 发布时间:2015-10-31
本文导语: (1) 请问一面的程序 String inFile = "c:\testin.xml"; String outFile = "c:\testout.xml"; try { //code to parse an existed XML file goes here... SAXBuilder builder = new org.jdom.input.SAXBuilder(); ...
(1)
请问一面的程序
String inFile = "c:\testin.xml";
String outFile = "c:\testout.xml";
try
{
//code to parse an existed XML file goes here...
SAXBuilder builder = new org.jdom.input.SAXBuilder();
Document doc = builder.build(inFile);
//code to save goes here...
FileWriter writer = new FileWriter(outFile);
XMLOutputter outputter =
new XMLOutputter(" ", true, "GB2312");
outputter.output(doc, writer);
writer.close();
}
catch (Exception e)
{
System.out.println (e.getMessage());
}
为何先要打开一个IN,再OUT呢,
我要是不打开这个IN,直接OUT可不可以??
(2)
怎么用JDOM直接生成下面的XML???xml version="1.0" encoding="UTF-8"?>
000001
wang
124
abc
000002
wanggang
beijing
suoliao
请问一面的程序
String inFile = "c:\testin.xml";
String outFile = "c:\testout.xml";
try
{
//code to parse an existed XML file goes here...
SAXBuilder builder = new org.jdom.input.SAXBuilder();
Document doc = builder.build(inFile);
//code to save goes here...
FileWriter writer = new FileWriter(outFile);
XMLOutputter outputter =
new XMLOutputter(" ", true, "GB2312");
outputter.output(doc, writer);
writer.close();
}
catch (Exception e)
{
System.out.println (e.getMessage());
}
为何先要打开一个IN,再OUT呢,
我要是不打开这个IN,直接OUT可不可以??
(2)
怎么用JDOM直接生成下面的XML???xml version="1.0" encoding="UTF-8"?>
000001
wang
124
abc
000002
wanggang
beijing
suoliao
|
jianhu ()我最近正在用JDOM并且有你所提问问题的源代码可以提供,给邮箱地址发给你。
|
1)你不读取infile,哪里有东西写到outfile里?
2)www.jdom.org把jdom.jar里的examples打开看看不就清楚了
2)www.jdom.org把jdom.jar里的examples打开看看不就清楚了
|
1)你不读取infile,哪里有东西写到outfile里?
2)www.jdom.org把jdom.jar里的examples打开看看不就清楚了
2)www.jdom.org把jdom.jar里的examples打开看看不就清楚了