package ReadJdom;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import org.jdom2.Document;
import org.jdom2.Element;
import org.jdom2.JDOMException;
import org.jdom2.input.SAXBuilder;
public class ReadJm {
public static void main(String[] args) throws JDOMException, IOException {
//新建构造器解析xml
SAXBuilder sax = new SAXBuilder();
//建一个文档去接受数据
Document doc = sax.build("readjm.xml");
//获取根元素
Element root = doc.getRootElement();
//定位到 -> Listlist = root.getChildren("Key");
List children = new ArrayList();
List childrens = new ArrayList();
System.out.println( list.size());
for (int i = 0; i
Element element=(Element)list.get(i);
System.out.println(element.getAttributeValue("Name"));//第二层节点
children= element.getChildren("Value");for (int j= 0;j < children.size(); j++) {
//System.out.println(children.size());子节点下面有多少个位Value的KV
Element elementC=(Element)children.get(j);//第三层节点
//System.out.println(elementC.getAttributeValue("Name"));得到第三层节点属性为Name的值
//定位到 -> -> if(elementC.getAttributeValue("Name").equals("PhotoIDWidth")){
//获取 -> -> 属性值
System.out.print(""+elementC.getAttributeValue("Name"));
//获取 -> -> 标签里内容
System.out.print(","+elementC.getText());
}
}
children.clear();
//定位到 -> -> children = element.getChildren("Key");
for (int k = 0; k
Element elementChildren=(Element)children.get(k);
//定位到 -> -> if(elementChildren.getAttributeValue("Name").equals("Child")){
childrens = elementChildren.getChildren("Value");
for (int j = 0; j
Element elementChildrens=(Element)childrens.get(j);//注意这里是childrens 0.10这里是第四层
//定位到 -> -> -> if(elementChildrens.getAttributeValue("Name").equals("HeadPercent")){
System.out.println(""+elementChildrens.getText());
}
}
}
}
}
}
}