xml如下:
<Tinfo>
<TCYzygs name = "zygs" id = "01">
<Tcar>
<Tcnum id = "0001">鄂H00001</Tcnum>
<Tcarcolor id = "0001">红色</Tcarcolor>
<Tcarmodel id = "0001">爱丽舍</Tcarmodel>
</Tcar>
</TCYzygs>
</Tinfo>
代码如下:
SAXReader saxr = new SAXReader();
Document dt = saxr.read("data.xml");
Element eroot = dt.getRootElement();
List<Element> fcylist = eroot.elements(“Tcnum”);
System.out.print(fcylist.size());
这里返回的List长度为0,是不是就是说elements()方法只能获取下一层的子节点,那子节点下层的子节点该样获取呢?
急,在线等,谢谢!
------解决思路----------------------
Element eroot = dt.getRootElement();
List<Element> fcylist = eroot.elements(“Tcnum”);
这2句代码没看懂吗,先获得根节点,在得跟节点下子节点集合,同理啊子节点在获得下一层子节点啊