ckj has asked for the wisdom of the Perl Monks concerning the following question:

Hi Monks, Can you suggest how we can read a XML file and import it contents into a XLS in a proper order. You can take any sample data for illustration. Update: Is running shell script a better solution for this & why? Also to make it automated batch job should be written in shell script/perl?
  • Comment on How to read XML file and copy it data to an excel sheet

Replies are listed 'Best First'.
Re: How to read XML file and copy it data to an excel sheet
by Corion (Patriarch) on May 31, 2012 at 08:20 UTC

    See XML::Twig for reading the XML and Spreadsheet::WriteExcel for writing to XLS. Just take any of your data and write it that way for illustration. This is not a code writing service.

Re: How to read XML file and copy it data to an excel sheet
by GrandFather (Saint) on May 31, 2012 at 09:16 UTC
    Is running shell script a better solution for this & why?

    Why do you ask? As we have no idea why you need to perform this trick how can we tell what is "better"? Is an orange better than a kiwi fruit and why? Same sort of question really.

    If you tell us more about your problem domain we may be able to help, but really Corion's answer is the best pointer toward a solution you're likely to get without you giving us more to go on and showing that you have made an effort of your own.

    True laziness is hard work
Re: How to read XML file and copy it data to an excel sheet
by locked_user sundialsvc4 (Abbot) on May 31, 2012 at 18:27 UTC

    Any time that you are manipulating or transforming XML, you should make yourself thoroughly familiar with two technologies:   XPath (a sort of query-language for XML); and XSLT (a way of transforming one XML document into another).   You should also understand XML schemas and the concept of validating a file against that schema.   The on-line resources concerning these topics are legion.

    What’s the “win?”   Answer:   you might well be able to avoid most-if-not-all programming.   I think that this is one reason why Microsoft et al has moved to an external file-format that consists of (possibly compressed) XML content built against a formally-defined schema.   You might find that you can extract data from an arbitrarily-large XML document (or set of documents), and produce a sophisticated output such as a spreadsheet from it, without programming in any language at all.

    Also do not overlook the fact that Microsoft Excel, in its current incarnations, knows how to use both an XML file and an XPath/XSLT as an input data-source ... especially when an XML schema is referenced and the file validates successfully against that schema.   You might well find that the product alone, perhaps with proper optional plug-ins installed, can deal with this sort of requirement with no external assistance from Perl or any other language (other than, maybe, the Visual Basic for Applications language that is embedded into every Office product.)   Fond as I am of Perl, let it be said that Microsoft Corporation has not been asleep at the switch!