0

Can i use default perl (say Strawberry perl 5.20 v) to build xml and populate its content with mine data? Or it is better to use modules from cpan like libXML or SimpleXML ? Are any useful modules default by installation ?

palyxk
  • 341
  • 2
  • 4
  • 17

2 Answers2

2

Strawberry Perl is bundled with many useful prebuilt modules, including the excellent XML::LibXML and XML::Twig

I recommend XML::Writer for creating XML documents from scratch, but unfortunately it isn't on the list of bundled modules. However App::cpanminus is there, which means you can add to your collection of utilities with

cpanm XML::Writer

from the command line

Borodin
  • 126,100
  • 9
  • 70
  • 144
1

This is a recommendation question, so typically that's offtopic. However I will draw your attention to this from XML::Simple.

The use of this module in new code is discouraged. Other modules are available which provide more straightforward and consistent interfaces. In particular, XML::LibXML is highly recommended.

Depending on the task, different libraries are 'good'. XML::LibXML or XML::Twig are solid choices. XML::Simple isn't - it's prone to making bad code.

Above all though - you should DEFINITELY use a parser, because whilst XML looks a bit like plain text, it isn't - there are some actually quite strict rules about what is - and isn't - OK in XML, and there are some semantically identical snippets of XML that have completely different formatting.

This question is my attempt at assembling XML with XML::Twig.

Assembling XML in Perl

You will probably have to install either of these modules. But don't worry. Installing modules is a Good Thing, and one of the reasons why Perl is so good.

Sobrique
  • 52,974
  • 7
  • 60
  • 101