You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by Tal Dayan <ta...@zapta.com> on 2001/11/13 07:36:35 UTC

Digester - forcing a DTD

Hello,

We plan to use Digester to read an XML configuration file. When a digester
reads an XML
file, is there a way to force validation against a predefined DTD or is it
up to the user
to specify the correct DTD at the top of the XML file ?

We would like to always use our predefined DTD whatever DTD the user
specifies in the
file (if at all).

Thanks,

Tal


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


RE: Digester - forcing a DTD

Posted by Tal Dayan <ta...@zapta.com>.
Hi Craig,

Thanks for the info.

I followed the example you mentioned but it still does not work. We are
trying to validate against
a DTD that is at a specific path in the local file system. It seems that the
'file:' URL does not
work because we need to specify the 'd:' windows drive.

The XML, DTD and error message are included below. Any idea how to make it
to work ?

Thanks,

Tal

------------- templates.xml --------------

<?xml version="1.0" ?>

<!DOCTYPE Templates PUBLIC
 "-//Netscape Communications//DTD RSS 0.91//EN"
 "http://my.netscape.com/publish/formats/rss-0.91.dtd">

<!-- Experimental XML based config file. Not in production use yet. -->

<Templates>

  <Template
     name             = "Basic"
     icon-title       = "Basic Page"
     icon-description = "A simple general purpose page"
     icon-url         =
"/system/templates/common/images/thumbnail_basic.gif"
     handler-class    = "cg.templates.basic.TemplateHandler_Basic"
  />

</Templates>


---------- templates.dtd -----------

<!DOCTYPE Templates
[
   <!ELEMENT Templates (Template*)>

   <!ELEMENT Template EMPTY>

   <!ATTLIST Template name         CDATA       #REQUIRED      >
   <!ATTLIST Template caption      CDATA       #REQUIRED      >
   <!ATTLIST Template id           CDATA       #REQUIRED      >
   <!ATTLIST Template class        CDATA       #REQUIRED      >
   <!ATTLIST Template depreacated  (yes | no)  #IMPLIED  "no" >
   <!ATTLIST Template icon         CDATA       #REQUIRED      >

]>

-------- digester initialization ---------

    Digester digester = new Digester();

    digester.push(root);

    digester.register("-//Netscape Communications//DTD RSS 0.91//EN",

"file://d:/ontero/server/runtime/config/default/templates.dtd");

    digester.setValidating(true);

    // a bunch of rules follow. They rules work well when not using a DTD


--------- runtime output ----------

setDocumentLocator(org.apache.crimson.parser.Parser2$DocLocator@733675)
startDocument()
resolveEntity('-//Netscape Communications//DTD RSS 0.91//EN',
'http://my.netscape.com/publish/formats/rss-0.91.dtd')
 Resolving to alternate DTD
'file://d:/ontero/server/runtime/config/default/templates.dtd'
java.net.UnknownHostException: d
	at
org.apache.commons.digester.Digester.createSAXException(Digester.java:1763)
	at
org.apache.commons.digester.Digester.createSAXException(Digester.java:1785)
	at org.apache.commons.digester.Digester.resolveEntity(Digester.java:1051)
	at
org.apache.crimson.parser.ExternalEntity.getInputSource(ExternalEntity.java:
88)
	at org.apache.crimson.parser.Parser2.pushReader(Parser2.java:2986)
	at
org.apache.crimson.parser.Parser2.externalParameterEntity(Parser2.java:2721)
	at org.apache.crimson.parser.Parser2.maybeDoctypeDecl(Parser2.java:1154)
	at org.apache.crimson.parser.Parser2.parseInternal(Parser2.java:488)
	at org.apache.crimson.parser.Parser2.parse(Parser2.java:304)
	at org.apache.crimson.parser.XMLReaderImpl.parse(XMLReaderImpl.java:433)
	at org.apache.commons.digester.Digester.parse(Digester.java:1170)


---------------- end



> -----Original Message-----
> From: craigmcc@localhost [mailto:craigmcc@localhost]On Behalf Of Craig
> R. McClanahan
> Sent: Tuesday, November 13, 2001 6:17 AM
> To: Jakarta Commons Developers List
> Subject: Re: Digester - forcing a DTD
>
>
>
>
> On Mon, 12 Nov 2001, Tal Dayan wrote:
>
> > Date: Mon, 12 Nov 2001 22:36:35 -0800
> > From: Tal Dayan <ta...@zapta.com>
> > Reply-To: Jakarta Commons Developers List
> <co...@jakarta.apache.org>
> > To: commons-dev@jakarta.apache.org
> > Subject: Digester - forcing a DTD
> >
> > Hello,
> >
> > We plan to use Digester to read an XML configuration file. When
> a digester
> > reads an XML
> > file, is there a way to force validation against a predefined
> DTD or is it
> > up to the user
> > to specify the correct DTD at the top of the XML file ?
> >
> > We would like to always use our predefined DTD whatever DTD the user
> > specifies in the
> > file (if at all).
> >
>
> You need to do two things to make this happen:
>
> * Your XML document needs to include a <DOCTYPE> element at the top
>   that declares the public and system identifiers of the DTD that
>   you want to use.
>
> * Prior to calling digester.parse(), call digester.setValidating(true)
>   to say that you want a validating parse against the DTD.
>
> Digester also includes the ability to register internal copies of DTDs so
> that you don't have to go out across the network to get them.  This is
> done by calling the register() method, and passing two arguments:
>
> * The public identifier of the DTD you are registering (must
>   match the public identifier in the document to be parsed)
>
> * The path of a resource file (loaded via ClassLoader.getResource())
>   containing the text of the DTD.
>
> An example of this technique can be found in the
> org.apache.commons.digester.rss.RSSDigester class, which knows how to
> parse Rich Site Summary documents.  The digester.jar file includes an
> internal copy of the DTD so that you can run validating parses against it,
> even when not connected to the Internet.
>
> This is set up by the register() calls in the configure() method.
>
> > Thanks,
> >
> > Tal
> >
>
> Craig
>
>
> --
> To unsubscribe, e-mail:
<ma...@jakarta.apache.org>
For additional commands, e-mail:
<ma...@jakarta.apache.org>


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: Digester - forcing a DTD

Posted by "Craig R. McClanahan" <cr...@apache.org>.

On Mon, 12 Nov 2001, Tal Dayan wrote:

> Date: Mon, 12 Nov 2001 22:36:35 -0800
> From: Tal Dayan <ta...@zapta.com>
> Reply-To: Jakarta Commons Developers List <co...@jakarta.apache.org>
> To: commons-dev@jakarta.apache.org
> Subject: Digester - forcing a DTD
>
> Hello,
>
> We plan to use Digester to read an XML configuration file. When a digester
> reads an XML
> file, is there a way to force validation against a predefined DTD or is it
> up to the user
> to specify the correct DTD at the top of the XML file ?
>
> We would like to always use our predefined DTD whatever DTD the user
> specifies in the
> file (if at all).
>

You need to do two things to make this happen:

* Your XML document needs to include a <DOCTYPE> element at the top
  that declares the public and system identifiers of the DTD that
  you want to use.

* Prior to calling digester.parse(), call digester.setValidating(true)
  to say that you want a validating parse against the DTD.

Digester also includes the ability to register internal copies of DTDs so
that you don't have to go out across the network to get them.  This is
done by calling the register() method, and passing two arguments:

* The public identifier of the DTD you are registering (must
  match the public identifier in the document to be parsed)

* The path of a resource file (loaded via ClassLoader.getResource())
  containing the text of the DTD.

An example of this technique can be found in the
org.apache.commons.digester.rss.RSSDigester class, which knows how to
parse Rich Site Summary documents.  The digester.jar file includes an
internal copy of the DTD so that you can run validating parses against it,
even when not connected to the Internet.

This is set up by the register() calls in the configure() method.

> Thanks,
>
> Tal
>

Craig


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>