import java.io.FileInputStream;
import java.io.IOException;
import java.util.Iterator;
import java.util.List;
import org.jdom.Document;
import org.jdom.Element;
import org.jdom.JDOMException;
import org.jdom.input.SAXBuilder;
import org.jdom.xpath.XPath;
public class XMLReader {
private static final String CONFIG_FILE_NAME = "testSuits.xml";
private Element rootElt;
public XMLReader() {
SAXBuilder sb = new SAXBuilder();
try {
//Document doc = sb.build(Thread.currentThread().getContextClassLoader().getResourceAsStream(CONFIG_FILE_NAME));
Document doc = sb.build(new FileInputStream("F:/report/testSuits.xml"));
//取得<sys-configure>
rootElt = doc.getRootElement(); //相当拿到了整个文件一样,都在rootElt中
} catch (Exception e) {
e.printStackTrace();
}
}
public void readXmlInfo() throws Exception {
List yongList = XPath.selectNodes(rootElt, "//sys-configures/sys-configure");
for (Iterator iter = yongList.iterator(); iter.hasNext();) {
Element yongElt = (Element)iter.next();
String test = yongElt.getAttributeValue("test");
System.err.println(test);
String err = yongElt.getAttributeValue("err");
System.err.println(err);
String time = yongElt.getAttributeValue("time");
System.err.println(time);
}
}
public static void main(String[] args) throws Exception {
XMLReader reader = new XMLReader();
reader.readXmlInfo();
}
}