java用saxReader解析下面的xml怎么搞,求帮助
答案:1 悬赏:70 手机版
解决时间 2021-11-09 17:08
- 提问者网友:低吟詩仙的傷
- 2021-11-08 22:45
java用saxReader解析下面的xml怎么搞,求帮助
最佳答案
- 五星知识达人网友:想偏头吻你
- 2021-11-08 23:25
1,你的xml中,最后一个标签错误,少一个/,会导致解析不了
public static void init(){
try {
SAXReader reader = new SAXReader();
Document document = reader.read(new File("xml\test.xml"));
List list = document.selectNodes("//OwnerSystem");
Element ele = null;
for(int i=0 ; i < list.size();i++){
ele = (Element) list.get(i);
System.out.println(ele.getText());
}
list = document.selectNodes("//LableName");
ele = null;
for(int i=0 ; i < list.size();i++){
ele = (Element) list.get(i);
List subList = ele.selectNodes("N");
for(int k=0 ; k < subList.size();k++){
ele = (Element) subList.get(k);
System.out.println(ele.getText());
}
}
} catch (Exception e) {
// TODO: handle exception
e.printStackTrace();
}
}
public static void main(String[] args) {
init();
}
public static void init(){
try {
SAXReader reader = new SAXReader();
Document document = reader.read(new File("xml\test.xml"));
List list = document.selectNodes("//OwnerSystem");
Element ele = null;
for(int i=0 ; i < list.size();i++){
ele = (Element) list.get(i);
System.out.println(ele.getText());
}
list = document.selectNodes("//LableName");
ele = null;
for(int i=0 ; i < list.size();i++){
ele = (Element) list.get(i);
List subList = ele.selectNodes("N");
for(int k=0 ; k < subList.size();k++){
ele = (Element) subList.get(k);
System.out.println(ele.getText());
}
}
} catch (Exception e) {
// TODO: handle exception
e.printStackTrace();
}
}
public static void main(String[] args) {
init();
}
我要举报
如以上问答信息为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯