Groovy解析xml,解析过程超简洁
方式1:
static main(args) {
File xmls =new File("");
def asset = new XmlParser().parse("c:/CCTV1_20120523_185942738_770297_117912.xml");
def title=asset.title[0].text()
def keywords=asset.keywords[0].text()
def coloumnName=asset.coloumnName[0].text()
def categoryName=asset.categoryName[0].text()
def duration=asset.duration[0].text()
def imagePath=asset.imagePath[0].text()
println title
println keywords
println coloumnName
println categoryName
println duration
println imagePath
}
方式2:
static main(args){
def books = new XmlParser().parse("c:/b.xml");
def bookss = books.book;
def specialBook = bookss[3];
books.book.each {
def bookid = it.attributes().get("bookid");
println bookid;
def properties = specialBook.position[0].property;
properties.each {
println "-------------------"
println it.'@name';
println it.text();
println "-------------------"
}
}
}
两个xml文件如下:
CCTV1_20120523_185942738_770297_117912.xml
<?xml version='1.0' encoding='utf-8' ?>
<Asset>
<uuid>882657bc-698f-4a71-9d3a-3c95f4138c63</uuid>
<id></id>
<playTime><![CDATA[2012-05-23 19:01:40]]></playTime>
<author>TVM</author>
<language>Chinese</language>
<title><![CDATA[纪念同志《在延安文艺座谈会上的讲话》发表70周年座谈会在京召开]]></title>
<content><![CDATA[]]></content>
<keywords><![CDATA[纪念部]]></keywords>
<channelCName>CCTV-1</channelCName>
<channelName>CCTV1</channelName>
<coloumnName>新闻联播</coloumnName>
<imagePath><![CDATA[News/JPG/CCTV1/2012/05/23/CCTV1_20120523_185942738_770297_117912.jpg]]></imagePath>
<categoryName>时政</categoryName>
<categoryId>25</categoryId>
<columnId>16</columnId>
<channelId>16</channelId>
<duration>290232</duration>
<updateTime><![CDATA[2012-05-23 19:23:52]]></updateTime>
<AssetFiles>
<fileCount>9</fileCount>
<file>
<fileFormat>AVI</fileFormat>
<filePath><![CDATA[News/AVI/CCTV1/2012/05/23/CCTV1_20120523_185942738_770297_117912.avi]]></filePath>
<videoCodec>Xvid</videoCodec>
<videoFrameRate>25</videoFrameRate>
<videoBitRate>1500</videoBitRate>
<width>704</width>
<hight>576</hight>
<audioCodec>MEPG</audioCodec>
<audioBitRate>128</audioBitRate>
<audioFrequency>44100</audioFrequency>
<duration>290232</duration>
<fileSize></fileSize>
</file>
<file>
<fileFormat>FLV</fileFormat>
<filePath><![CDATA[News/FLV/CCTV1/2012/05/23/CCTV1_20120523_185942738_770297_117912.flv]]></filePath>
<videoCodec>H.263</videoCodec>
<videoFrameRate>25</videoFrameRate>
<videoBitRate>100</videoBitRate>
<width>320</width>
<hight>240</hight>
<audioCodec>MEPG</audioCodec>
<audioBitRate>64</audioBitRate>
<audioFrequency>44100</audioFrequency>
<duration>290232</duration>
<fileSize></fileSize>
</file>
<file>
<fileFormat>NFLV</fileFormat>
<filePath><![CDATA[News/NFLV/CCTV1/2012/05/23/CCTV1_20120523_185942738_770297_117912.flv]]></filePath>
<videoCodec>H.264</videoCodec>
<videoFrameRate>25</videoFrameRate>
<videoBitRate>400</videoBitRate>
<width>480</width>
<hight>360</hight>
<audioCodec>MEPG</audioCodec>
<audioBitRate>32</audioBitRate>
<audioFrequency>44100</audioFrequency>
<duration>290232</duration>
<fileSize></fileSize>
</file>
<file>
<fileFormat>MP4_MAIN</fileFormat>
<filePath><![CDATA[News/MP4_MAIN/CCTV1/2012/05/23/CCTV1_20120523_185942738_770297_117912.mp4]]></filePath>
<videoCodec>AVC</videoCodec>
<videoFrameRate>25</videoFrameRate>
<videoBitRate>512</videoBitRate>
<width>400</width>
<hight>300</hight>
<audioCodec>AAC</audioCodec>
<audioBitRate>48</audioBitRate>
<audioFrequency>48000</audioFrequency>
<duration>290232</duration>
<fileSize></fileSize>
</file>
<file>
<fileFormat>MP4</fileFormat>
<filePath><![CDATA[News/MP4/CCTV1/2012/05/23/CCTV1_20120523_185942738_770297_117912.mp4]]></filePath>
<videoCodec>AVC</videoCodec>
<videoFrameRate>25</videoFrameRate>
<videoBitRate>250</videoBitRate>
<width>352</width>
<hight>288</hight>
<audioCodec>AAC</audioCodec>
<audioBitRate>32</audioBitRate>
<audioFrequency>44100</audioFrequency>
<duration>290232</duration>
<fileSize></fileSize>
</file>
<file>
<fileFormat>JPG</fileFormat>
<filePath><![CDATA[News/JPG/CCTV1/2012/05/23/CCTV1_20120523_185942738_770297_117912.jpg]]></filePath>
<width>704</width>
<hight>576</hight>
<fileSize></fileSize>
</file>
<file>
<fileFormat>SJPG</fileFormat>
<filePath><![CDATA[News/SJPG/CCTV1/2012/05/23/CCTV1_20120523_185942738_770297_117912.jpg]]></filePath>
<width>96</width>
<hight>72</hight>
<fileSize></fileSize>
</file>
<file>
<fileFormat>MTG</fileFormat>
<filePath><![CDATA[News/MTG/CCTV1/2012/05/23/CCTV1_20120523_185942738_770297_117912.mtg]]></filePath>
<fileSize></fileSize>
</file>
<file>
<fileFormat>TMF</fileFormat>
<filePath><![CDATA[]]></filePath>
<fileSize></fileSize>
</file>
</AssetFiles>
</Asset>
b.xml
<?xml version="1.0" encoding="UTF-8"?>
<books location="theLocation">
<book bookid="1" mark="4">Java in action</book>
<book bookid="2" mark="3">Groovy in action</book>
<book bookid="3" mark="2">JavaScript in action</book>
<book bookid="4">
<position url="http://">
<property name="propertiName1">Hello</property>
<property name="propertiName2">World</property>
</position>
</book>
</books>
分享到:
相关推荐
xstream、dom4j、groovy、jdom解析xml,所给的xml的例子比较全吧,基本搞懂了这些,这四种解析就差不多了
脚本解析工具,可使用Groovy或Xquery解析JSON报文或XML报文
入参是字符串格式的xml,目的是解析xml节点值,作为数据库检索where条件,检索出数据库记录,利用四个游标返回四个数据集,然后用groovy脚本将四个游标数据集解析成json出参中对应的四个节点值。出参json有两层结构...
书店 软件设计实验室的作业 2,第 3 年 CS 自己提出的任务: - 习惯 git; - 习惯 groovy; - 创建一个书店应用程序 - 用 groovy 解析 xmls
测试更富有表现力,脚本任务,比如XML解析或倒入数据,提供扩展点在您的应用程序中,最终用户可以自定义行为与自己的脚本, 用于定义特定于域的语言表达可读的和简洁的业务规则,甚至作为一个成熟的通用语言编写应用程序的...
CodeNarc应用适用于每个Groovy文件的一组规则(预定义和/或自定义),并生成结果HTML或XML报告,包括每个源文件违反的规则列表以及每包和整个项目的违规行为。 CodeNarc与流行的静态分析工具(例如PMD或Checkstyle...
该包是一些 Groovy 类的集合。 基础 XmiParser 类执行 XMI 模型的所有解析,迭代模型中的每个元素和包,然后将它们添加到多个数据结构(包括查找表)以遍历模型。 HTML 生成器使用 javadoc 摘要页面和详细的类级...
JCaptcha4Struts2 是一个 Struts2的插件,用来增加验证码的支持,使用时只需要用一个 JSP 标签 (<jcaptcha:image label="Type the text "/> ) 即可,直接在 struts.xml 中进行配置,使用强大的 JCaptcha来生成验证码...
使用Groovy 友好 CSS 选择器 ###使用 HTTPBuilder ######介绍 CSS Selector 通过将其注册为“text/html”内容类型的解析器来与 HTTPBuilder 一起使用。 ######细节 import groovyx.net....
会议JConf 是一个用于 Java 或 Groovy 应用程序中的配置模块的简单轻便的库。 目前这个库支持 , , , , 访问了解更多详细信息用法对于行家添加依赖 < dependency> < groupId>...
Hibernate使用dom4j解析XML配置文件和XML映射元文件。必需的。 ehcache-1.2.jar Hibernate可以使用不同cache缓存工具作为二级缓存。EHCache是缺省的cache缓存工具。如果没有其它的可选缓存工具,则为必需的。 ...
Groovy 编程而不是声明 XML 的增量构建。 与 Maven 的依赖管理配合良好,并将 Ant 脚本视为一等公民。 字节码操作 以编程方式操作 Java 字节码的库。 - 通用、低级、字节码操作和分析。 - 使用流畅的 API 进一步简化...
静态节点构建器一个基于 Cedric Champeau 的 staticbuilder 项目的简单项目,旨在填补 XML 解析/生成中的空白,其中强加的要求意味着架构过于严格(正如 jaxb 和其他 XML 库所要求的那样)。 一个示例用法是: ...
Gradle通过Groovy编程而不是传统的XML声明进行配置。Gradle可以很好地配合Maven进行依赖管理,并且把Ant脚本当作头等公民。 字节码操作 编程操作Java字节码的函数库。 ASM:通用底层字节码操作及分析。 Javassist:...
Maven权威指南 Authors Tim O'Brien (Sonatype, Inc.) , John Casey (Sonatype, Inc.) , Brian Fox (Sonatype, Inc.) , Bruce Snyder () , Jason Van Zyl (Sonatype, Inc.) , Juven Xu () Abstract ...
Gradle通过Groovy编程而不是传统的XML声明进行配置。Gradle可以很好地配合Maven进行依赖管理,并且把Ant脚本当作头等公民。 字节码操作 编程操作Java字节码的函数库。 ASM:通用底层字节码操作及分析。 Javassist:...
spring-boot-starter-groovy-templates spring-boot-starter-hateoas spring-boot-starter-hornetq spring-boot-starter-integration spring-boot-starter-jdbc spring-boot-starter-...
2.2.1. 更简单的XML配置 2.2.2. 新的bean作用域 2.2.3. 可扩展的XML编写 2.3. 面向切面编程(AOP) 2.3.1. 更加简单的AOP XML配置 2.3.2. 对@AspectJ 切面的支持 2.4. 中间层 2.4.1. 在XML里更为简单的声明性事务配置 ...
为什么要使用XML,Groovy,Scala,JavaScript或其他某种语言来构建项目? 这是供跨平台使用的,特别是-linux 32/64,mac 32/64和Windows 32/64。 Java 6+ 能够复制与远程构建完全相同的构建(提供相同的“ build...
2.2.2. 更简单的XML配置 2.2.3. 可扩展的XML编写 2.2.4. Annotation(注解)驱动配置 2.2.5. 在classpath中自动搜索组件 2.3. 面向切面编程(AOP) 2.3.1. 更加简单的AOP XML配置 2.3.2. 对@AspectJ 切面的支持 ...