资源文件的读取
来源:互联网 发布:淘宝公益宝贝计划 编辑:程序博客网 时间:2024/05/16 07:31
1.XMLParser
public class XMLParser {
protected Element elapp;
protected Document doc;
protected String filename;
public XMLParser(InputStream ins) {
elapp=null;
doc=null;
filename=null;
DocumentBuilderFactory xmlDocfactory = DocumentBuilderFactory.newInstance();
xmlDocfactory.setNamespaceAware(false);
xmlDocfactory.setValidating(false);
xmlDocfactory.setIgnoringElementContentWhitespace(true);
try {
DocumentBuilder db = xmlDocfactory.newDocumentBuilder();
doc = db.parse(ins);
elapp = doc.getDocumentElement();
} catch (Exception e) {
}
}
public String getValue(String sysname,String name)
{
String value=null;
Element child = getChildElement(getChildElement(sysname), name);
value=child==null?null:getElementValue(child);
return value;
}
private Element getChildElement(String childName)
{
return getChildElement(elapp,childName);
}
private synchronized Element getChildElement(Element parent,String childName)
{
if(parent!=null)
{
NodeList children=parent.getChildNodes();
int size=children.getLength();
for(int i=0;i<size;i++)
{
Node node=children.item(i);
if(node.getNodeType()==1)
{
Element element=(Element) node;
if(childName.equals(element.getNodeName()))
{
return element;
}
}
}
}
return null;
}
private synchronized String getElementValue(Element element)
{
NodeList nodes=element.getChildNodes();
if(nodes!=null)
{
StringBuffer sb=new StringBuffer();
for(int i=0;i<nodes.getLength();i++)
{
Node node=nodes.item(i);
if(node.getNodeType()==4 || node.getNodeType()==3)
{
sb.append(node.getNodeValue());
}
}
if(sb.length()>0)
{
return sb.toString();
}
}
return null;
}
public String getValue(String name)
{
String value = null;
Element child = getChildElement(name);
value = child == null ? null : getElementValue(child);
return value;
}
}
- 资源文件的读取
- 资源文件的读取
- 资源文件的读取
- 读取资源文件的方法
- 读取资源文件的值
- windows资源文件的读取
- 关于资源文件的读取
- IOS 资源文件的读取
- android私有文件资源文件的读取
- Android 的assets文件资源与raw文件资源读取
- java读取资源文件--使用文件流的方式读取
- 读取资源文件的方法 ApplicationResources.properties
- 读取资源文件的N种方法
- 【转】对xml资源文件的读取
- Grails探索之资源文件的读取
- 读取资源文件的N种方法- -
- 读取资源文件的三种方式
- 读取资源文件的N种方法
- netstat命令
- Twitter Bootstrap 框架介绍
- Android中如何合并两个工程的功能
- ruby-debug 命令详解
- Android4.0 Launcher源码研究
- 资源文件的读取
- 优化 PHP 代码技巧
- 如何在 Visual Basic 控件中实现 IObjectSafety
- 如何在Tomcat中创建、发布和访问基于CXF的服务
- 二分查找算法【鸡蛋】
- android 开启关闭wifi服务
- 自动获取焦点
- 资源文件读取
- 修改strurs2中struts.xml文件的位置