java读取xml

JAR包:jdom.jar

SAXBuilder sax = new SAXBuilder();
Document document = sax.build(FilePath);
Element rootElement = document.getRootElement(); //得到跟节点

List firstList = rootElement.getChildren();//得到所有子节点集合,getChildren()可以得到任意节点的子节点集合


if(null!=firstList && firstList.size()>0)
{
	for(int i=0;i<firstList.size();i++)
	{
		Element secondElement = (Element)firstList.get(i);
		System.out.println(secondElement.getName());  //得到子节点名称
		List<Attribute> NetworkElementAttrList =secondElement.getAttributes();  //得到子节点参数集合

	}
}
 

你可能感兴趣的:(读取xml)