xml学习
关键字: j2ee学习xml
dtd:document type define;
sax: simple api fox xml;
dom: document object modal ; 文档对象模型
//
xml文件的element 对象
documentBuilderFactory docBuilderFactory=DocumentBuilderFactory.newInstance();
DocumentBuilder docBuilder=docBuilderFactory.newDocumentBuilder ();
doc=docBuilder.parse(new File(argv[0]));
elementObj=doc.getDocumentElement();
简单的实现,生成一个xml文件。
-------------------------
package test.Xml;
import org.apache.crimson.tree.ElementNode;
import org.apache.crimson.tree.XmlDocument;
import java.io.*;
/**
*
* @author zf
*/
public class XmlExample {
public static void main(String args[]) throws IOException
{
XmlDocument xmldoc=new XmlDocument();
ElementNode name=(ElementNode) xmldoc.createElement("name");
ElementNode first=(ElementNode) xmldoc.createElement("first");
ElementNode last=(ElementNode) xmldoc.createElement("last");
Writer out=new OutputStreamWriter(System.out);
FileOutputStream filout=new FileOutputStream("Build.xm");
xmldoc.appendChild(name);
name.appendChild(first);
first.appendChild(xmldoc.createTextNode("zfigl"));
name.appendChild(last);
last.appendChild(xmldoc.createTextNode("zfig2"));
name.setAttribute("city", "beijing");
xmldoc.write(out);
xmldoc.write(filout);
out.write("\n");
out.flush();
}
}
发表评论
- 浏览: 4040 次
- 性别:

- 来自: 重庆

- 详细资料
搜索本博客
最近加入圈子
最新评论
-
system.exit(int n)
学习的过程就是痛并快乐着! 共勉!
-- by wdlfellow -
list set map 学习
说的太简单了 其实还有很多的内容 要讲
-- by laowood -
07年奋斗的一年
努力,时间过的太快了。
-- by ouspec -
郁闷的一天
,问题全部搞定,我要好好学习啦!哈哈,高兴的一天
-- by zfigo_000






评论排行榜