- public void xmlString2MapObject(String strXML){
- Document doc = null;
- try {
- doc = DocumentHelper.parseText(strXML);
- } catch (DocumentException e) {
- e.printStackTrace();
- }
- Element rootElt = doc.getRootElement();
- List<Element> liste2 = rootElt.elements();
- for(int i=0 ;i<liste2.size();i++){
- getSubEle(liste2.get(i));
- }
- }
- /**
- * 看看还有更深层节点不 */
- public boolean isHasSubEle(Element e){
- return !e.isTextOnly();
- }
- /**
- * 节点遍历
- * @param e
- */
- public void getSubEle(Element e){
- boolean sub = isHasSubEle(e);
- if(sub){
- List<Element> subs = e.elements();
- for(int j=0 ;j<subs.size();j++){
- getSubEle(subs.get(j));
- }
- }else {
- System.out.println("key="+e.getName()+" value="+e.getText());
- return;
- }
- }
- //该片段来自于http://www.codesnippet.cn/detail/040320148880.html
来源: http://www.codesnippet.cn/detail/040320148880.html