首页
学习
活动
专区
工具
TVP
发布
精选内容/技术社群/优惠产品,尽在小程序
立即前往

Groovy:XMLSlurper的正确语法,用于查找具有给定属性的元素

Groovy是用于读取和操作XML文档的DSL,而XMLSlurper是Groovy的库之一。要查找具有给定属性的元素,XMLSlurper可以使用正确的语法,以下是示例代码:

代码语言:java
复制
def document = """<?xml version="1.0"?>
<catalog>
  <book id="bk101">
   <author>Gambardella, Matthew</author>
   <title>XML Developer's Guide</title>
   <genre>Computer</genre>
   <price>44.95</price>
   <publish_date>2000-10-01</publish_date>
   <description>An in-depth look at creating applications with XML.</description>
  </book>
  <book id="bk102">
   <author>Ralls, Kim</author>
   <title>Midnight Rain</title>
   <genre>Fantasy</genre>
   <price>5.95</price>
   <publish_date>2000-12-16</publish_date>
   <description>A former architect battles corporate zombies and an evil sorceress.</description>
  </book>
</catalog>
"""

def books = new XmlSlurper().parse(document)

def authorWithID="bk102"
页面内容是否对你有帮助?
有帮助
没帮助

相关·内容

没有搜到相关的沙龙

扫码

添加站长 进交流群

领取专属 10元无门槛券

手把手带您无忧上云

扫码加入开发者社群

相关资讯

热门标签

活动推荐

    运营活动

    活动名称
    广告关闭
    领券