Stopping Xerces-j parser from resolving entities on its own

V

Vineeth

Hi,

I am using xerces2.6.0 and am developing a program for converting an
xml document to a text file. My program is extending the
DefaultHandler. The first problem I am facing is that even though I
have turned the Validation feature off, the SAX parser still needs the
DTD to be present. If I remove the DOCTYPE declaration from the XML
file then it raises an exception for unparsed entities. If I provide a
zero byte DTD then the SX parser parses the document. Can someone
suggest how I can remove this dependency.

The second problem that I am facing is that my XML file contains many
external entities which I donot want the SAX parser to resolve on its
own. I would be resolving those entities programatically using java
code. I want the SAX parser to return all the text as it is to me
through the characters event. In my present case it is returning only
null values in place of any external entity. I would really
appreciate any hep in the above problems.

Thankx,
Vineeth
 
F

Frank Meyer

Hi,
I am using xerces2.6.0 and am developing a program for converting an
xml document to a text file. My program is extending the
DefaultHandler. The first problem I am facing is that even though I
have turned the Validation feature off, the SAX parser still needs the
DTD to be present. If I remove the DOCTYPE declaration from the XML
file then it raises an exception for unparsed entities. If I provide a
zero byte DTD then the SX parser parses the document. Can someone
suggest how I can remove this dependency.

There is a xerces-feature to ignore DTDs, see
http://xml.apache.org/xerces2-j/features.html#nonvalidating.load-external-dtd
However, afaik this is xerces-dependend, not a sax-feature.
The second problem that I am facing is that my XML file contains many
external entities which I donot want the SAX parser to resolve on its
own. I would be resolving those entities programatically using java
code. I want the SAX parser to return all the text as it is to me
through the characters event. In my present case it is returning only
null values in place of any external entity. I would really
appreciate any hep in the above problems.

You can write your own EntityResolver.

frank
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,997
Messages
2,570,241
Members
46,831
Latest member
RusselWill

Latest Threads

Top