非递归方式将Xml转hashmap对象
来源:互联网 发布:vb.net label 透明 编辑:程序博客网 时间:2024/06/06 06:30
项目中有个接口传递过来一个xml格式字符串,为方便处理,将其转换成hashmap
/** * 将dom对象转换成hashmap对象(备用函数) * @param document * @return */public static HashMap<String,Object> xmlToHashMap(Document document){Element root=document.getDocumentElement();NodeList iterator=root.getChildNodes();Stack<Object> stack=new Stack<Object>();Integer j=0;HashMap<String,Object> tmp=new HashMap<String, Object>();do{for(;j<iterator.getLength();j++){Node childNode = iterator.item(j);if(childNode.getNodeType() == Node.ELEMENT_NODE){if(childNode.getChildNodes().getLength()==1 ){tmp.put(childNode.getNodeName(), childNode.getTextContent());}else{HashMap<String,Object> cc=new HashMap<String, Object>();tmp.put(childNode.getNodeName(), cc);stack.push(tmp);stack.push(j+1);stack.push(iterator);tmp=cc;j=0;iterator=childNode.getChildNodes();}}}if(stack.isEmpty()){break;}iterator=(NodeList)stack.pop();j=(Integer)stack.pop();tmp=(HashMap<String,Object>)stack.pop();}while(true);return tmp;}
0 0
- 非递归方式将Xml转hashmap对象
- 递归方式将多层级xml转成map
- 递归转非递归
- 求助,将递归改为非递归
- 反转字符串递归与非递归方式
- 用递归方式实现将一个非负整数逆序输出
- 递归方式解析xml文档
- xml解析得到数据并将其插入数据库(dom4j非Xpath方式)
- [置顶]快速排序的递归方式和非递归方式
- 递归转非递归理解
- 递归算法转非递归
- xml TO json(非递归实现)
- 将树形结构的数据转换为二维数组 (续 PHP非递归方式实现无限分类(转载))
- 非递归方式遍历所有组合
- dom解析非递归方式实现
- 非递归方式遍历ftp文件夹
- 非递归方式遍历本地文件夹
- 快速排序算法 -- 非递归方式
- C#: 文件读取操作
- 指针函数与函数指针的区别
- JS属性操作实例
- SecureCRT 的使用技巧
- 将博客搬至CSDN
- 非递归方式将Xml转hashmap对象
- 隐藏UIScrollView的滚动条的方法
- jboss如何记log
- 日语学习之新版初级标准日本语-3 ここは デパートです
- KEIL5或KEIL4生成.S19文件 .BIN文件方法
- 异常处理与MiniDump详解(3) SEH(Structured Exception Handling)
- 用宏定义设置字体
- java+selenium环境搭建
- Apache配置多级域名