import java.io.*;
import javax.xml.parsers.*;
import org.w3c.dom.*;
import java.sql.*;
import org.apache.crimson.tree.*;public class WriterXml { public static void ha() {
System.out.println("ahahahhaha");
}
public static void main(String[] args) {
Document doc = null;
Element students;
Element stud;
Element fName;
Element sName;
try {
DocumentBuilderFactory dFactory = DocumentBuilderFactory.newInstance();
DocumentBuilder dBuilder = dFactory.newDocumentBuilder();
doc = dBuilder.newDocument(); stud = doc.createElement("Student");
fName = doc.createElement("FirstName");
fName.appendChild(doc.createTextNode("Chen"));
stud.appendChild(fName);
sName = doc.createElement("Surname");
sName.appendChild(doc.createTextNode("Liancong"));
stud.appendChild(sName);
students = doc.createElement("Students");
students.setAttribute("Department","Mathematics"); students.appendChild(stud);
doc.appendChild(students);
//((XmlDocument)doc).write(System.out);
((XmlDocument)doc).write(new FileOutputStream("d:\\a.txt"));
}catch(Exception e) {
e.printStackTrace();
}
}
}
import javax.xml.parsers.*;
import org.w3c.dom.*;
import java.sql.*;
import org.apache.crimson.tree.*;public class WriterXml { public static void ha() {
System.out.println("ahahahhaha");
}
public static void main(String[] args) {
Document doc = null;
Element students;
Element stud;
Element fName;
Element sName;
try {
DocumentBuilderFactory dFactory = DocumentBuilderFactory.newInstance();
DocumentBuilder dBuilder = dFactory.newDocumentBuilder();
doc = dBuilder.newDocument(); stud = doc.createElement("Student");
fName = doc.createElement("FirstName");
fName.appendChild(doc.createTextNode("Chen"));
stud.appendChild(fName);
sName = doc.createElement("Surname");
sName.appendChild(doc.createTextNode("Liancong"));
stud.appendChild(sName);
students = doc.createElement("Students");
students.setAttribute("Department","Mathematics"); students.appendChild(stud);
doc.appendChild(students);
//((XmlDocument)doc).write(System.out);
((XmlDocument)doc).write(new FileOutputStream("d:\\a.txt"));
}catch(Exception e) {
e.printStackTrace();
}
}
}
解决方案 »
- 求解 如下函数执行过程
- 什么时候用抽象类?请举例说明
- 如何阅读理解JAVA API文档呢?
- ArrayList<String[]>如何导出为String[][]?
- 关于TextField.........
- JAVA开发环境的问题
- 安装Apache的问题,急急急急!!!
- 低价转让SCJP考试券!!!!!!
- 怎样把一副图片拉伸显示在一个控件中?
- 请问class,abstract class,interface的区别和联系.
- 请问大家:这个程序只有几行,书上抄的,编译出错,问题在哪?
- (100分)求助!使用SERVLET接收XML文件流信息,十万火急,请求帮助,还在线蹲着一天。今天结贴,进来的也有分混。
import org.dom4j.Document;
import org.dom4j.DocumentHelper;
import org.dom4j.Element;public class Foo { public Document createDocument() {
Document document = DocumentHelper.createDocument();
Element root = document.addElement( "root" ); Element author1 = root.addElement( "author" )
.addAttribute( "name", "James" )
.addAttribute( "location", "UK" )
.addText( "James Strachan" );
Element author2 = root.addElement( "author" )
.addAttribute( "name", "Bob" )
.addAttribute( "location", "US" )
.addText( "Bob McWhirter" ); return document;
}
}