Visit Jeremy's Blog.
Go Back > Forums > Non-*NIX Forums > Programming
User Name
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.


  Search this Thread
Old 12-14-2009, 10:06 AM   #1
Registered: Feb 2004
Location: Athens, Greece
Distribution: Gentoo,FreeBSD, Debian
Posts: 705

Rep: Reputation: 30
java xml DOM question

i have a program, that uses a DOM parser, to parse a set of XML files according to a specific DTD. This set includes XMLs that are valid to the DTD and XMLs, that are not valid. How can i filter out the invalid ones? I could read a DOCTYPE or some field of them, but first i must load them; that is not possible however, since they are not valid according to the DTD and produce exceptions first.

Thank you
Old 12-15-2009, 06:54 PM   #2
Senior Member
Registered: Dec 2005
Location: London, ON, Canada
Distribution: Arch, Ubuntu, Slackware, OpenBSD, FreeBSD
Posts: 1,853

Rep: Reputation: 65
If they are not valid to the DTD, does it throw an exception of any sort? If so, when you catch the exception, skip over that XML file and carry on to the next one.
Old 12-16-2009, 09:35 AM   #3
Registered: Feb 2004
Location: Athens, Greece
Distribution: Gentoo,FreeBSD, Debian
Posts: 705

Original Poster
Rep: Reputation: 30
Thanks indienick, this would work, but somehow i didn't like the design behind this and maybe catching exceptions would be insufficient. Another way would be:

	db.setEntityResolver(new EntityResolver() {
				public InputSource resolveEntity(String publicId, String systemId)
						throws SAXException, IOException {			
		            if (!systemId.contains("XMLDefinition.dtd")) {
		                return new InputSource(new StringReader(""));
		            } else {
		                return null;


dom, java, parse

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
adding xml files to dom libxml2 pgpython Programming 0 07-20-2009 11:32 AM
XML parsing using DOM & Xerces on C++ amitpardesi Linux - Software 0 01-21-2009 05:15 PM
C++ XML DOM parser? pembo13 Programming 1 02-05-2006 03:16 PM
CXOffice can't find XML::DOM BroX Slackware 0 10-25-2004 02:47 AM
XML php dom amirspl Programming 2 09-20-2003 06:04 AM > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 10:23 PM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration