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

Monks,

I have an application that takes XML files as its input. The thing is, in order to test that application, I need to generate thousands of those XML files, with random data.

The application accepts several different XML files (different DTDs), so hard-coding is not possible...

Before I start coding (a templating thing that outputs XML filled with random data, from a DTD), I would like to know if something like that has been written already... A cursory look at CPAN didn't return anything ...

Appreciate any ideas/suggestions...

Thanks.

Replies are listed 'Best First'.
Re: Automatically generating XML
by mirod (Canon) on Feb 01, 2002 at 17:56 UTC

    I don't think you will find something like this on CPAN, it is not a simple problem, especially if the DTDs are complex and if you want the documents to be really random.

    I built a generator of XML documents once (actually it was SGML, it was in 1992, and it was in C, not in Perl), the general algorythm was that each element in the DTD was generated by a function, that would randomly choose between alternate possibilities when needed, and in turn call the function for other elements. The DTD was quite complex, with nested sections of arbitrary level and complex relationship between elements in various sections. It was great fun, even though it was in C at the time.

      Yep, I quickly dropped the idea of using the DTD as templates. I am going to use a template XML, and generate more tags based on that, so if it says: <value repeat=5> I know I'll repeat the <value> tag 5 times...

Re: Automatically generating XML
by Matts (Deacon) on Feb 01, 2002 at 23:06 UTC
    Try XML::AutoWriter. The random bit you'll have to do for yourself, but AutoWriter will stick to the DTD for you.