现在的位置: 首页 > 综合 > 正文

jdom 操作类

2013年08月03日 ⁄ 综合 ⁄ 共 1197字 ⁄ 字号 评论关闭

 import java.io.IOException;

import org.jdom.input.*;
import org.jdom.output.*;
import org.jdom.*;
import org.jdom.xpath.*;
import java.io.*;

import java.util.*;
import com.test.bean.RSS;
import com.test.bean.RssItem;

public class Test {
   
 Document doc=null;

 public Test()
 {
  try {
     } catch (JDOMException e) {
   // TODO Auto-generated catch block
   e.printStackTrace();
  } catch (IOException e) {
   // TODO Auto-generated catch block
   e.printStackTrace();
  }
 }
 
 public  void load(String url) throws JDOMException, IOException
 {
  doc= new org.jdom.input.SAXBuilder().build(url);
 }
 
 public void load(InputStream in) throws Exception
 {
  doc=new org.jdom.input.SAXBuilder().build(in);
 }
 
 public List selectNodes(String xpathString)
 {
  List l=null;
  
  try {
   XPath xpath=XPath.newInstance(xpathString);
      l=xpath.selectNodes(doc);
  } catch (JDOMException e) {
   // TODO Auto-generated catch block
   e.printStackTrace();
  }
  catch(Exception ex)
  {
   System.out.println(ex.getMessage());
  }
  return l;
 }
 

 
 public Element selectSingleNode(String xpathString)
 {
  Element e1=null;
  try {
   XPath xpath=XPath.newInstance(xpathString);
      e1=(Element)xpath.selectSingleNode(doc);
  } catch (JDOMException e) {
   // TODO Auto-generated catch block
   e.printStackTrace();
  }
  return e1;
 }

抱歉!评论已关闭.