快速开始Perl XML:接口篇翻译:fayland 出处:中国Perl协会 用户推广组(Foundation of Perlchina) 原文名:《Perl XML Quickstart: The Perl XML Interfaces》 原文作者:Kip Hampton 原文出处:http://www.xml.com/pub/a/2001/04/18/perlxmlqstart1.html April 18, 2001 Perlchina提醒您:请保护作者的著作权,维护作者劳动的结晶。 |
CPAN上的XML模块可以分成三大类:对 XML 数据提供独特的接口(通常有关在XML实例和Perl数据之间的转换),实现某一标准XML API的模块,和对一些特定的XML相关任务进行简化的特殊用途模块。这个月我们先关注第一个,XML Perl专用接口。
Dromedary, or Arabian Camel
300 to 690 kg.
The dromedary camel is characterized by a long-curved
neck, deep-narrow chest, and a single hump.
...
The dromedary camel is an herbivore.
...
The dromedary camel has a lifespan of about 40-50 years
...
With the exception of rutting males, dromedaries show
very little aggressive behavior.
...
The camels prefer desert conditions characterized by a
long dry season and a short rainy season.
...
Since the dromedary camel is domesticated, the camel has
no special status in conservation.
...
现在我们假设此完整文档(可从本月例子代码中获取)包含骆驼家族所有成员的全部信息,而不仅仅是上面的单峰骆驼信息。为了举例说明每一模块是如何从此文件中提取某一数据子集,我们将写一个很简短的脚本来处理camelids.xml文档和在STDOUT上输出我们找到的每一种类的普通名(common-name),拉丁名(用括号包起来),和当前保存状况。因此,处理完整个文档,每一个脚本的输出应该为如下结果:
Bactrian Camel (Camelus bactrianus) endangered Dromedary, or Arabian Camel (Camelus dromedarius) no special status Llama (Lama glama) no special status Guanaco (Lama guanicoe) special concern Vicuna (Vicugna vicugna) endangered
Hash 如下:
my %camelid_links = (
one => { url => '
http://www.online.discovery.com/news/picture/may99/photo20.html',
description => 'Bactrian Camel in front of Great ' .
'Pyramids in Giza, Egypt.'},
two => { url => 'http://www.fotos-online.de/english/m/09/9532.htm',
description => 'Dromedary Camel illustrates the ' .
'importance of accessorizing.'},
three => { url => 'http://www.eskimo.com/~wallama/funny.htm',
description => 'Charlie - biography of a narcissistic llama.'},
four => { url => 'http://arrow.colorado.edu/travels/other/turkey.html',
description => 'A visual metaphor for the perl5-porters ' .
'list?'},
five => { url => 'http://www.galaonline.org/pics.htm',
description => 'Many cool alpacas.'},
six => { url => 'http://www.thpf.de/suedamerikareise/galerie/vicunas.htm',
description => 'Wild Vicunas in a scenic landscape.'}
);
而我们所期望从hash中创建的文档例子为:
Charlie -
biography of a narcissistic llama.
如果您对本文有任何疑问或者建议,请到讨论区发表您的意见:
>>
论坛入口 <<
上一篇:Subversion比CVS更好用
下一篇:从MySQL导出XLS数据库工具(跨平台)
【文章评论】
【收藏本文】
【推荐好友】
【打印本文】
【我要投稿】 【论坛讨论】
更多相关文章
推荐文章
精彩文章