?? readxml.java~33~
字號:
package scout.database.util;
/**
* <p>Title: get the parameter of connecton database</p>
* <p>Description: abtain the parameter's values for connection a oracle9i database
* such as sid,account,password,etc..</p>
* <p>Copyright: Copyright (c) 2006</p>
* <p>Company: Chongqing Kemeida corporation</p>
* @author zengBo
* @version 1.0
*/
import java.io.*;
import org.jdom.*;
import java.util.*;
import org.jdom.output.*;
import org.jdom.input.*;
public class ReadXml {
private String xmlURL = "\\..\\sys_conf.xml";
/**
* constructor function
*/
public ReadXml() {
}
/**
* constructor function
* @param xmlURL,include the path and fileName of one xml
*/
public ReadXml(String xmlURL) {
this.xmlURL = xmlURL;
}
/**
* push some value in XML into VECTOR
* @return vector
* @throws Exception
*/
public Vector getVectorOfXml() throws Exception {
int childSize = 0;
Vector vector = new Vector();
ReadXml in = new ReadXml(xmlURL);
SAXBuilder sb = new SAXBuilder();
Document doc = sb.build(in.loadFile());
ProcessingInstruction pi = new ProcessingInstruction
("xml-stylesheet",
"href=\"bookList.html.xsl\" type=\"text/xsl\"");
doc.addContent(pi);
//get the root name
Element root = doc.getRootElement();
//get all children's elements of the root
java.util.List children = root.getChildren();
childSize = children.size();
for (int i = 0; i < childSize; i++) {
//get a child element
Element child = (Element) children.get(i);
//get the value of a child and save it in vector
vector.addElement(child.getTextTrim());
}
return vector;
}
/**
* get the file of xml,and return the InputStream of the xml
* @return InputStream
*/
public InputStream loadFile() {
Object object = null;
try {
object = getClass().getResourceAsStream(this.xmlURL);
System.out.println(this.xmlURL);
} catch (Exception e) {
System.out.println("the file of xml is not found");
}
return (InputStream) object;
}
/**
* the main function for testing
* @param args
* @throws Exception
*/
public static void main(String args[]) throws Exception {
ReadXml ne = new ReadXml();
System.out.print(ne.loadFile());/*
Vector vv = new Vector();
vv = ne.getVectorOfXml();
for (int i = 0; i < vv.size(); i++) {
System.out.println(vv.elementAt(i));
}*/
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -