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
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
There's some misunderstanding. You can't parse DTD using DOM or SAX. DTD describes document structure. You can validate generated document against DTD using various tools.
Just read and understand the DTD and generate XML document accordingly. You can later check if the document conforms to DTD.
EDIT: You don't have to write code for parsing DTD. First, you should read about DTD. Start with Wikipedia description, there're more links at the end.
Then read DTD manually and understand required document structure. Then just generate XML that will conform to the DTD.
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?)