dom4j难道不能遍历出来吗,不会吧
jdom都有的功能,不断升级的dom4j会没有?
jdom都有的功能,不断升级的dom4j会没有?
解决方案 »
- 随机获取oracle中的数据是否有重复值false and true
- 在web中如何开发交互式配置程序?
- ibatis如何调用sqlserver的funcion?
- EJB
- SAP Recruitment: Software Developer - BC Tool
- tomcat5配置连接池的问题
- 第一个corba程序运行出错,请指教
- 我有一个用c写的dll,java程序汇总想用jni调用。
- 请问客户端.java程序调用EJB组件的问题
- JMeter 一个线程组的多个请求,怎么设置指定请求并发呢?
- hibernate 双向多对一映射 不能insert
- MyEclipse6.0中开发struts2.0
import java.net.MalformedURLException;
import java.util.Iterator;import org.dom4j.Attribute;
import org.dom4j.Document;
import org.dom4j.DocumentException;
import org.dom4j.Element;
import org.dom4j.Node;
import org.dom4j.io.SAXReader;public class Test1 {
public static Document read() throws MalformedURLException,
DocumentException {
StringBuffer str = new StringBuffer(
"<?xml version=\"1.0\" encoding=\"GBK\" ?>");
str.append("<root>");
str.append("<a name='aa' value='1'>");
str.append("<b name='bb' value='2'>");
str.append("<c name='cc' value='3'>");
str.append("<d name='dd' value='4'>");
str.append("</d>");
str.append("</c>");
str.append("</b>");
str.append("</a><e></e>");
str.append("</root>");
StringReader sr = new StringReader(str.toString());
SAXReader reader = new SAXReader();
Document document = reader.read(sr);
return document;
} public static void searchAtt(Element e) {
for (Iterator i = e.attributeIterator(); i.hasNext();) {
Attribute attribute = (Attribute) i.next();
System.out.println(attribute.getName()+" "+attribute.getValue());
}
} public static void searchEle(Element e) {
for (int i = 0, size = e.nodeCount(); i < size; i++) {
Node node = e.node(i);
if (node instanceof Element) {
Element nd=(Element) node;
System.out.println(nd.getName());
searchAtt(nd);
searchEle((Element) node);
}
} } public static void main(String[] args) throws Exception, DocumentException {
Document doc = read();
searchEle(doc.getRootElement());
}}