java读取XML文件里面的数据之DOM实现
import org.w3c.dom.*;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import java.io.*;
public class ReadXML {
private File file;
public ReadXML(String filename){
File file=new File(filename);
this.file=file;
}
/**
*
* @return the instance of Document
*/
public Document getDOM(){
DocumentBuilderFactory dbf=DocumentBuilderFactory.newInstance();
DocumentBuilder db;
Document document=null;
try{
db=dbf.newDocumentBuilder();
document=db.parse(file);
}catch(Exception e ){
e.printStackTrace();
}
return document;
}
/**
*
* @param tagName
* @return
*/
public String getInfoByTagName(String tagName)
{
String info="";
Document document=this.getDOM();
//获取NodeName 为tagName的节点组
NodeList nl=document.getElementsByTagName(tagName);
for(int i=0;i<nl.getLength();i++)
{
info+=tagName+"[+"+i+"+]"+"\n";
Node node=nl.item(i);
//如果当前节点有子节点(这里 只考虑还有一级子节点的情况)
if(node.hasChildNodes())
{
NodeList list=node.getChildNodes();
for(int j=0;j<list.getLength();j++)
{
Node childNode=list.item(j);
/* 不加这个If语句会抛出
* Exception in thread "main" java.lang.NullPointerException
* at ReadXML.getInfoByTagName(ReadXML.java:59)
* at Test.main(Test.java:17)
*/
if(childNode.getFirstChild()!=null)
/* 对getNodeValue()的过程彻底无语
* 调试这个地方的时候,在网上很容易找到了
* 在得到Value的时候必须在节点对象后面先调用getFirstChild()或者getChildNodes().item(0)
* 原因很简单,但是不知道设计者问什么要这么设计
* 最近在看《Be
相关文档:
Hibernate、TopLink等OR Mapping操作数据库的技术都是建立JDBC技术之上的,实际来说,他们的性能和JDBC是有很大差距的,但反过来说,如果JDBC用不好,还不如 hibernate呢。暂且不说这些孰优孰劣的话了,再次主要是对Java的基础技术做个总结,以加深认识。
一、JDBC的基本原理
JDBC是Java操作数据库的技术规范。他实 ......
The Mean Opinion
Score (MOS) test is a well acccepted standard which is defined in the ITU-T
Rec.P.800.
The value of MOS
test is generated by letting large number of listeners to evaluate the quality
of the test sentences.
The test scores
are averaged to a mean score which range fro ......
学习Java程序主要包含以下四个部分。
(1)编辑代码 edit code
(2)保存代码 save code
(3)编译代码 compiler code
(4)运行程序 run program
第一个程序文件HelloWorld.java
public class HelloWorld {
public static void main(String[] args){
......
java泛型中的super关键字不太常用,也不太好理解,今天又从头看了看java的泛型机制,作一记录。
上界:
上界用extends关键字声明,表示参数化的类型可能是所指定的类型,或者是此类型的子类。如下面的代码:
Java代码
public void upperBound(List<? extends Date> list, Date& ......