Search code examples
xmldomparsingdtdsax

Can I create an XML document from dtd file in Java?


I have a simple DTD file with elements and attributes specifications. Can i create a suitable XML file (with DOM) parsing this DTD with Java and no external APIs?

Thanks in advance


Solution

  • I understand your question differently from Eugene Morozov. Tell me if I'm right: you want a program which takes as input a DTD and automatically generates XML file(s) whch are valid according to this DTD. Is it a correct description?

    If so, it is certainly possible, such programs exist for other "structure languages" (see abnfgen for BNF grammars; in the XML world, it seems that XMLSpy, for instance, can open a W3C Schema file - XSD file - and generates a sample valid XML) but I don't know one for DTD/XML, you'll have to write it yourself.

    Just be aware that there is an infinity of valid XML files according to a given DTD. Your program will just generate a small subset (but it may be sufficient for your purpose: what is it, anyway?)