How can I create XML from Perl?

后端 未结 6 812
佛祖请我去吃肉
佛祖请我去吃肉 2020-12-05 04:52

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

6条回答
  •  独厮守ぢ
    2020-12-05 05:15

    I don't do much XML, but XML::Smart looks like it might do what you want. Take a look at the section Creating XML Data in the doc and it looks very simple and easy to use.

    Paraphrasing the doc:

    use XML::Smart;
    
    ## Create a null XML object:
    my $XML = XML::Smart->new() ;
    
    ## Add a server to the list:
    $XML->{server} = {
        os => 'Linux' ,
        type => 'mandrake' ,
        version => 8.9 ,
        address => [ '192.168.3.201', '192.168.3.202' ] ,
    } ;
    
    $XML->save('newfile.xml') ;
    

    Which would put this in newfile.xml:

    
      
    192.168.3.201
    192.168.3.202

    Cool. I'm going to have to play with this :)

提交回复
热议问题