⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 readxml.java~32~

📁 野生动物系统的JAVA源码, 野生动物系统的JAVA源码
💻 JAVA~32~
字号:
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 + -