Archive for August, 2005

DTD to XSD conversion using Trang

The tool dtd2xsd.exe is commonly used to convert XML DTDs to XML Schemas. Unfortunately, it doesn’t convert correctly when it comes across an attribute definition for whitespace treatment:

<!ATTLIST ZZZ xml:space (default|preserve) 'preserve'>

The XML 1.1 specs make it clear that this is a valid declaration (see section 2.1 White Space Handling), but the output for this line after conversion with the dtd2xsd tool is:

<xsd:attribute name='xml:space' default='preserve'></xsd>

This is a problem, as the value “xml:space” is not valid for the name attribute of this element (schema validation available from w3.org). Fortunately there is another converter that does a better job. Trang correctly converts this line to:

<xs:attribute ref="xml:space" default="preserve"/>

Scope Warts

“Scope Warts” is a pretty catchy way of decribing the same way that I encode the scope of a variable in its name.

Generally, I would prefix a class variable with the, e.g. theLogger, an instance level variable with my, e.g. myAccount, and a method or lower level variable with tmp.

Works well, and even though there is IDE support for reporting errors on variable hiding in Java IDEs, its a good practice to get into, since we’re not always coding in an IDE, particularly with scripting languages.