如何从 Perl 创建 XML? [英] How can I create XML from Perl?

查看:23
本文介绍了如何从 Perl 创建 XML?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要在 Perl 中创建 XML.根据我的阅读,XML::LibXML 非常适合解析和使用来自别的地方.有人对 XML Writer 有什么建议吗?XML::Writer 还在维护吗?有人喜欢/使用它吗?

I need to create XML in Perl. From what I read, XML::LibXML is great for parsing and using XML that comes from somewhere else. Does anyone have any suggestions for an XML Writer? Is XML::Writer still maintained? Does anyone like/use it?

除了功能完整性之外,我还对易于使用的语法感兴趣,因此请在回答中描述语法以及您喜欢该模块的任何其他原因.

In addition to feature-completeness, I am interested an easy-to-use syntax, so please describe the syntax and any other reasons why you like that module in your answer.

请为每个答案提供一个建议,如果有人已经回答了您最喜欢的答案,请对该答案投票.希望很容易就能看出什么是最受欢迎的.

Please respond with one suggestion per answer, and if someone has already answered with your favorite, please vote that answer up. Hopefully it will be easy to see what is most popular.

谢谢!

推荐答案

XML::Writer 仍在维护中(至少截至今年 2 月),它确实是目前最受欢迎的 Perl XML 编写器之一.

XML::Writer is still maintained (at least, as of February of this year), and it's indeed one of the favorite Perl XML writers out there.

至于描述语法,最好查看模块的文档(链接已经在问题中).即:

As for describing the syntax, one is better to look at the module's documentation (the link is already in the question). To wit:

use XML::Writer;

my $writer = new XML::Writer();  # will write to stdout
$writer->startTag("greeting", 
                  "class" => "simple");
$writer->characters("Hello, world!");
$writer->endTag("greeting");
$writer->end();

# produces <greeting class='simple'>Hello world!</greeting>

这篇关于如何从 Perl 创建 XML?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆