List childNodes = node.getChildren();
解决方案 »
- 远程传输annotation对象到老系统(譬如说1.4)的问题?
- HQL语句:mysql中怎么比较日期
- 一个全局事务警告,不明白其中的意义。
- IWAB0398E Error in generating WSDL from Java java.lang.NoClassDefFoundError: javax/activation/DataSource
- java开发使用的框架、技术
- J2EE在做实体BEAN的时候遇到的问题,下面是出错提示,大家帮帮忙看看问题出在什么地方。
- 我用jboss部署一个struts程序怎么出这种错误啊?
- weblogic7开发的项目,实施时企业买的是weblogic8,出了问题,怎么办?
- java 后台代码中的substring截取字符串中第三个;之前的数据
- 项目本来用TOMCAT5.5跑然后换到了6.0抛错
- 关于隐式对象的一个示例错误困惑中,急!!!
- 大家来给个思路 应该怎么做~
import java.io.FileInputStream;
import java.util.Iterator;
import java.util.List;import org.jdom.Document;
import org.jdom.Element;
import org.jdom.ProcessingInstruction;
import org.jdom.Text;
import org.jdom.input.SAXBuilder;
import org.jdom.xpath.*;public class ReadXML { public void myRead3XMl()throws Exception{
// 别一种方法 ,XPath是对某一个元素的其字元素的定位,
//看jdom1.0源码例程
SAXBuilder builder = new SAXBuilder();
Document doc = builder.build("c:\\student.xml");
Element root = doc.getRootElement();
XPath nodepath = XPath.newInstance("//data");
List nodes = nodepath.selectNodes(doc);
Iterator i = nodes.iterator();
while(i.hasNext()){
Element e = (Element)i.next();
List nodenames =e.getChildren("student");
Iterator k = nodenames.iterator();
while(k.hasNext()){
Element el = (Element)k.next();
System.out.println(el.getChildText("number"));
System.out.println(el.getChildText("name"));
System.out.println(el.getChildText("age"));
}
}
}
public void myRead2XMl()throws Exception{
// 别一种方法
SAXBuilder builder = new SAXBuilder();
Document doc = builder.build("c:\\student.xml");
Element root = doc.getRootElement();
List node = root.getChildren("data");
Iterator i = node.iterator();
while(i.hasNext()){
Element e = (Element)i.next();
List nodeChild = e.getChildren("student");
Iterator k = nodeChild.iterator();
while(k.hasNext()){
Element el = (Element)k.next();
System.out.println(el.getChildText("number"));
System.out.println(el.getChildText("name"));
System.out.println(el.getChildText("age"));
}
}
}
}