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 and its copy at 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

External referenced DTD in XML

You have duplicate DOCTYPE declarations. If you want to reference an external DTD: test.xml <?xml version=’1.0′ encoding=’UTF-8′?> <!DOCTYPE email SYSTEM “test.dtd”> <email> <von></von> <zu></zu> <titel>Hello</titel> <text>Dear John….;-).</text> <prior type=”schnell”/> </email> test.dtd <!ELEMENT email (von,zu,titel,text,prior)> <!ELEMENT von (#PCDATA)> <!ELEMENT zu (#PCDATA)> <!ELEMENT titel (#PCDATA)> <!ELEMENT text (#PCDATA)> <!ELEMENT prior EMPTY> <!ATTLIST prior type CDATA #REQUIRED > … Read more

Make DocumentBuilder.parse ignore DTD references

Try setting features on the DocumentBuilderFactory: DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); dbf.setValidating(false); dbf.setNamespaceAware(true); dbf.setFeature(“”, false); dbf.setFeature(“”, false); dbf.setFeature(“”, false); dbf.setFeature(“”, false); DocumentBuilder db = dbf.newDocumentBuilder(); … Ultimately, I think the options are specific to the parser implementation. Here is some documentation for Xerces2 if that helps.

Why are nested anchor tags illegal?

Keep in mind that an anchor isn’t just a link, it’s also something to which one can link. (Though the former use is far more common than the latter.) Quoting W3C (old, but relevant): An anchor is a piece of text which marks the beginning and/or the end of a hypertext link. To that end, … Read more

What is DOCTYPE?

Basically, the DOCTYPE describes the HTML that will be used in your page. Browsers also use the DOCTYPE to determine how to render a page. Not including a DOCTYPE or including an incorrect one can trigger quirks mode. The kicker here is, that quirks mode in Internet Explorer is quite different from quirks mode in … Read more