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
相关文档:
create PROCEDURE pagelist
@tablename nvarchar(50),
@fieldname nvarchar(50)='*',
@pagesize int output,--每页显示记录条数
@currentpage int output,--第几页
@orderid nvarchar(50),--主键排序
@sort int,--排序方式,1表示升序,0表示降序排列
......
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 ......
1:应用程序不再需要使用 Class.forName() 显式地加载 JDBC 驱动程序。当前使用 Class.forName() 加载 JDBC 驱动程序的现有程序将在不作修改的情况下继续工作。
2:需要注意以下命令:
executeUpdate:是最基础的数据库的更新、插入和删除操作。效率低下。
executeQuery:是最基础的执行查询语句,同样 ......
说到GB2312和GBK就不得不提中文网页的编码。尽管很多新开发的Web系统和新上线的注重国际化的网站都开始使用UTF-8,仍有相当一部分的中文媒体坚持使用GB2312和GBK,例如新浪的页面。其中有两点很值得注意。
第一,页面中meta标签的部分,常常可以见到charset=GB2312这样的写法,很不幸的是,这个“cha ......
Java中的字符集编码入门
ASCII及相关标准
地球人都知道ASCII就是美国标准信息交换码的缩写,也知道ASCII规定用7位二进制数字来表示英文字符,ASCII被定为国际标准之后的 代号为ISO-646.由于ASCII码只使用了7个二进制位,也就是说一个字节可以表示的256个数字中,它仅使用了0-127这128个码位,剩下的 ......