Win a copy of Machine Learning for Business: Using Amazon SageMaker and JupyterE this week in the Jython/Python forum
or Object Design Style Guide in the Object-Oriented programming forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
  • Campbell Ritchie
  • Bear Bibeault
  • Paul Clapham
  • Jeanne Boyarsky
  • Knute Snortum
  • Liutauras Vilda
  • Tim Cooke
  • Junilu Lacar
Saloon Keepers:
  • Ron McLeod
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Carey Brown
  • Joe Ess
  • salvin francis
  • fred rosenberger

How can I parse a document with the DTD?

Ranch Hand
Posts: 87
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am writing a program that is parsing XML.
I am using the javax.xml.parsers.DocumentBuilder to do the parsing.
The problem I have is the XML contains a referance to a DTD.
I want to parse to the XML without the DTD.
How can I do this?
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Dave,

Do you mean you want to skip the validation of the document (so don't use the DTD)?
In this case, you can disable the validation as follows:

DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
// disable validation

DocumentBuilder builder = factory.newDocumentBuilder();
Document doc = builder.parse("file.xml");

Hope it helps,


[ May 22, 2008: Message edited by: Francois Dang Ngoc ]
I'd appreciate it if you pronounced my name correctly. Pinhead, with a silent "H". Petite ad:
Java file APIs (DOC, XLS, PDF, and many more)
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!