今天上司让用struts做个东西,查询某张表的全部数据,以xml的形式,返回全部数据,请问这是什么意思?我以前只是使用xml文件用来配置什么的这个方法就是写了一个xml文件,但如何将xml文件设置进去?
public void BuildXML() throws Exception { Element root, student, number, name, age; root = new Element("student-info"); // 生成根元素:student-info student = new Element("student"); // 生成元素:student(number,name,age) number = new Element("number"); name = new Element("name"); age = new Element("age"); Document doc = new Document(root); // 将根元素植入文档doc中 number.setText("001"); name.setText("zhang"); age.setText("24");

student.addContent(name); // 先add的name,那么在XML文件中<name></name>出现在前面 student.addContent(number);

student.addContent(age); root.addContent(student); Format format = Format.getCompactFormat(); format.setEncoding("UTF-8"); // 设置xml文件的字符为gb2312 format.setIndent(" "); // 设置xml文件的缩进为4个空格 XMLOutputter XMLOut = new XMLOutputter(format);// 元素后换行一层元素缩四格 XMLOut.output(doc, new FileOutputStream("c:\\studentinfo.xml")); }