Skip to Main Content

Java EE (Java Enterprise Edition) General Discussion

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

How to set non validating with DOM

843834Aug 1 2002 — edited Apr 29 2008
How can I avoid validation against DTD using DOM parsing?

I want to parse XML from a stream source like a socket which includes a DOCTYPE reference.
Everything left by default settings, the DocumentBuilder.parse(InputStream is); method tries to read the DTD.

This causes an exception because the DTD file couldn't be found in current working directory.

I know that I could set the factory to non validating by DocumentBuilder.setValidating(false);

But I wonder why it's needed because the default value for this property is false.

In case of SAX parsing I've seen that people use SAXParser.setProperty(String name, Object value); to achieve non validation.
However, DocumentBuilderFactory doesn't implement setProperty(). DOMParser does but I'd like to use the proper interfaces instead cutting directly into the DOMParser.

Thanks for any hint
Carsten
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on May 27 2008
Added on Aug 1 2002
12 comments
496 views