|
网站首页
|
JAVA文章
|
AppServers
|
Web开发
|
应用开发
|
资源下载
|
论坛
想学好编程,学好外语很重要 [enadd 2006年12月25日]
设为首页
加入收藏
联系站长
您现在的位置:
编程笔记网
>>
JAVA文章
>>
JAVAXML
>> 文章正文
XML 实用工具类
热
荐
【字体:
小
大
】
XML 实用工具类
作者:- 文章来源:- 点击数: 更新时间:2006-4-20
XML 实用工具类
JSP教程-Java与XML
package com.elink.util;
/*
* <p>Company: 凌科软件 www.elingke.com </p>
* @author liubaojun
* @version 1.0
* Created on 2004-11-29
* 来源于 elinkBSP 部分源代码
*/
import
java
.io.*;
import
java
.util.*;
import
java
x.xml.parsers.*;
import
java
x.xml.transform.*;
import
java
x.xml.transform.dom.*;
import
java
x.xml.transform.stream.*;
import org.w3c.dom.*;
import org.xml.sax.*;
public class XmlUtil
{
public static synchronized Document newDocument()
{
Document doc = null;
try
{
DocumentBuilder db = DocumentBuilderFactory.newInstance().
newDocumentBuilder();
doc = db.newDocument();
}
catch (Exception e)
{
LogUtil.logException( e );
}
return doc;
}
public static synchronized Element createRootElement()
{
Element rootElement = null;
try
{
DocumentBuilder db = DocumentBuilderFactory.newInstance().
newDocumentBuilder();
Document doc = db.newDocument();
rootElement = doc.getDocumentElement();
}
catch (Exception e)
{
e.printStackTrace();
}
return rootElement;
}
public static synchronized Element getRootElement(String fileName)
{
if (fileName == null || fileName.length() == 0)
{
return null;
}
try
{
Element rootElement = null;
FileInputStream fis = new FileInputStream(fileName);
rootElement = getRootElement(fis);
fis.close();
return rootElement;
}
catch (Exception e)
{
return null;
}
}
public static synchronized Element getRootElement(InputStream is)
{
if (is == null)
{
return null;
}
Element rootElement = null;
try
{
DocumentBuilder db = DocumentBuilderFactory.newInstance().
newDocumentBuilder();
Document doc = db.parse(is);
rootElement = doc.getDocumentElement();
}
catch (Exception e)
{
e.printStackTrace();
}
return rootElement;
}
public static synchronized Element getRootElement(InputSource is)
{
if (is == null)
{
return null;
}
Element rootElement = null;
[1]
[2]
[3]
[4]
[5]
下一页
文章录入:enadd 责任编辑:enadd
上一篇文章:
Java & xml学习笔记 SAX篇
下一篇文章:
XMLHTTP---介绍
【
发表评论
】【
加入收藏
】【
告诉好友
】【
打印此文
】【
关闭窗口
】
最新热点
最新推荐
相关文章
Java中四种XML解析技术之不完…
XMLHTTP---介绍
Java & xml学习笔记 SAX…
用Java生成XML
XML配置文件的读取处理
Tomcat和MySQL的一个Server.…
用JDom轻松整合Java和XML
本源XML数据库Xindice 介绍 …
Tiger系列一:从XML中加载属…
保护XML文档的工具[Z]
网友评论:
(只显示最新10条。评论内容只代表网友观点,与本站立场无关!)
|
设为首页
|
加入收藏
|
联系站长
|
友情链接
|
版权申明
|
管理登录
|
Copyright ©2000 - 2005
Enadd
.com
备案序号:辽ICP备06005595号
QQ:1656107
站长:
enadd