ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
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.
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.
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;
}
}
});
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.