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
Post a Comment