in reply to Re: Re: Creating XML from DTDs
in thread Creating XML from DTDs

  1. XML::Parser cannot work on DTD as DTD is not an XML document.
  2. XML::Parser cannot even validate XML document against DTD, because it's based on expat, which is non-validating XML parser.
  3. I cannot imagine how one can create 'template XML document' from DTD. DTD specifies rules for document composition, but if tag <foo> can contain tags <foobar> and <foofoo>, will you create <foo><foobar> or <foo><foofoo> (or <foo><foobar/><foofoo/>)in this 'template' document?
  4. I can imagine GUI-based tool that will help you in authoring XML by supplying you with valid tags in your current context, but if you are looking for something like this, you should at least specify OS/platform for such a tool.
BTW: If someaone know of such tool for Linux/Solaris, I will appreciate an URL.

Replies are listed 'Best First'.
Re: Re: Re: Re: Creating XML from DTDs
by mirod (Canon) on Jan 12, 2001 at 20:07 UTC

    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...)

      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.
      Not yet. But you could use my spew program to do that, and it wouldn't be hard to to use XML::Parser's info about the DTD to generate a valid spew grammar. Hmm. Sounds like a column. :)

      -- Randal L. Schwartz, Perl hacker