LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
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.

Notices

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

Rep: Reputation: 30
java xml DOM question


Hi,
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
indienick
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
kpachopoulos
Member
 
Registered: Feb 2004
Location: Athens, Greece
Distribution: Gentoo,FreeBSD, Debian
Posts: 704

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:

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


Reply

Tags
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


All times are GMT -5. The time now is 03:50 AM.

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