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

📄 xmldictnumconuterwithdom.java

📁 使用OSGi框架开发的分布式电子辞典
💻 JAVA
字号:
/* * @(#)XmlDictNumConuterWithDOM.java *  * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 3 of the License, or * (at your option) any later version. *  * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the * GNU Library General Public License for more details. * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */package ynu.edu.cn.sei.stoneagedict.util;import java.io.File;import java.io.IOException;import java.util.ArrayList;import java.util.logging.Level;import java.util.logging.Logger;import javax.xml.parsers.DocumentBuilder;import javax.xml.parsers.DocumentBuilderFactory;import javax.xml.parsers.ParserConfigurationException;import org.w3c.dom.Document;import org.w3c.dom.Element;import org.w3c.dom.Node;import org.w3c.dom.NodeList;import org.w3c.dom.Text;import org.xml.sax.SAXException;/** * 统计xml词库文件里的单词量. * @author zy * @version 1.0.0.0, Mar 18, 2008 */public class XmlDictNumConuterWithDOM {        private static Document doc = null;    private static ArrayList<String> content = new ArrayList<String>();    private static int icounter = 0;    /**     * @param args the command line arguments     */    public static void main(String[] args) {        DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();        DocumentBuilder builder = null;        try {             builder = factory.newDocumentBuilder();        } catch (ParserConfigurationException ex) {            Logger.getLogger(XmlDictNumConuterWithDOM.class.getName()).log(Level.SEVERE, null, ex);        }        File file = new File("E:\\xdxf.xml");        try {            doc = builder.parse(file);        } catch (SAXException ex) {            Logger.getLogger(XmlDictNumConuterWithDOM.class.getName()).log(Level.SEVERE, null, ex);        } catch (IOException ex) {            Logger.getLogger(XmlDictNumConuterWithDOM.class.getName()).log(Level.SEVERE, null, ex);        }        showTitles(doc.getDocumentElement());        System.out.println("日语单词有: " + icounter + "个");    }            private static void showTitles(Node e) {        NodeList kids = e.getChildNodes();        for (int i = 0; i < kids.getLength(); i++) {            Node child = kids.item(i);            if (child instanceof Element) {                Element childElement = (Element) child;                if (childElement.getTagName().equals("ar")) {                    icounter++;                }            }            showTitles(child);        }    }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -