江湖救急 关于jdom
public static void BuildXML()
throws Exception
{
Element root,rbif,rinm,ricd,rpdt,cttn,catis,cati,
ctif,ctnm,citp,ctid,csnm,ctnt,htdt,htcrs,htcr,crcd,ttnm,tsdts,tsdt,rini
,finn,firc,rltp,fict,finc,catp,ctac,tbif,tbnm,tbit,tbid,tbnt,tsif,tstm,
ticd,tstp,tsct,tsdr,tdrc,trcd,crpp,crtp,crat,tcif,cfin,cfct,cfic,tcnm,tcit,
tcid,tcat,tcac;
root = new Element( "HVTR "); //生成根元素:HVTR
rbif = new Element( "RBIF "); //生成元素:RBIF,该元素中将包含元素rinm,ricd,rpdt,cttn
rinm = new Element( "RINM ");
ricd = new Element( "RICD ");
rpdt = new Element( "RPDT ");
cttn = new Element( "CTTN ");
catis=new Element( "CATIs ");//生成元素:CATIS,该元素中将包含元素CATI
cati=new Element( "CATI ");//生成元素:CATI,该元素中将包含元素CTIF
ctif=new Element( "CTIF ");//生成元素:CTIF,该元素中将包含元素CTNM,CTIP,CTID,CSNM,CTNT
ctnm=new Element( "CTNM ");
citp=new Element( "CITP ");
ctid=new Element( "CTID ");
csnm=new Element( "CSNM ");
ctnt=new Element( "CTNT ");
htdt=new Element( "HTDT ");
htcrs=new Element( "HTCRS ");
htcr=new Element( "HTCR ");
crcd=new Element( "CRCD ");
ttnm=new Element( "TTNM ");
tsdts=new Element( "TSDTS ");
tsdt=new Element( "TSDT ");
rini=new Element( "RINI ");
finn=new Element( "FINN ");
firc=new Element( "FIRC ");
rltp=new Element( "RLTP ");
fict=new Element( "FICT ");
finc=new Element( "FINC ");
catp=new Element( "CATP ");
ctac=new Element( "CTAC ");
tbif=new Element( "TBIF ");
tbnm=new Element( "TBNM ");
tbit=new Element( "TBIT ");
tbid=new Element( "TBID ");
tbnt=new Element( "TBNT ");
tsif=new Element( "TSIF ");
tstm=new Element( "TSTM ");
ticd=new Element( "TICD ");
tstp=new Element( "TSTP ");
tsct=new Element( "TSCT ");
tsdr=new Element( "TSDR ");
tdrc=new Element( "TDRC ");
trcd=new Element( "TRCD ");
crpp=new Element( "CRPP ");
crtp=new Element( "CRTP ");
crat=new Element( "CRAT ");
tcif=new Element( "TCIF ");
cfin=new Element( "CFIN ");
cfct=new Element( "CFCT ");
cfic=new Element( "CFIC ");
tcnm=new Element( "TCNM ");
tcit=new Element( "TCIT ");
tcid=new Element( "TCID ");
tcat=new Element( "TCAT ");
tcac=new Element( "TCAC ");
Document doc = new Document(root); //将根元素植入文档doc中
rinm.setText( " ");
ricd.setText( " ");
rpdt.setText( " ");
cttn.setText( " ");
rbif.addContent(rinm);
rbif.addContent(ricd);
rbif.addContent(rpdt);
rbif.addContent(cttn);
root.addContent(rbif);
ctnm.setText( " ");
citp.setText( " ");
ctid.setText( " ");
csnm.setText( " ");
ctnt.setText( " ");
ctif.addContent(ctnm);
ctif.addContent(citp);
ctif.addContent(ctid);
ctif.addContent(csnm);
ctif.addContent(ctnt);
cati.addContent(ctif);
htdt.setText( " ");
cati.addContent(htdt);
crcd.setText( " ");
ttnm.setText( " ");
htcr.addContent(crcd);
htcr.addContent(ttnm);
finn.setText( " ");
firc.setText( " ");
rltp.setText( " ");
fict.setText( " ");
finc.setText( " ");
catp.setText( " ");
ctac.setText( " ");
rini.addContent(finn);
rini.addContent(firc);
rini.addContent(rltp);
rini.addContent(fict);
rini.addContent(finc);
rini.addContent(catp);
rini.addContent(ctac);
tsdt.addContent(rini);
tbnm.setText( " ");
tbit.setText( " ");
tbid.setText( " ");
tbnt.setText( " ");
tbif.addContent(tbnm);
tbif.addContent(tbit);
tbif.addContent(tbid);
tbif.addContent(tbnt);
tsdt.addContent(tbif);
tstm.setText( " ");
ticd.setText( " ");
tstp.setText( " ");
tsct.setText( " ");
tsdr.setText( " ");
tdrc.setText( " ");
trcd.setText( " ");
crpp.setText( " ");
crtp.setText( " ");
crat.setText( " ");
tsif.addContent(tstm);
tsif.addContent(ticd);
tsif.addContent(tstp);
tsif.addContent(tsct);
tsif.addContent(tsdr);
tsif.addContent(tdrc);
tsif.addContent(trcd);
tsif.addContent(crpp);
tsif.addContent(crtp);
tsif.addContent(crat);
tsdt.addContent(tsif);
cfin.setText( " ");
cfct.setText( " ");
cfic.setText( " ");
tcnm.setText( " ");
tcit.setText( " ");
tcid.setText( " ");
tcat.setText( " ");
tcac.setText( " ");
tcif.addContent(cfin);
tcif.addContent(cfct);
tcif.addContent(cfic);
tcif.addContent(tcnm);
tcif.addContent(tcit);
tcif.addContent(tcid);
tcif.addContent(tcat);
tcif.addContent(tcac);
tsdt.addContent(tcif);
tsdts.addContent(tsdt);
htcr.addContent(tsdts);
htcrs.addContent(htcr);
cati.addContent(htcrs);
catis.addContent(cati);
root.addContent(catis);
Format format = Format.getCompactFormat();
format.setEncoding( "gb2312 "); //设置xml文件的字符为gb2312 format.setIndent( " "); //设置xml文件的缩进为4个空格
XMLOutputter XMLOut = new XMLOutputter(format);//在元素后换行,每一层元素缩排四格
XMLOut.output(doc, new FileOutputStream( "studentinfo.xml "));
}
小弟写了这样一个函数 问题出在这个地方
Format format = Format.getCompactFormat();
format.setEncoding( "gb2312 "); //设置xml文件的字符为gb2312 format.setIndent( " "); //设置xml文件的缩进为4个空格
XMLOutputter XMLOut = new XMLOutputter(format);//在元素后换行,每一层元素缩排四格
说找不到 Format 请各位大大指点 在线等啊
[解决办法]
jdom1.0修改了XMLOutputter()方法,它的参数写到一个格式类Format里了:如下
Format format = Format.getPrettyFormat();
format.setEncoding(encoding);
format.setLineSeparator( "\r\n ");
XMLOutputter outputter = new XMLOutputter(format);
//对比以前的是实例化XMLOutputter时用参数值或变量传入
建议参照下jdom文档,很详细的