| 
| 在DOM4J中使用XPath |  
| Zergling 原创  (参与分:48,专家分:80)   发表:2003-7-21 下午4:49   更新:2003-7-22 上午8:34   版本:1.0   阅读:2623次 |  | 
| 
| import java.util.Iterator;
 import java.util.List;
 
 import org.dom4j.Attribute;
 import org.dom4j.Document;
 import org.dom4j.DocumentException;
 import org.dom4j.io.SAXReader;
 
 /**
 * @author
 * <a href="mailto:jdcyang@yahoo.com.cn">刘洋</a>
 * 2003-7-21 16:18:27
 */
 public class Example4 {
 
 public static void main(String[] args) {
 Example4 example4 = new Example4();
 SAXReader reader = new SAXReader();
 Document document;
 try {
 document = reader.read("address1.xml");
 example4.query(document);
 } catch (DocumentException e) {
 // TODO Auto-generated catch block
 e.printStackTrace();
 }
 }
 public void query(Document document){
 List list = document.selectNodes( "//phone/@type" );
 for (Iterator iter = list.iterator(); iter.hasNext(); ) {
 Attribute attribute = (Attribute) iter.next();
 String type = attribute.getValue();
 System.out.println(type);
 }
 
 }
 }
 
 
 
 |  
 | 
| 
 
| 
| 评论人:JFML    参与分: 616    专家分: 530    来自: 杭州 
 | 发表时间: 2003-7-22 上午9:25 |  
| Dom4J方便易用得多 
 只是不是W3C标准的接口
 
 显得有点“独”了
 |  |  
 
| 
| 评论人:javamonkey    参与分: 527    专家分: 540    来自: 北京海淀区三里河 
 | 发表时间: 2003-7-22 下午4:35 |  
| jdom现在也支持这样的功能 不知道俩者谁好用些?标准性更好些
 |  |  
 
| 
| 评论人:JFML    参与分: 616    专家分: 530    来自: 杭州 
 | 发表时间: 2003-7-23 上午9:10 |  
| JDOM更新的太慢了 
 功能上也不如Dom4J强大
 
 尽管遵守W3C标准
 |  |  
 |