Saturday, 15 February 2014

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


I am working with Java and I want to know if an XML file is valid against DTD.

Let's say we have a DTD file, I have to see if some XML file is valid against the same definition proposed in the DTD file or not.

Is there any way to use JDOM?

Yes, you can do it in JDM. This is the easiest in JDOM 2.x (as opposed to 1.x).

See that an XMLReaderJDOMFactory takes an example usage:

  SAXbuilder sb = New SAXBuilder (XMLReaders.DTDVALIDATING); Document Doctor = sb.build ("http://www.w3schools.com/dtd/note_ex_dtd.xml"); XMLOutputter xout = new XMLOutputter (Format.getPrettyFormat ()); Xout.output (doctor, system. Out);  

Note that the above code has been validated against the DTD specified in the DocType declaration ("Note.dtd"), which is in relation to the Note-ex_dtd.xml document relative to the document . / P>


No comments:

Post a Comment