使用Jdom来解析比JAXB好一些,关键代码如下 SAXBuilder sb = new SAXBuilder(); Document doc = sb.build(new FileInputStream("yourFile.xml")); Element root = doc.getRootElement(); //得到xml文件的根元素,这个文件应该是 <List Name="FSMount"> List myList = root.getChildren(); //得到根元素所有子元素的集合 Element book Element myNeed = (Element)myList.get(1); //得到第2个List元素 List myList2 = myNeed.getChildren();//得到这个list的子元素 Element value = (Element)myList2.get(2);//得到值以上是我的想法,但具体能不能实现没有试过,希望对你有所帮助,谢谢。
List myList = root.getChildren(); //得到根元素所有子元素的集合 Element book Element myNeed = (Element)myList.get(1); //得到第2个List元素 List myList2 = myNeed.getChildren();//得到这个list的子元素 Element value = (Element)myList2.get(2);//得到值 写的急,没看,更正为 List myList = root.getChildren(); //得到根元素所有子元素的集合 Element myNeed = (Element)myList.get(1); //得到第2个List元素 List myList2 = myNeed.getChildren();//得到这个list的子元素 Element value = (Element)myList2.get(3);//得到值
能给个例子吗?
谢谢。
SAXBuilder sb = new SAXBuilder();
Document doc = sb.build(new FileInputStream("yourFile.xml"));
Element root = doc.getRootElement(); //得到xml文件的根元素,这个文件应该是
<List Name="FSMount">
List myList = root.getChildren(); //得到根元素所有子元素的集合 Element book Element myNeed = (Element)myList.get(1); //得到第2个List元素
List myList2 = myNeed.getChildren();//得到这个list的子元素
Element value = (Element)myList2.get(2);//得到值以上是我的想法,但具体能不能实现没有试过,希望对你有所帮助,谢谢。
List myList2 = myNeed.getChildren();//得到这个list的子元素
Element value = (Element)myList2.get(2);//得到值
写的急,没看,更正为
List myList = root.getChildren(); //得到根元素所有子元素的集合
Element myNeed = (Element)myList.get(1); //得到第2个List元素
List myList2 = myNeed.getChildren();//得到这个list的子元素
Element value = (Element)myList2.get(3);//得到值