Actually XML::Parser reads the DTD, and in 2.28 and later gives you quite a bit of information about it, so you could use it to generate a tree, that you could then walk (choosing at random when faced with an alternative, or just generate _all_ alternatives and choose the shortest or some other more sophisticated heuristic) to generate a valid instance.

An alternative to generating atree would be to generate a Parse::RecDescent grammar and then I think you can use a feature of Parse::RecDescent that let's you generate a valid instance conformant to the grammar.

I did that a long time ago, in C, to generate test documents for an SGML project I was working on and it worked fine, except that it was not based directly on the DTD. You usually need more information than a DTD will give you (what kind of text is expected, what kind of ID/REFID links do you want to generate etc...)


In reply to Re: Re: Re: Re: Creating XML from DTDs by mirod
in thread Creating XML from DTDs by coreolyn

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.