java 解析xml

XOM

参考:https://xom.nu/

java 利用XOM解析XML

参考:http://blog.sodhanalibrary.com/2014/09/parse-xml-using-java.html#.W0rOEjozbIU

XOM解析XML为Java对象

1student_list.xml 2 3<?xml version="1.0"?> 4<students> 5 <student> 6 <name>Sriram</name> 7 <age>2</age> 8 </student> 9 <student> 10 <name>Venkat</name> 11 <age>29</age> 12 </student> 13 <student> 14 <name>Anu</name> 15 <age>28</age> 16 </student> 17</students> 18 19package com.bethecoder.tutorials.xom.tests; 20 21import java.io.IOException; 22import java.io.InputStream; 23 24import nu.xom.Builder; 25import nu.xom.Document; 26import nu.xom.Element; 27import nu.xom.Elements; 28import nu.xom.ParsingException; 29import nu.xom.ValidityException; 30 31public class ReadXML { 32 33 /** 34 * @param args 35 * @throws IOException 36 * @throws ParsingException 37 * @throws ValidityException 38 */ 39 public static void main(String[] args) throws ValidityException, ParsingException, IOException { 40 Builder builder = new Builder(); 41 InputStream ins = ReadXML.class.getClassLoader() 42 .getResourceAsStream("student_list.xml"); 43 44 //Reads and parses the XML 45 Document doc = builder.build(ins); 46 Element root = doc.getRootElement(); 47 System.out.println("Root Node : " + root.getLocalName()); 48 49 //Get children 50 Elements students = root.getChildElements(); 51 Element nameChild = null; 52 for (int i = 0 ; i < students.size() ; i ++) { 53 System.out.println(" Child : " + students.get(i).getLocalName()); 54 55 //Get first child with tag name as 'name' 56 nameChild = students.get(i).getFirstChildElement("name"); 57 if (nameChild != null) { 58 System.out.println(" Name : " + nameChild.getValue()); 59 } 60 } 61 } 62 63}

补充:https://www.petefreitag.com/item/445.cfm

点赞
收藏

评论区

加载中...

相关推荐

MySQL:[Err] 1292 - Incorrect datetime value: ‘0000-00-00 00:00:00‘ for column ‘CREATE_TIME‘ at row 1

文章目录问题用navicat导入数据时,报错:原因这是因为当前的MySQL不支持datetime为0的情况。解决修改sql\mode:sql\mode:SQLMode定义了MySQL应支持的SQL语法、数据校验等,这样可以更容易地在不同的环境中使用MySQL。全局s

Oracle 分组与拼接字符串同时使用

SELECTT.,ROWNUMIDFROM(SELECTT.EMPLID,T.NAME,T.BU,T.REALDEPART,T.FORMATDATE,SUM(T.S0)S0,MAX(UPDATETIME)CREATETIME,LISTAGG(TOCHAR(

MySQL部分从库上面因为大量的临时表tmp_table造成慢查询

背景描述Time:20190124T00:08:14.70572408:00User@Host:@Id:Schema:sentrymetaLast_errno:0Killed:0Query_time:0.315758Lock_

皕杰报表之UUID

​在我们用皕杰报表工具设计填报报表时,如何在新增行里自动增加id呢?能新增整数排序id吗?目前可以在新增行里自动增加id,但只能用uuid函数增加UUID编码,不能新增整数排序id。uuid函数说明:获取一个UUID,可以在填报表中用来创建数据ID语法:uuid()或uuid(sep)参数说明:sep布尔值,生成的uuid中是否包含分隔符'',缺省为

手写Java HashMap源码

HashMap的使用教程HashMap的使用教程HashMap的使用教程HashMap的使用教程HashMap的使用教程22

PhoneGap设置Icon

参考:http://cordova.apache.org/docs/en/latest/config\_ref/images.html通过config.xml中的<icon标签来设置Icon<iconsrc"res/ios/icon.png"platform"ios"width"57"height"57"densi