请问 哪位 大哥有 解析xml 完整的源码 万分感谢 请问 哪位 大哥有 解析xml 完整的源码 能否注明 如何使用 谢谢 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 转载,不好意思忘了是从哪里弄来的了-----------------------------------------------------------------------------import java.io.*;import java.util.*;import javax.servlet.http.*;import org.apache.log4j.*;import org.jdom.*;import org.jdom.input.*;public class XMLReader { static public Logger log = Logger.getLogger(XMLReader.class); protected Element m_RootElement = null; protected String m_webAppPath = null; /** * <font color="orange">构造函数。</font> * @param xmlFile <font color="steelblue">要读取的配置文件的绝对路径。</font> */ public XMLReader(String xmlFile) { m_webAppPath = null; try { SAXBuilder builder = new SAXBuilder(); document.nbspdoc = null; doc = builder.build(new FileInputStream(xmlFile)); m_RootElement = doc.getRootElement(); } catch (IOException ex) { log.error("XMLReader构造时出现IO错误:" + ex.toString()); } catch (JDOMException ex1) { log.error("XMLReader构造时分析XML文件出错:" + ex1.toString()); } catch (Exception ex) { log.error("XMLReader 构造出错:" + ex.toString()); } } public XMLReader(HttpServlet servletObj) { m_webAppPath = servletObj.getServletContext().getRealPath("/"); String configFileName = m_webAppPath + "XmlConfig/Config.xml"; try { SAXBuilder builder = new SAXBuilder(); document.nbspdoc = null; doc = builder.build(new FileInputStream(configFileName)); m_RootElement = doc.getRootElement(); } catch (IOException ex) { log.error("XMLReader构造时出现IO错误(/XmlConfig/Config.xml):" + ex.toString()); } catch (JDOMException ex1) { log.error("XMLReader构造时分析XML文件出错(/XmlConfig/Config.xml):" + ex1.toString()); } catch (Exception ex) { log.error("XMLReader构造出错(/XmlConfig/Config.xml):" + ex.toString()); } } public String getWebAppPath() { return m_webAppPath; } /** * <font color="orange">从配置文件中获得配置信息。</font> * @param key <font color="steelblue">要获取的配置名称。</font> * @param curRootName <font color="steelblue">查找的起始节点名称,如果为null从根开始查找。</font> * @return <font color="tomato">配置的字符串。</font> */ public String getElementvalue(String curRootName, String key) { String value = null; Element curRoot = getElement(null, curRootName); if (null == curRoot) { curRoot = m_RootElement; } Element keyNode = getElement(curRoot, key); if (null != keyNode) { value = keyNode.getTextTrim(); } return value; } /** * <font color="orange">根据名字获得节点。广度遍历,递归调用。</font> * @param nodeName <font color="steelblue">节点的名字。</font> * @param curRoot <font color="steelblue"> 从开始查找的起始节点,如果为null从根开始查找。</font> * @return <font color="tomato">返回从指定节点下找到的第一个节点。如果没有返回null。</font> */ private Element getElement(Element curRoot, String nodeName) { Element retElement = null; if (null == nodeName) return m_RootElement; if (null == curRoot) { curRoot = m_RootElement; } if (null != curRoot) { retElement = curRoot.getChild(nodeName); if (null == retElement) { List nestElements = curRoot.getChildren(); Iterator iterator = nestElements.iterator(); while (iterator.hasNext() && null == retElement) { retElement = getElement( (Element) iterator.next(), nodeName); } } } return retElement; } /** * <font color="orange">获得指定节点的属性。</font> * @param elementName <font color="steelblue">节点的名称。</font> * @param attName <font color="steelblue">要获得的属性的名称。</font> * @return <font color="tomato">要查找的属性的值。</font> */ public String getElementAtrribute(String elementName, String attName) { Element el = getElement(null, elementName); if (null == el) return null; return el.getAttributevalue(attName); }} www.apache.org中的项目commons-degister 转载,不好意思忘了是从哪里弄来的了-----------------------------------------------------------------------------import java.io.*;import java.util.*;import javax.servlet.http.*;import org.apache.log4j.*;import org.jdom.*;import org.jdom.input.*;public class XMLReader { static public Logger log = Logger.getLogger(XMLReader.class); protected Element m_RootElement = null; protected String m_webAppPath = null; /** * <font color="orange">构造函数。</font> * @param xmlFile <font color="steelblue">要读取的配置文件的绝对路径。</font> */ public XMLReader(String xmlFile) { m_webAppPath = null; try { SAXBuilder builder = new SAXBuilder(); document.nbspdoc = null; doc = builder.build(new FileInputStream(xmlFile)); m_RootElement = doc.getRootElement(); } catch (IOException ex) { log.error("XMLReader构造时出现IO错误:" + ex.toString()); } catch (JDOMException ex1) { log.error("XMLReader构造时分析XML文件出错:" + ex1.toString()); } catch (Exception ex) { log.error("XMLReader 构造出错:" + ex.toString()); } } public XMLReader(HttpServlet servletObj) { m_webAppPath = servletObj.getServletContext().getRealPath("/"); String configFileName = m_webAppPath + "XmlConfig/Config.xml"; try { SAXBuilder builder = new SAXBuilder(); document.nbspdoc = null; doc = builder.build(new FileInputStream(configFileName)); m_RootElement = doc.getRootElement(); } catch (IOException ex) { log.error("XMLReader构造时出现IO错误(/XmlConfig/Config.xml):" + ex.toString()); } catch (JDOMException ex1) { log.error("XMLReader构造时分析XML文件出错(/XmlConfig/Config.xml):" + ex1.toString()); } catch (Exception ex) { log.error("XMLReader构造出错(/XmlConfig/Config.xml):" + ex.toString()); } } public String getWebAppPath() { return m_webAppPath; } /** * <font color="orange">从配置文件中获得配置信息。</font> * @param key <font color="steelblue">要获取的配置名称。</font> * @param curRootName <font color="steelblue">查找的起始节点名称,如果为null从根开始查找。</font> * @return <font color="tomato">配置的字符串。</font> */ public String getElementvalue(String curRootName, String key) { String value = null; Element curRoot = getElement(null, curRootName); if (null == curRoot) { curRoot = m_RootElement; } Element keyNode = getElement(curRoot, key); if (null != keyNode) { value = keyNode.getTextTrim(); } return value; } /** * <font color="orange">根据名字获得节点。广度遍历,递归调用。</font> * @param nodeName <font color="steelblue">节点的名 转载,不好意思忘了是从哪里弄来的了-----------------------------------------------------------------------------import java.io.*;import java.util.*;import javax.servlet.http.*;import org.apache.log4j.*;import org.jdom.*;import org.jdom.input.*;public class XMLReader { static public Logger log = Logger.getLogger(XMLReader.class); protected Element m_RootElement = null; protected String m_webAppPath = null; /** * <font color="orange">构造函数。</font> * @param xmlFile <font color="steelblue">要读取的配置文件的绝对路径。</font> */ public XMLReader(String xmlFile) { m_webAppPath = null; try { SAXBuilder builder = new SAXBuilder(); document.nbspdoc = null; doc = builder.build(new FileInputStream(xmlFile)); m_RootElement = doc.getRootElement(); } catch (IOException ex) { log.error("XMLReader构造时出现IO错误:" + ex.toString()); } catch (JDOMException ex1) { log.error("XMLReader构造时分析XML文件出错:" + ex1.toString()); } catch (Exception ex) { log.error("XMLReader 构造出错:" + ex.toString()); } } public XMLReader(HttpServlet servletObj) { m_webAppPath = servletObj.getServletContext().getRealPath("/"); String configFileName = m_webAppPath + "XmlConfig/Config.xml"; try { SAXBuilder builder = new SAXBuilder(); document.nbspdoc = null; doc = builder.build(new FileInputStream(configFileName)); m_RootElement = doc.getRootElement(); } catch (IOException ex) { log.error("XMLReader构造时出现IO错误(/XmlConfig/Config.xml):" + ex.toString()); } catch (JDOMException ex1) { log.error("XMLReader构造时分析XML文件出错(/XmlConfig/Config.xml):" + ex1.toString()); } catch (Exception ex) { log.error("XMLReader构造出错(/XmlConfig/Config.xml):" + ex.toString()); } } public String getWebAppPath() { return m_webAppPath; } /** * <font color="orange">从配置文件中获得配置信息。</font> * @param key <font color="steelblue">要获取的配置名称。</font> * @param curRootName <font color="steelblue">查找的起始节点名称,如果为null从根开始查找。</font> * @return <font color="tomato">配置的字符串。</font> */ public String getElementvalue(String curRootName, String key) { String value = null; Element curRoot = getElement(null, curRootName); if (null == curRoot) { curRoot = m_RootElement; } Element keyNode = getElement(curRoot, key); if (null != keyNode) { value = keyNode.getTextTrim(); } return value; } /** * <font color="orange">根据名字获得节点。广度遍历,递归调用。</font> * @param nodeName <font color="steelblue">节点的名 转载,不好意思忘了是从哪里弄来的了-----------------------------------------------------------------------------import java.io.*;import java.util.*;import javax.servlet.http.*;import org.apache.log4j.*;import org.jdom.*;import org.jdom.input.*;public class XMLReader { static public Logger log = Logger.getLogger(XMLReader.class); protected Element m_RootElement = null; protected String m_webAppPath = null; /** * <font color="orange">构造函数。</font> * @param xmlFile <font color="steelblue">要读取的配置文件的绝对路径。</font> */ public XMLReader(String xmlFile) { m_webAppPath = null; try { SAXBuilder builder = new SAXBuilder(); document.nbspdoc = null; doc = builder.build(new FileInputStream(xmlFile)); m_RootElement = doc.getRootElement(); } catch (IOException ex) { log.error("XMLReader构造时出现IO错误:" + ex.toString()); } catch (JDOMException ex1) { log.error("XMLReader构造时分析XML文件出错:" + ex1.toString()); } catch (Exception ex) { log.error("XMLReader 构造出错:" + ex.toString()); } } public XMLReader(HttpServlet servletObj) { m_webAppPath = servletObj.getServletContext().getRealPath("/"); String configFileName = m_webAppPath + "XmlConfig/Config.xml"; try { SAXBuilder builder = new SAXBuilder(); document.nbspdoc = null; doc = builder.build(new FileInputStream(configFileName)); m_RootElement = doc.getRootElement(); } catch (IOException ex) { log.error("XMLReader构造时出现IO错误(/XmlConfig/Config.xml):" + ex.toString()); } catch (JDOMException ex1) { log.error("XMLReader构造时分析XML文件出错(/XmlConfig/Config.xml):" + ex1.toString()); } catch (Exception ex) { log.error("XMLReader构造出错(/XmlConfig/Config.xml):" + ex.toString()); } } public String getWebAppPath() { return m_webAppPath; } /** * <font color="orange">从配置文件中获得配置信息。</font> * @param key <font color="steelblue">要获取的配置名称。</font> * @param curRootName <font color="steelblue">查找的起始节点名称,如果为null从根开始查找。</font> * @return <font color="tomato">配置的字符串。</font> */ public String getElementvalue(String curRootName, String key) { String value = null; Element curRoot = getElement(null, curRootName); if (null == curRoot) { curRoot = m_RootElement; } Element keyNode = getElement(curRoot, key); if (null != keyNode) { value = keyNode.getTextTrim(); } return value; } /** * <font color="orange">根据名字获得节点。广度遍历,递归调用。</font> * @param nodeName <font color="steelblue">节点的名 可是这个东西 怎么用呢我有jdom包这个直接用可以么?? 把一个String 类型的转换成 ArrayList<Byte> 有什么好的方法 eclipse下连接sql2008 出现问题 JDK-JRE与JRE的JVM及lib的区别? 100分 求输入1个数N 打印前N个素数的代码 50分求解!scjp! 怎样理解2进制? 求助:关于Hashtable的一个小问题,在线等 请问:用JDBC连接数据库时,多表查询怎样区分各表字段名? 表格输出行号 为啥不对呢? 但是控制台输出正常 有没有可操作excel形状的java工具类库 如何得到上一周的周一和周日? 这个程序为什么会抛出异常
import java.io.*;
import java.util.*;
import javax.servlet.http.*;
import org.apache.log4j.*;
import org.jdom.*;
import org.jdom.input.*;
public class XMLReader { static public Logger log = Logger.getLogger(XMLReader.class);
protected Element m_RootElement = null;
protected String m_webAppPath = null; /**
* <font color="orange">构造函数。</font>
* @param xmlFile <font color="steelblue">要读取的配置文件的绝对路径。</font>
*/
public XMLReader(String xmlFile) {
m_webAppPath = null;
try { SAXBuilder builder = new SAXBuilder();
document.nbspdoc = null;
doc = builder.build(new FileInputStream(xmlFile));
m_RootElement = doc.getRootElement();
}
catch (IOException ex) {
log.error("XMLReader构造时出现IO错误:" + ex.toString());
}
catch (JDOMException ex1) {
log.error("XMLReader构造时分析XML文件出错:" + ex1.toString());
}
catch (Exception ex) {
log.error("XMLReader 构造出错:" + ex.toString());
}
}
public XMLReader(HttpServlet servletObj) {
m_webAppPath = servletObj.getServletContext().getRealPath("/");
String configFileName = m_webAppPath + "XmlConfig/Config.xml"; try {
SAXBuilder builder = new SAXBuilder();
document.nbspdoc = null;
doc = builder.build(new FileInputStream(configFileName));
m_RootElement = doc.getRootElement();
}
catch (IOException ex) {
log.error("XMLReader构造时出现IO错误(/XmlConfig/Config.xml):" + ex.toString());
}
catch (JDOMException ex1) {
log.error("XMLReader构造时分析XML文件出错(/XmlConfig/Config.xml):" + ex1.toString());
}
catch (Exception ex) {
log.error("XMLReader构造出错(/XmlConfig/Config.xml):" + ex.toString());
}
} public String getWebAppPath() {
return m_webAppPath;
} /**
* <font color="orange">从配置文件中获得配置信息。</font>
* @param key <font color="steelblue">要获取的配置名称。</font>
* @param curRootName <font color="steelblue">查找的起始节点名称,如果为null从根开始查找。</font>
* @return <font color="tomato">配置的字符串。</font>
*/
public String getElementvalue(String curRootName, String key) {
String value = null;
Element curRoot = getElement(null, curRootName);
if (null == curRoot) {
curRoot = m_RootElement;
}
Element keyNode = getElement(curRoot, key);
if (null != keyNode) {
value = keyNode.getTextTrim();
}
return value;
} /**
* <font color="orange">根据名字获得节点。广度遍历,递归调用。</font>
* @param nodeName <font color="steelblue">节点的名字。</font>
* @param curRoot <font color="steelblue"> 从开始查找的起始节点,如果为null从根开始查找。</font>
* @return <font color="tomato">返回从指定节点下找到的第一个节点。如果没有返回null。</font>
*/
private Element getElement(Element curRoot, String nodeName) {
Element retElement = null; if (null == nodeName)
return m_RootElement; if (null == curRoot) {
curRoot = m_RootElement;
} if (null != curRoot) {
retElement = curRoot.getChild(nodeName);
if (null == retElement) {
List nestElements = curRoot.getChildren();
Iterator iterator = nestElements.iterator();
while (iterator.hasNext() && null == retElement) {
retElement = getElement( (Element) iterator.next(), nodeName);
}
}
} return retElement;
} /**
* <font color="orange">获得指定节点的属性。</font>
* @param elementName <font color="steelblue">节点的名称。</font>
* @param attName <font color="steelblue">要获得的属性的名称。</font>
* @return <font color="tomato">要查找的属性的值。</font>
*/
public String getElementAtrribute(String elementName, String attName)
{
Element el = getElement(null, elementName);
if (null == el)
return null; return el.getAttributevalue(attName);
}}
import java.io.*;
import java.util.*;
import javax.servlet.http.*;
import org.apache.log4j.*;
import org.jdom.*;
import org.jdom.input.*;
public class XMLReader { static public Logger log = Logger.getLogger(XMLReader.class);
protected Element m_RootElement = null;
protected String m_webAppPath = null; /**
* <font color="orange">构造函数。</font>
* @param xmlFile <font color="steelblue">要读取的配置文件的绝对路径。</font>
*/
public XMLReader(String xmlFile) {
m_webAppPath = null;
try { SAXBuilder builder = new SAXBuilder();
document.nbspdoc = null;
doc = builder.build(new FileInputStream(xmlFile));
m_RootElement = doc.getRootElement();
}
catch (IOException ex) {
log.error("XMLReader构造时出现IO错误:" + ex.toString());
}
catch (JDOMException ex1) {
log.error("XMLReader构造时分析XML文件出错:" + ex1.toString());
}
catch (Exception ex) {
log.error("XMLReader 构造出错:" + ex.toString());
}
}
public XMLReader(HttpServlet servletObj) {
m_webAppPath = servletObj.getServletContext().getRealPath("/");
String configFileName = m_webAppPath + "XmlConfig/Config.xml"; try {
SAXBuilder builder = new SAXBuilder();
document.nbspdoc = null;
doc = builder.build(new FileInputStream(configFileName));
m_RootElement = doc.getRootElement();
}
catch (IOException ex) {
log.error("XMLReader构造时出现IO错误(/XmlConfig/Config.xml):" + ex.toString());
}
catch (JDOMException ex1) {
log.error("XMLReader构造时分析XML文件出错(/XmlConfig/Config.xml):" + ex1.toString());
}
catch (Exception ex) {
log.error("XMLReader构造出错(/XmlConfig/Config.xml):" + ex.toString());
}
} public String getWebAppPath() {
return m_webAppPath;
} /**
* <font color="orange">从配置文件中获得配置信息。</font>
* @param key <font color="steelblue">要获取的配置名称。</font>
* @param curRootName <font color="steelblue">查找的起始节点名称,如果为null从根开始查找。</font>
* @return <font color="tomato">配置的字符串。</font>
*/
public String getElementvalue(String curRootName, String key) {
String value = null;
Element curRoot = getElement(null, curRootName);
if (null == curRoot) {
curRoot = m_RootElement;
}
Element keyNode = getElement(curRoot, key);
if (null != keyNode) {
value = keyNode.getTextTrim();
}
return value;
} /**
* <font color="orange">根据名字获得节点。广度遍历,递归调用。</font>
* @param nodeName <font color="steelblue">节点的名
import java.io.*;
import java.util.*;
import javax.servlet.http.*;
import org.apache.log4j.*;
import org.jdom.*;
import org.jdom.input.*;
public class XMLReader { static public Logger log = Logger.getLogger(XMLReader.class);
protected Element m_RootElement = null;
protected String m_webAppPath = null; /**
* <font color="orange">构造函数。</font>
* @param xmlFile <font color="steelblue">要读取的配置文件的绝对路径。</font>
*/
public XMLReader(String xmlFile) {
m_webAppPath = null;
try { SAXBuilder builder = new SAXBuilder();
document.nbspdoc = null;
doc = builder.build(new FileInputStream(xmlFile));
m_RootElement = doc.getRootElement();
}
catch (IOException ex) {
log.error("XMLReader构造时出现IO错误:" + ex.toString());
}
catch (JDOMException ex1) {
log.error("XMLReader构造时分析XML文件出错:" + ex1.toString());
}
catch (Exception ex) {
log.error("XMLReader 构造出错:" + ex.toString());
}
}
public XMLReader(HttpServlet servletObj) {
m_webAppPath = servletObj.getServletContext().getRealPath("/");
String configFileName = m_webAppPath + "XmlConfig/Config.xml"; try {
SAXBuilder builder = new SAXBuilder();
document.nbspdoc = null;
doc = builder.build(new FileInputStream(configFileName));
m_RootElement = doc.getRootElement();
}
catch (IOException ex) {
log.error("XMLReader构造时出现IO错误(/XmlConfig/Config.xml):" + ex.toString());
}
catch (JDOMException ex1) {
log.error("XMLReader构造时分析XML文件出错(/XmlConfig/Config.xml):" + ex1.toString());
}
catch (Exception ex) {
log.error("XMLReader构造出错(/XmlConfig/Config.xml):" + ex.toString());
}
} public String getWebAppPath() {
return m_webAppPath;
} /**
* <font color="orange">从配置文件中获得配置信息。</font>
* @param key <font color="steelblue">要获取的配置名称。</font>
* @param curRootName <font color="steelblue">查找的起始节点名称,如果为null从根开始查找。</font>
* @return <font color="tomato">配置的字符串。</font>
*/
public String getElementvalue(String curRootName, String key) {
String value = null;
Element curRoot = getElement(null, curRootName);
if (null == curRoot) {
curRoot = m_RootElement;
}
Element keyNode = getElement(curRoot, key);
if (null != keyNode) {
value = keyNode.getTextTrim();
}
return value;
} /**
* <font color="orange">根据名字获得节点。广度遍历,递归调用。</font>
* @param nodeName <font color="steelblue">节点的名
import java.io.*;
import java.util.*;
import javax.servlet.http.*;
import org.apache.log4j.*;
import org.jdom.*;
import org.jdom.input.*;
public class XMLReader { static public Logger log = Logger.getLogger(XMLReader.class);
protected Element m_RootElement = null;
protected String m_webAppPath = null; /**
* <font color="orange">构造函数。</font>
* @param xmlFile <font color="steelblue">要读取的配置文件的绝对路径。</font>
*/
public XMLReader(String xmlFile) {
m_webAppPath = null;
try { SAXBuilder builder = new SAXBuilder();
document.nbspdoc = null;
doc = builder.build(new FileInputStream(xmlFile));
m_RootElement = doc.getRootElement();
}
catch (IOException ex) {
log.error("XMLReader构造时出现IO错误:" + ex.toString());
}
catch (JDOMException ex1) {
log.error("XMLReader构造时分析XML文件出错:" + ex1.toString());
}
catch (Exception ex) {
log.error("XMLReader 构造出错:" + ex.toString());
}
}
public XMLReader(HttpServlet servletObj) {
m_webAppPath = servletObj.getServletContext().getRealPath("/");
String configFileName = m_webAppPath + "XmlConfig/Config.xml"; try {
SAXBuilder builder = new SAXBuilder();
document.nbspdoc = null;
doc = builder.build(new FileInputStream(configFileName));
m_RootElement = doc.getRootElement();
}
catch (IOException ex) {
log.error("XMLReader构造时出现IO错误(/XmlConfig/Config.xml):" + ex.toString());
}
catch (JDOMException ex1) {
log.error("XMLReader构造时分析XML文件出错(/XmlConfig/Config.xml):" + ex1.toString());
}
catch (Exception ex) {
log.error("XMLReader构造出错(/XmlConfig/Config.xml):" + ex.toString());
}
} public String getWebAppPath() {
return m_webAppPath;
} /**
* <font color="orange">从配置文件中获得配置信息。</font>
* @param key <font color="steelblue">要获取的配置名称。</font>
* @param curRootName <font color="steelblue">查找的起始节点名称,如果为null从根开始查找。</font>
* @return <font color="tomato">配置的字符串。</font>
*/
public String getElementvalue(String curRootName, String key) {
String value = null;
Element curRoot = getElement(null, curRootName);
if (null == curRoot) {
curRoot = m_RootElement;
}
Element keyNode = getElement(curRoot, key);
if (null != keyNode) {
value = keyNode.getTextTrim();
}
return value;
} /**
* <font color="orange">根据名字获得节点。广度遍历,递归调用。</font>
* @param nodeName <font color="steelblue">节点的名
我有jdom包这个直接用可以么??