xml-general mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Patrick Haggerty <h...@mindspring.com>
Subject Re: How do i get the dtd name?
Date Sun, 22 Oct 2000 15:46:23 GMT
Hey there Sandeep!

Unfortunately the DOCTYPE is not reported as the first element. What you 
need to do it write your own LexicalHandler. You implement the 
LexicalHandler interface in a class and it defines a method

startDTD(java.lang.String name, java.lang.String publicId, java.lang.String 
systemId)

like so:

import org.xml.sax.ext.*;
public class MyLexicalHandler implements LexicalHandler
{
   public void startDTD(String name, String publicId, String systemId) 
throws org.xml.sax.SAXException
   {
     System.out.println("Got the DTD: " + name + sep);
     if(publicId==null)
       System.out.println("\tType SYSTEM: " + systemId);
     else
       System.out.println("\tType PUBLIC: " + publicId);
   }
   public void endDTD() throws org.xml.sax.SAXException
   {
   }
   public void startEntity(String parm1) throws org.xml.sax.SAXException
   {
   }
   public void endEntity(String parm1) throws org.xml.sax.SAXException
   {
   }
   public void startCDATA() throws org.xml.sax.SAXException
   {
   }
   public void endCDATA() throws org.xml.sax.SAXException
   {
   }
   public void comment(char[] parm1, int parm2, int parm3) throws 
org.xml.sax.SAXException
   {
   }
}

Then in your mail parser class just enable the property:
       parser.setProperty("http://xml.org/sax/properties/lexical-handler", 
new MyLexicalHandler());

And you are good to go.

Have a good one!!!

At 02:36 PM 10/22/2000 +0100, you wrote:
>Sandeep Randhawa wrote:
> >
> > Hi could somebody tell me how to get the dtd name ie ?SYSTEM filename
> > ?PUBLIC
> > What i want is the data after <!DOCTYPE, i looked up the docu, i found how
> > to do it in dom, but i need to find it in SAX. I need the dtd file name.
> > Thanks for any help.
> > PS: I looked thru the docu, but maybe i missed something.
>
>Should be the same as the first Element which will be reported through
>the first startElement() call in SAX.
>
>-Edwin
>
>---------------------------------------------------------------------
>In case of troubles, e-mail:     webmaster@xml.apache.org
>To unsubscribe, e-mail:          general-unsubscribe@xml.apache.org
>For additional commands, e-mail: general-help@xml.apache.org


Cheers!
Hagg
That's Internet for:
Patrick E. Haggerty, III

Remember to be kind to rude people
They are just too stupid to know any better


Mime
View raw message