You are viewing a plain text version of this content. The canonical link for it is here.
Posted to j-users@xerces.apache.org by Christian Lebaudy <cl...@netfinca.com> on 2003/04/15 10:31:43 UTC
DTD access over the internet
Hello, i am having trouble to parse a very simple document that has a
<!DOCTYPE section with an http link over the internet.
I do not want to acces internet
I do not want to have to cut the XML file to get the DOCTYPE section out
of it
I simply want to parse the document.
I am using : DOMParser parser = new DOMParser();
I try following features but the java application want always to open a
connection to the internet :
// deactivating parser XML-DTD validation
parser.setFeature("http://xml.org/sax/features/validation",false
<http://xml.org/sax/features/validation> );
// deactivating Xerces SAX parser DTD-file definition
load
parser.setFeature("http://apache.org/xml/features/nonvalidating/load-ext
ernal-dtd",false
<http://apache.org/xml/features/nonvalidating/load-external-dtd> );
// deactivating Xerces SAX parser grammar DTD-file
definition load
parser.setFeature("http://apache.org/xml/features/nonvalidating/load-dtd
-grammar",false
<http://apache.org/xml/features/nonvalidating/load-dtd-grammar> );
parser.setFeature("http://apache.org/xml/features/validation/schema",fal
se <http://apache.org/xml/features/validation/schema> );
parser.setFeature("http://apache.org/xml/features/validation/schema-full
-checking",false
<http://apache.org/xml/features/validation/schema-full-checking> );
parser.setFeature("http://apache.org/xml/features/validation/dynamic",fa
lse <http://apache.org/xml/features/validation/dynamic> );
parser.setProperty("http://apache.org/xml/properties/schema/external-sch
emaLocation",new
<http://apache.org/xml/properties/schema/external-schemaLocation>
File(".").getCanonicalPath());
I did not thought that i should have an internet connection to parse a
document.
Does anyone knows how to tell to Xerces that I only want to parse a
local document ?
thanks in advance
Re: DTD access over the internet
Posted by Simon Kitching <si...@ecnetwork.co.nz>.
Hi,
Just a note: Rahul says return "null" from method resolveEntity to
ignore a DTD: I presume he meant to say "return an empty stream" or
"return a stream containing an empty DTD".
Returning null will cause xerces' default behaviour to occur, which
*will* load the DTD from the remote location.
Jeff is quite correct to point out that if the DTD referenced contains
entity references, default values for attributes, etc., then ignoring it
will affect the content of the original XML document. If this is the
case, then you should instead keep a local copy of the DTD, and use the
EntityResolver to return the contents of that file.
Note that disabling *validation* merely suppresses error messages. The
DTD or schema files still need to be loaded because they can set default
attributes, and other things that are nothing to do with validation. So
turning off validation won't get Xerces to stop loading external DTDs or
schemas; extra steps are needed.
You do mention that you tried setting this feature to false:
http://apache.org/xml/features/nonvalidating/load-external-dtd"
I would have thought that would have done the trick without having to
define an EntityResolver...
It might be worth trying to set this feature to false before going to
the effort of writing an EntityResolver. From the description it looks
like it might be what you want:
http://apache.org/xml/features/external-parameter-entities
http://xml.org/sax/features/external-parameter-entitieshttp://xml.org/sax/features/external-parameter-entities
Regards,
Simon
On Wed, 2003-04-16 at 04:35, Jeff Greif wrote:
> Alternatively, you can provide an EntityResolver that will resolve the
> SystemId (the URI) of the DTD to a copy on the local filesystem of the
> parsing application.
>
> In general, even a non-validating XML parser is supposed to read the
> DTD to supply default values for attributes and to expand entity
> references. Without the latter, the document may not appear to be
> well-formed, or be missing very large pieces. If you know that the
> documents and DTD in question preclude the need to read the DTD, you
> can skip it as Rahul suggested.
>
> Jeff
> ----- Original Message -----
> From: Rahul Srivastava
> To: xerces-j-user@xml.apache.org
> Sent: Tuesday, April 15, 2003 3:30 AM
> Subject: RE: DTD access over the internet
>
> Hi Christian,
>
> Set an EntityResolver to the parser, and return a null from
> within resolveEntity() method, for the URI that you wish to
> ignore.
>
> Cheers,
> Rahul.
>
>
> -----Original Message-----
> From: Christian Lebaudy [mailto:clebaudy@netfinca.com]
> Sent: Tuesday, April 15, 2003 2:02 PM
> To: xerces-j-user@xml.apache.org
> Subject: DTD access over the internet
>
>
>
>
> Hello, i am having trouble to parse a very simple
> document that has a <!DOCTYPE section with an http
> link over the internet.
> I do not want to acces internet
> I do not want to have to cut the XML file to get the
> DOCTYPE section out of it
> I simply want to parse the document.
>
> I am using : DOMParser parser = new
> DOMParser();
>
> I try following features but the java application want
> always to open a connection to the internet :
>
> // deactivating parser XML-DTD
> validation
>
> parser.setFeature("http://xml.org/sax/features/validation",false);
> // deactivating Xerces SAX parser
> DTD-file definition load
>
> parser.setFeature("http://apache.org/xml/features/nonvalidating/load-external-dtd",false);
> // deactivating Xerces SAX parser
> grammar DTD-file definition load
>
> parser.setFeature("http://apache.org/xml/features/nonvalidating/load-dtd-grammar",false);
>
> parser.setFeature("http://apache.org/xml/features/validation/schema",false);
>
> parser.setFeature("http://apache.org/xml/features/validation/schema-full-checking",false);
>
> parser.setFeature("http://apache.org/xml/features/validation/dynamic",false);
>
> parser.setProperty("http://apache.org/xml/properties/schema/external-schemaLocation",new File(".").getCanonicalPath());
>
> I did not thought that i should have an internet
> connection to parse a document.
> Does anyone knows how to tell to Xerces that I only
> want to parse a local document ?
>
> thanks in advance
>
---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-j-user-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-j-user-help@xml.apache.org
Re: DTD access over the internet
Posted by Jeff Greif <jg...@alumni.princeton.edu>.
MessageAlternatively, you can provide an EntityResolver that will resolve the SystemId (the URI) of the DTD to a copy on the local filesystem of the parsing application.
In general, even a non-validating XML parser is supposed to read the DTD to supply default values for attributes and to expand entity references. Without the latter, the document may not appear to be well-formed, or be missing very large pieces. If you know that the documents and DTD in question preclude the need to read the DTD, you can skip it as Rahul suggested.
Jeff
----- Original Message -----
From: Rahul Srivastava
To: xerces-j-user@xml.apache.org
Sent: Tuesday, April 15, 2003 3:30 AM
Subject: RE: DTD access over the internet
Hi Christian,
Set an EntityResolver to the parser, and return a null from within resolveEntity() method, for the URI that you wish to ignore.
Cheers,
Rahul.
-----Original Message-----
From: Christian Lebaudy [mailto:clebaudy@netfinca.com]
Sent: Tuesday, April 15, 2003 2:02 PM
To: xerces-j-user@xml.apache.org
Subject: DTD access over the internet
Hello, i am having trouble to parse a very simple document that has a <!DOCTYPE section with an http link over the internet.
I do not want to acces internet
I do not want to have to cut the XML file to get the DOCTYPE section out of it
I simply want to parse the document.
I am using : DOMParser parser = new DOMParser();
I try following features but the java application want always to open a connection to the internet :
// deactivating parser XML-DTD validation
parser.setFeature("http://xml.org/sax/features/validation",false);
// deactivating Xerces SAX parser DTD-file definition load
parser.setFeature("http://apache.org/xml/features/nonvalidating/load-external-dtd",false);
// deactivating Xerces SAX parser grammar DTD-file definition load
parser.setFeature("http://apache.org/xml/features/nonvalidating/load-dtd-grammar",false);
parser.setFeature("http://apache.org/xml/features/validation/schema",false);
parser.setFeature("http://apache.org/xml/features/validation/schema-full-checking",false);
parser.setFeature("http://apache.org/xml/features/validation/dynamic",false);
parser.setProperty("http://apache.org/xml/properties/schema/external-schemaLocation",new File(".").getCanonicalPath());
I did not thought that i should have an internet connection to parse a document.
Does anyone knows how to tell to Xerces that I only want to parse a local document ?
thanks in advance
RE: DTD access over the internet
Posted by Rahul Srivastava <rs...@firstam.com>.
MessageHi Christian,
Set an EntityResolver to the parser, and return a null from within
resolveEntity() method, for the URI that you wish to ignore.
Cheers,
Rahul.
-----Original Message-----
From: Christian Lebaudy [mailto:clebaudy@netfinca.com]
Sent: Tuesday, April 15, 2003 2:02 PM
To: xerces-j-user@xml.apache.org
Subject: DTD access over the internet
Hello, i am having trouble to parse a very simple document that has a
<!DOCTYPE section with an http link over the internet.
I do not want to acces internet
I do not want to have to cut the XML file to get the DOCTYPE section out
of it
I simply want to parse the document.
I am using : DOMParser parser = new DOMParser();
I try following features but the java application want always to open a
connection to the internet :
// deactivating parser XML-DTD validation
parser.setFeature("http://xml.org/sax/features/validation",false);
// deactivating Xerces SAX parser DTD-file definition load
parser.setFeature("http://apache.org/xml/features/nonvalidating/load-externa
l-dtd",false);
// deactivating Xerces SAX parser grammar DTD-file
definition load
parser.setFeature("http://apache.org/xml/features/nonvalidating/load-dtd-gra
mmar",false);
parser.setFeature("http://apache.org/xml/features/validation/schema",false);
parser.setFeature("http://apache.org/xml/features/validation/schema-full-che
cking",false);
parser.setFeature("http://apache.org/xml/features/validation/dynamic",false)
;
parser.setProperty("http://apache.org/xml/properties/schema/external-schemaL
ocation",new File(".").getCanonicalPath());
I did not thought that i should have an internet connection to parse a
document.
Does anyone knows how to tell to Xerces that I only want to parse a local
document ?
thanks in advance