这个问题我也问过,也解决了,看一下:http://expert.csdn.net/Expert/topic/1958/1958075.xml?temp=.4901087希望能对你有用.
解决方案 »
- 一个错误org.springframework.beans.factory.BeanNotOfRequiredTypeException
- Hibernate 出现attempted to assign id from null one-to-one property
- 大家讨论一下怎么学习JSP和J2EE框架..
- 有关串号的问题求达人解惑
- java中调用系统时间生成字符串
- struts+hibernate+spring代码,webwork+hibernate+velocity代码下载
- 請有好的struts例子,給一個好嗎?小弟我正在學習struts中,需要
- 很简单的一句,为什么出错?
- 一个关于JSP自定义标签的问题.急!!!
- 【求解】jsp中使用el表达式如何获取list 中的list数据?
- log4j的问题1>怎样把它输出的时间变成24小时制?2>当重新编译Servlet或javaBean后运行程序,怎样可以不用重启动tomcat仍旧可以输出log4j的
- 关于applet
jdbc:mysql://localhost/abc?user=root&useUnicode=true
这个也可以看成是节点。
import java.io.*;
import org.w3c.dom.*;//获得一个xml解析器
DocumentBuilderFactory factory=DocumentBuilderFactory.newInstance();
DocumentBuilder builder=factory.newDocumentBuilder();
//解析XML文件
Document document= builder.parse(new File("你的XML所在绝对路径"));
//获取根节点
Element root=document.getDocumentElement();
//获取所有的"Configuration"标记,它是一个NodeList
NodeList Configuration=root.getElementsByTagName("Configuration");
for(int i=0;i<Configuration.getLength();i++){
//获取Configuration的每一个元素
Element Configurations=(Element)Configuration.item(i);
//取ConnectionString
String Configurations=(String)Configurations.getElementsByTagName("ConnectionString").item(0).getFirstChild().getNodeValue();
//InternalAddr
String InternalAddr=(String)Configurations.getElementsByTagName("InternalAddr").item(0).getFirstChild().getNodeValue();
//取ExternalAddr
String ExternalAddr=(String)Configurations.getElementsByTagName("ExternalAddr").item(0).getFirstChild().getNodeValue();
}
OK了,自己研究一下吧,累死我了
import org.dom4j.io.*;
import java.io.*;SAXReader r = new SAXReader();
Document doc = r.read(new FileInputStream("parameters.xml"));connectionString = doc.selectSingleNode("Configuration/ConnectionString").getText();
internalAddress = doc.selectSingleNode("Configuration/InternalAddress").getText();
externalAddress = doc.selectSingleNode("Configuration/ExternalAddress").getText();