当前位置: 首页 > news >正文

已有域名 做网站网络广告网站

已有域名 做网站,网络广告网站,泉州做网站工作室,网站开发要学哪些本篇我们会看到 Perl 成为知名编程语言的关键特色--哈希 hash(2000年以前叫:关联数组)。 在Perl 中,可以使用各种模块和函数来解析 XML元素和属性。其中,最古老的模块是 XML::Parser,它提供了一组完整的X…

本篇我们会看到 Perl 成为知名编程语言的关键特色--哈希 hash(2000年以前叫:关联数组)。

在Perl 中,可以使用各种模块和函数来解析 XML元素和属性。其中,最古老的模块是  XML::Parser,它提供了一组完整的XML解析和处理函数,可以解析XML文档中的元素和属性。

例如,下面是一个使用 XML::Parser 模块解析 XML元素和属性 的示例代码:

编写 xml_parser_tree.pl  如下

#!/usr/bin/perl
use 5.010;
use strict;
use warnings;
use utf8;
use XML::Parser;
use Data::Dumper;if ($#ARGV != 0){die "You must specify a file.xml to parse";
}
my $file = shift @ARGV;
# Tree 风格比较难用,它的数据结构不符合标准的JSON.
my $p = XML::Parser->new(Style => 'Tree',Handlers => {Start => \&start, End => \&end_, Char => \&text});
my $tree = $p->parsefile($file) or die "cannot read file.xml\n";
#print Dumper($tree);my $f2 = $file .'.txt';
# 写入文件
open(my $fw, '>:encoding(UTF-8)', $f2) or die "cannot open file '$f2' $!";
my @array;
# 访问 hash
sub start { my ($self, $tag, %attribs) = @_;if ($tag eq 'node'){push @array, $attribs{'TEXT'};}
}
sub end_ {my ($self, $tag) = @_;
}
sub text {my ($self, $text) = @_;
}
my $ln =0; # 行数
foreach my $txt (@array){print $fw $txt ."\n";$ln++;
}
close($fw);
print $ln;

运行 perl xml_parser_tree.pl your_test.xml

编写  xml_parser_subs.pl  如下

#!/usr/bin/perl
use 5.010;
use strict;
use warnings;
use utf8;
use XML::Parser;
#use Data::Dumper;if ($#ARGV != 0){die "You must specify a file.xml to parse";
}
my $file = shift @ARGV;
# Subs 风格比较容易使用,它需要对应于标签名定义子程序
my $p = XML::Parser->new(Style => 'Subs',Handlers => {Char => \&text});
my $doc = $p->parsefile($file) or die "cannot read file.xml\n";
say '$doc is a ', $doc;my $f2 = $file .'.txt';
# 写入文件
open(my $fw, '>:encoding(UTF-8)', $f2) or die "cannot open file '$f2' $!";
my @array;
# 访问 hash
sub node { my ($self, $tag, %attribs) = @_;push @array, $attribs{'TEXT'};
}
sub node_ {my ($self, $tag) = @_;
}
sub text {my ($self, $text) = @_;
}
my $ln =0; # 行数
foreach my $txt (@array){print $fw $txt ."\n";$ln++;
}
close($fw);
print $ln;

运行 perl xml_parser_subs.pl your_test.mm

参阅:XML::Parser - A perl module for parsing XML documents - metacpan.org

http://www.tj-hxxt.cn/news/24232.html

相关文章:

  • 重庆网站托管外包公司哪家好推广链接怎么自己搞定
  • asp.net网站开发四酷全书种子搜索神器
  • 网站外链建设seo tdk
  • 网站做多久搜索引擎优化的定义是什么
  • 一般做美食网站的产品需求职业技能培训机构
  • 西安网站建设工程常德网站建设制作
  • 制作宣传册用什么app沈阳专业seo关键词优化
  • 怎样低成本做网站推广网络推广大概需要多少钱
  • 沈阳网站建设小工作室广州企业推广
  • 营销型网站建设考试答案推广普通话宣传标语
  • 数商云是外包吗关键词优化seo公司
  • 中企动力科技股份有限公司厦门分公司沙洋县seo优化排名价格
  • 网站开发的运行可行性专业公司网络推广
  • 购物商城英语seo综合查询网站源码
  • 做网站商城怎么样百度人工服务24小时电话
  • 做网站页面一般用什么软件友情链接实例
  • 中交建设招标有限公司网站360提交入口网址
  • 广西自治区政府网站建设要求太原关键词排名优化
  • 网页设计免费模板图片关键词排名优化易下拉技术
  • 网站开发是网站后台开发吗经典营销案例
  • nodejs做网站能保护源代码吗网络营销与直播电商专业介绍
  • 微博网站开发友情手机站
  • 网站备案好弄吗推广计划书范文
  • 做网站确定什么主题好搜索引擎优化英文简称
  • 手机网站优化排名seo站长网怎么下载
  • 中国十大公司排名手机系统优化
  • asp.net 网站安装包新闻摘抄
  • 招聘网站是做什麼的比优化更好的词是
  • 网站建设的大功效b站推广入口2023mmm无病毒
  • wordpress get_query_var搜索引擎优化服务公司哪家好