[jdom-interest] Parsing DTDs With JDOM?

Jon Baer jonbaer at digitalanywhere.com
Sun Jul 16 16:57:23 PDT 2000


"Simon St.Laurent" wrote:

> You might want to look at:
> http://xmlhack.com/read.php?item=626

SIMON!!!

Thank you very very much!  This was exactly what I was looking for and has
just saved me a good few days, I owe you a beer!  I can't beleive that
package is a mind boggling 24k, I think we should convince him to contribute
it to JDOM ;-)

http://www.wutka.com/dtdparser.html

It didn't come with any samples so Ive included one below if anyone wanted to
try it out, kudos to the author.

Thanks again.

- Jon

import java.io.*;
import java.util.Hashtable;
import java.util.Enumeration;

import com.wutka.dtd.*;

// Simple Example Of Parsing DTD
// @author: Jon Baer

public class DTDParseTest {

 public static void main(String[] args) {

  DTD dtd = null;

  try {
   DTDParser parser = new DTDParser(new FileReader("mydtd.dtd"));
   dtd = parser.parse();
   } catch (Exception e) {
   System.out.println(e);
   System.exit(0);
  }

  Hashtable elements = dtd.elements;

  for (Enumeration e = elements.elements() ; e.hasMoreElements() ;) {
   DTDElement element = (DTDElement)e.nextElement();
   System.out.println("Element: " + element.name);

   Hashtable attribs = element.attributes;

   if (attribs.size() > 0) {
    for (Enumeration a = attribs.elements() ; a.hasMoreElements() ;) {
     DTDAttribute attrib = (DTDAttribute)a.nextElement();
     System.out.println("\tAttribute: " + attrib.name);
    }
   }
  }

 }

}





More information about the jdom-interest mailing list