6.5. XML::Simple

简介:

 
use strict;
use XML::Simple qw(:strict);

my $xml =q(<?xml version='1.0'?>
<library>
  <book>
    <isbn>0596001320</isbn>
    <title>Learning Perl, 3rd Edition</title>
    <author>Randal L. Schwartz</author>
    <author>Tom Phoenix</author>
  </book>
  <book>
    <isbn>1565922204</isbn>
    <title>Advanced Perl Programming</title>
    <author>Sriram Srinivasan</author>
  </book>
  <book>
    <isbn>076455106X</isbn>
    <title>Guitar for Dummies</title>
    <author>Mark Phillips</author>
    <author>John Chappell</author>
  </book>
</library>
);

my $library = XMLin($xml);

foreach my $book (@{$library->{book}}) {
  print "$book->{title}\n";
  print "  $_\n" foreach(@{$book->{author}});
}
 





原文出处:Netkiller 系列 手札
本文作者:陈景峯
转载请与作者联系,同时请务必标明文章原始出处和作者信息及本声明。

目录
相关文章
|
XML 数据格式
使用simple transformation查找xml file内某个节点的attribute是否存在指定value
使用simple transformation查找xml file内某个节点的attribute是否存在指定value
130 0
使用simple transformation查找xml file内某个节点的attribute是否存在指定value
|
2月前
|
XML Java 数据格式
Spring5入门到实战------7、IOC容器-Bean管理XML方式(外部属性文件)
这篇文章是Spring5框架的实战教程,主要介绍了如何在Spring的IOC容器中通过XML配置方式使用外部属性文件来管理Bean,特别是数据库连接池的配置。文章详细讲解了创建属性文件、引入属性文件到Spring配置、以及如何使用属性占位符来引用属性文件中的值。
Spring5入门到实战------7、IOC容器-Bean管理XML方式(外部属性文件)
|
4月前
|
XML Java 数据格式
java创建xml文件内容
java创建xml文件内容
|
4月前
|
XML Java 数据格式
java解析xml文件内容
java解析xml文件内容
|
1月前
|
SQL XML Java
mybatis :sqlmapconfig.xml配置 ++++Mapper XML 文件(sql/insert/delete/update/select)(增删改查)用法
当然,这些仅是MyBatis功能的初步介绍。MyBatis还提供了高级特性,如动态SQL、类型处理器、插件等,可以进一步提供对数据库交互的强大支持和灵活性。希望上述内容对您理解MyBatis的基本操作有所帮助。在实际使用中,您可能还需要根据具体的业务要求调整和优化SQL语句和配置。
31 1
|
2月前
|
XML 监控 数据格式
ROS 2 - Python、XML 和 YAML 编写 Launch 文件
ROS 2 - Python、XML 和 YAML 编写 Launch 文件
197 0
|
4月前
|
XML Java 数据库
配置applicationContext.xml文件
配置applicationContext.xml文件
|
3月前
|
XML Java 数据库
配置applicationContext.xml文件
配置applicationContext.xml文件