in reply to Creating XML from DTDs

Do you mean with perl? If so, I haven't had much experience and can't help. Sorry. :-)

If not, shame on you for asking a non-perl question, and at your rank even. You should know better! :-)

Assuming you don't mean with perl, XML spy is one of the better tools available for windows. On the linux side of the OS wars, Merlot seems to have some potential.

Hope at least some of this helped.

Replies are listed 'Best First'.
Re: Re: Creating XML from DTDs
by coreolyn (Parson) on Jan 12, 2001 at 03:26 UTC

    Ack sorry. (Sorry I can't believe I posted such a poorly worded question). I got hit from left field with this one and sent out a panic question. My apologies. I've got someone that would like me to write a tool that will take a DTD then create an template XML document from the definitions.

    I've minimal XML expirience and I know XML::Parser would work on the XML doc, but would it work on the DTD?

    coreolyn Ack nevermind. They just found a commercial product... Damn there goes a nice project... grrr..
      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.

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