| XML::TwigXML::Twig 与其他只有Perl的XML接口不同,它是一个除了标准的XML APIs外还有其它富有创造性特点的Perlish接口。需要更多更具体的介绍请查看XML.com 文章 Readinguse XML::Twig;
my $file = 'files/camelids.xml';
my $twig = XML::Twig->new();
$twig->parsefile($file);
my $root = $twig->root;
foreach my $species ($root->children('species')){
print $species->first_child_text('common-name');
print ' (' . $species->att('name') . ') ';
print $species->first_child('conservation')->att('status');
print "\n";
}
Writing
use XML::Twig;
require "files/camelid_links.pl";
my 蕀elid_links = get_camelid_data();
my $root = XML::Twig::Elt->new('html');
my $body = XML::Twig::Elt->new('body');
$body->paste($root);
foreach my $item ( keys (蕀elid_links) ) {
my $link = XML::Twig::Elt->new('a');
$link->set_att('href', $camelid_links{$item}->{url});
$link->set_text($camelid_links{$item}->{description});
$link->paste('last_child', $body);
}
print qq|<?xml version="1.0"?>|;
$root->print;
这些例子举例说明了这些普通XML Perl模块的基本使用方法。我的目标是提供足够多的例子让你感受怎么用每个模块写代码。下个月我们将眼球“实现某一标准XML API的模块”,非凡说明的,XML::DOM, XML::XPath 和其他大量的 SAX 和类SAX模块。
|
| 共4页: 上一页 [1] [2] [3] 4 下一页 |
评论加载中…