how to disable dtd at runtime in java’s xpath?

You should be able to specify your own EntityResolver, or use specific features of your parser? See here for some approaches. A more complete example: <?xml version=”1.0″?> <!DOCTYPE foo PUBLIC “//FOO//” “foo.dtd”> <foo> <bar>Value</bar> </foo> And xpath usage: import java.io.File; import java.io.IOException; import java.io.StringReader; import javax.xml.parsers.DocumentBuilder; import javax.xml.parsers.DocumentBuilderFactory; import javax.xml.xpath.XPath; import javax.xml.xpath.XPathFactory; import org.w3c.dom.Document; import … Read more

How to choose between DTD and XSD

It’s probably important to learn DTDs as a separate exercise, just for the knowledge of how they work in case you encounter them somewhere else, and so that you can appreciate some of the things that XSD was trying to solve. However, for your current purposes of describing an XML document, indeed stick to XSDs. … Read more

Validate an XML file against local DTD file with Java

In an ideal world, you’d be able to validate using a Validator. Something like this: SchemaFactory schemaFactory = SchemaFactory .newInstance(XMLConstants.XML_DTD_NS_URI); Schema schema = schemaFactory.newSchema(new File( “xmlValidate.dtd”)); Validator validator = schema.newValidator(); validator.validate(new StreamSource(“xmlValidate.xml”)); Unfortunately, the Sun implementation (at least, as of Java 6) does not include support for creating a Schema instance from a DTD. You … Read more

Where is the HTML5 Document Type Definition?

There is no HTML5 DTD. The HTML5 RC explicitly says this when discussing XHTML serialization, and this clearly applies to HTML serialization as well. DTDs have been regarded by the designers of HTML5 as too limited in expressive power, and HTML5 validators (basically the HTML5 mode of http://validator.nu and its copy at http://validator.w3.org/nu/) use schemas … Read more

What is difference between XML Schema and DTD?

From the Differences Between DTDs and Schema section of the Converting a DTD into a Schema article: The critical difference between DTDs and XML Schema is that XML Schema utilize an XML-based syntax, whereas DTDs have a unique syntax held over from SGML DTDs. Although DTDs are often criticized because of this need to learn … Read more