Assembling XML in Perl

余生颓废 提交于 2019-11-27 09:49:57

I've found it with a bit of digging - set_pi was a red herring. What I really want is:

XML::Twig methods: set_xml_version, set_encoding, and set_doctype.

use strict;
use warnings;

use XML::Twig;

my $twig = XML::Twig->new( 'pretty_print' => 'indented' );
$twig->set_root(
    XML::Twig::Elt->new(
        'netapp',
        {   version => 1.7,
            vfiler  => "somevfiler",
            xmlns   => "http://www.netapp.com/filer/admin",
        },
    )
);
my $api_req = $twig->root->insert_new_elt('nfs-exportfs-list-rules');
   $api_req ->insert_new_elt( 'pathname', '/vol/path/to/somewhere' );
   $api_req -> insert_new_elt ('your mum' );
   # etc.

$twig->set_doctype('netapp SYSTEM "file:/etc/netapp_filer.dtd"');
$twig->set_xml_version("1.0");
$twig->set_encoding('utf-8');

$twig->print;

Note - to send via LWP, what you'll need is $request -> content ( $twig -> sprint );

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!