SAX的解吸模式和DOM不同,不是解吸者主动的,
而是被动的形式,实现你要根据XML文档结构设计好解吸器
然后顺序一次解吸完,解吸途中保存你要的信息至于子结点要用状态机来判断读取
而是被动的形式,实现你要根据XML文档结构设计好解吸器
然后顺序一次解吸完,解吸途中保存你要的信息至于子结点要用状态机来判断读取
解决方案 »
- 这样的错错误时什么原因造成的
- 关于for (i=0;i<10;i++){if(i%2==0)continue;
- java rxtx 串口通信问题
- 怎样自动生成学生学号??急急!!!!急
- 各位大哥哥救我了
- 打成war后发布怎样得到绝对路径?
- struts+tomcat启动时,不停的出现错,而且没有终止,不知道什么原因????
- 关于spring+Hibernate结构中DAO中调用getHibernateTemplate().save(vo);不commit的问题!
- 急急急 resin-ee-2.1.12 + oracle9i 死机----->>>
- 求struts的validation验证html非法字符和SQL非法字符的正则表达式
- 关于写XML
- 一个struts中关于<tiles/>标签的问题?谢谢各位给予解答!!
thanks, to Alain_Delone(阿龙) ,
能具体一些么?
import org.jdom.output.*;
import org.jdom.input.*;
import java.io.*;public class jdomtest{
public static void main(String args[])throws Exception{ SAXBuilder sb = new SAXBuilder(); //从文件构造一个Document,因为XML文件中已经指定了编码,所以这里不必了
Document doc = sb.build(new FileInputStream("exampleA.xml")); Element root = doc.getRootElement(); //得到根元素
java.util.List books = root.getChildren(); //得到根元素所有子元素的集合
Element book = (Element)books.get(0); //得到第一个book元素
Element author = book.getChild("author"); //得到指定的字元素
author.setText("mhj"); //将作者改为mhj
//或 Text t = new Text("王五");book.addContent(t);
Element price = book.getChild("price"); //得到指定的字元素 System.out.println(price.getText() );//得到值
//修改价格,比较郁闷的是我们必须自己转换数据类型,而这正是JAXB的优势
price.setText(Float.toString(50.0f)); String indent = "";
boolean newLines = false;
XMLOutputter outp = new XMLOutputter(indent,newLines,"GBK");
outp.output(doc, new FileOutputStream("exampleB.xml")); }
};<?xml version="1.0" encoding="GBK"?>
<bookList>
<book>
<name>Java编程入门</name>
<author>张三</author>
<publishDate>2002-6-6</publishDate>
<price>35.0</price>
</book>
<book>
<name>XML在Java中的应用</name>
<author>李四</author>
<publishDate>2002-9-16</publishDate>
<price>92.0</price>
</book>
</bookList>