使用Xpath递归输出所有数据
来源:互联网 发布:数控车床螺纹编程实例 编辑:程序博客网 时间:2024/06/09 18:28
public class TestMain { public static void main(String[] args) throws Exception { DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); DocumentBuilder builder = factory.newDocumentBuilder(); InputStream inputStream = TestMain.class.getClassLoader().getResourceAsStream("mybatis-config.xml"); Document doc = builder.parse(inputStream); XPath xPath = XPathFactory.newInstance().newXPath(); String expression ="/configuration"; Node node = (Node) xPath.evaluate(expression,doc, XPathConstants.NODE); printNode(node); //System.out.println(node.getNodeName()+":"+node.getNodeValue()+":"+node.getChildNodes().getLength()); } public static void printNode(Node root){ System.out.println("NodeName:"+root.getNodeName()+" NodeValue:"+root.getNodeValue()); NamedNodeMap attributes = root.getAttributes(); if(attributes!=null){ for(int i=0;i<attributes.getLength();i++){ Node item = attributes.item(i); System.out.println("attributeName:"+item.getNodeName()+" attributeValue:"+item.getNodeValue()); } } NodeList childNodes = root.getChildNodes(); if(childNodes!=null){ for(int i=0;i<childNodes.getLength();i++){ Node child = childNodes.item(i); if(child.getNodeName().equals("#text")) continue; printNode(child); } } }}
阅读全文
0 0
- 使用Xpath递归输出所有数据
- XPath遍历输出XML所有叶子节点
- 使用递归函数,输出n个元素的所有子集
- 使用递归函数,输出n个元素的所有子集
- 【递归】输出一个字符串的所有排列
- 递归输出char数组的所有排列
- 文件递归输出所有txt文件
- dom4j使用递归的方法输出xml元素的所有值
- 使用XPATH对XML数据进行解析
- 使用Xpath查询xml文档节点数据
- 使用XPath提取xml文档数据
- 使用递归输出树形目录
- 使用递归 输出文件树
- 使用递归反向输出字符串
- 【算法面试】写程序输出8皇后问题的所有排列,要求使用非递归的深度优先遍历。
- 写程序输出8皇后问题的所有排列,要求使用非递归的深度优先遍历。
- xpath使用
- xpath使用
- 第2课:通过案例对SparkStreaming 透彻理解三板斧之二:解密SparkStreaming运行机制和架构
- 使用Xpath读取xml文件
- XPath路径表达式
- 曙光初现
- 管道流进行线程间通信
- 使用Xpath递归输出所有数据
- 你为什么跳槽?真正原因找到了吗?
- 【23种设计模式】概要
- 考研英语
- Web前端学习日记29---------继续在线简历的完成
- JavaScript深入浅出(进阶)
- 一种Vin码扫描识别sdk技术
- python实现给定一个列表,输出由各个位置除了自身元素外所有元素乘积组成的列表
- 微信小程序函数中有wx.request 返回值为undefined 因为request是异步请求