原文:http://www.jdon.com/jive/thread.jsp?forum=16&thread=302
看下面比較:












使用Iterator返回:













































If your XML documents contain document data (e.g., Framemaker documents stored in XML format), then DOM is a completely natural fit for your solution. If you are creating some sort of document information management system, then you will probably have to deal with a lot of document data. An example of this is the Datachannel RIO product, which can index and organize information that comes from all kinds of document sources (like Word and Excel files). In this case, DOM is well suited to allow programs access to information stored in these documents.
However, if you are dealing mostly with structured data (the equivalent of serialized Java objects in XML) DOM is not the best choice. That is when SAX might be a better fit.
If the information stored in your XML documents is machine readable (and generated) data then SAX is the right API for giving your programs access to this information. Machine readable and generated data include things like:
So machine generated data is information that you normally have to create data structures and classes for in Java. A simple example is the address book which contains information about persons, as shown in Figure 1. This address book XML file is not like a word processor document, rather it is a document that contains pure data, which has been encoded into text using XML.
When your data is of this kind, you have to create your own data structures and classes (object models) anyway in order to manage, manipulate and persist this data. SAX allows you to quickly create a handler class which can create instances of your object models based on the data stored in your XML documents. An example is a SAX document handler that reads an XML document that contains my address book and creates an AddressBook class that can be used to access this information. The first SAX tutorial shows you how to do this. The address book XML document contains person elements, which contain name and email elements. My AddressBook object model contains the following classes:
So my "SAX address book document handler" is responsible for turning person elements into Person objects, and then storing them all in an AddressBook object. This document handler turns the name and email elements into String objects.
The SAX document handler you write does element to object mapping. If your information is structured in a way that makes it easy to create this mapping you should use the SAX API. On the other hand, if your data is much better represented as a tree then you should use DOM.
參考原文地址 http://homepage.mac.com/edahand/projects/java/example1.html
1 在E盤建立一個目錄sandh, 然后把那個空的struts-blank.war解壓到這下面作為struts模板,把hibernate3.1里面的jar文件拷貝到/sandh/web-inf/lib下面,ehcache.xml拷貝到/sand/web-inf/src/java下面。
2 在tomcat下配置datasource命名為jdbc/aix,然后建立一個新的context名字為sand,在sand下建一個新的資源連接jdbc/aix,作為hibernate.cfg.xml中hibernate.connection.datasouce引用值。
3 在sybase中新建一個表item
4 在/sandh/web-inf/src/java下面建立以下文件
log4j.properties
hibernate.cfg.xml
Item.hbm.xml
HibernateUtil.java
Item.java
AddItemAction.java
ItemService.java
在/sandh/web-inf/src下面新建build.xml文件,然后ant compile。
在/sandh/pages下新建AddItem.jsp文件
5 修改/sandh/web-inf/struts-config.xml文件,內容如下:
修改/sandh/web-inf/validation.xml文件,為addItemForm增加動態驗證,內容如下:
6 在tomcat下面測試一下吧。http://127.0.0.1:8080/sand
7 測試的時候發現2個問題:
首先,如果在/sandh/web-inf/classes下面沒有ehcache.xml這個文件,會報這個錯誤,No configuration found. Configuring ehcache from ehcache-failsafe.xml found in the classpath:.....這個文件是hibernate緩存配置文件,以后在學習。
另外在log文件中一直發現這個警告:Could not bind factory to JNDI javax.naming.NamingException: Context is read only..... 網上查找后發現只要在hibernate.cfg.xml文件的<session-factory name="java:/hibernate/HibernateFactory"> 中把name=....去掉就好了,否則會自動把name注冊進jndi中失敗而發出警告。
8 所有文件打包在這里 http://www.aygfsteel.com/Files/luckyrobbie/sandh.rar 里面lib下面的文件自己添進去吧。
昨天是星期天,早上我睡懶覺起床后貝貝和媽媽已經出去玩了,發現電腦桌上有幾顆魚皮花生米,那是我買給貝貝吃的椰子味的花生米。心想:是不是留給我吃的啊^^
中午在父母家吃飯,我問老婆,是不是貝貝特意留了給我的?老婆說,別美了,肯定是他放在桌子上忘記了。于是我問貝貝:是否留給爸爸吃的呀?貝貝答:是的。我繼續問:你當時是怎么想的啊?貝貝答:我當時想爸爸也喜歡吃的,于是留給你的。
呵呵,不管是真是假,心里美滋滋的。
晚上,貝貝拿著玩具手機打電話給老師,編了幾句后,我問他老師說什么了。他說:陸老師明天帶我到##飯店去吃飯的。
“帶爸爸去嗎?”
“不帶”
“帶媽媽去嗎?”
“不帶”
“那你一個人怎么過去呢?” 我問。
于是貝貝又打了一個電話,說“陸老師明天來接我去吃飯的”
對于上面的actionform的傳遞,本來以為一定要通過提交<html:form.../>才能接收的,后來發現其實通過參數的傳遞也可以實現。
例如上面的actionform, 如果有2個field, 分別是A和B, 如果不通過提交form的方法,直接用帶參數的連接表示, 那么通過這個做法也可以正確的用f.get(..)方法得到數值.?
http://localhost:8080/app/myaction.do?A=abc&B=def
由此可見,如果分別3個頁面page a, page b and page c. page a中有一個form, 提交后產生page b, 對page b中的鏈接提交后產生page c. 那么page b 和 page c 可以通過一個action來實現, 只要保證page b中關于action的連接后面加的參數名字和actionform的field名字一致就可以了。