xml学习

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();
 }

}

 

 

 

你可能感兴趣的:(apache,xml)