java - check the compatibility of an XML document against a DTD using JDOM? -


i working java , want check if xml file valid against dtd.

assuming have dtd file, want check if xml file valid against same definitions proposed in dtd file.

is there way using jdom?

yes, can, in jdom. it's easiest in jdom 2.x (as opposed 1.x).

see the saxbuilder constructor takes xmlreaderjdomfactory. example usage is:

    saxbuilder sb = new saxbuilder(xmlreaders.dtdvalidating);     document doc = sb.build("http://www.w3schools.com/dtd/note_ex_dtd.xml");     xmloutputter xout = new xmloutputter(format.getprettyformat());     xout.output(doc, system.out); 

note above code validated xml against dtd specified in doctype declaration ("note.dtd") @ location relative note-ex_dtd.xml document.


Comments

Popular posts from this blog

node.js - Mongoose: Cast to ObjectId failed for value on newly created object after setting the value -

[C++][SFML 2.2] Strange Performance Issues - Moving Mouse Lowers CPU Usage -

ios - Possible to get UIButton sizeThatFits to work? -