share
Stack OverflowHidden Features of XML, DTD and XML Schema
[0] [1] Xinus
[2010-01-03 06:18:39]
[ xml xml-schema dtd hidden-features ]
[ http://stackoverflow.com/questions/1994150/hidden-features-of-xml-dtd-and-xml-schema ] [DELETED]

With all of the other hidden features questions on SO [1], how can we forget XML?

What are the hidden features of XML, DTD and XML Schema?

(2) Returned the bounty and tried to make the question a little bit more acceptable. - Bill the Lizard
[+3] [2010-01-03 17:34:54] Mads Hansen

Entities [1] can be used to centralize content and make maintenance easier.

One cool trick that I learned from G. Ken Holman [2] was that entity references can also be used for easier namespace management [3].

An easy and robust method of maintaining URI strings is through XML general entities.

Consider the following namespaces.ent entity file declaring both an input namespace URI and a stylesheet maintenance URI:

<!--maintenance vocabularies-->
<!ENTITY ns-xyz "urn:x-crane:xyz">
<!--end of file-->

These strings can be brought into a stylesheet through a DOCTYPE declaration at the start of the stylesheet:

<!DOCTYPE xsl:stylesheet SYSTEM "namespaces.ent">
<xsl:stylesheet 
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  xmlns:abc="&ns-abc;"
  xmlns:xyz="&ns-xyz;"
  exclude-result-prefixes="xyz"
  version="1.0">
...
     <xsl:element name="def" namespace="&ns-abc;">
...

By externalizing the namespace values(and other common values) to a shared file and managed as general entities, multiple XML files can share the declared entity values. Then all of the namespace declarations in all of the XML files referencing those entities can be updated with a single update to the one file, rather than find/replace the namespace string value in each and every XML file.

This can make maintenance operations faster, easier, and more reliable for large libraries of XML and XSL files.

[1] http://www.w3.org/TR/REC-xml/#sec-entity-decl
[2] http://ca.linkedin.com/in/gkholman
[3] http://web.archive.org/web/20071113054804/http%3A//www.idealliance.org/proceedings/xml05/ship/18/Holman-18.HTML#d0e333

This is pretty interesting, but in my experience the ability to change namespaces is a problem that I've never needed to solve. Are there environments in which namespaces aren't static? - Robert Rossney
The particular XML vocabulary referenced in the case study that we dealt with did version their URIs. I know that some people version their namespace URIs for SOAP services to differentiate schema changes. That way the stub and skeleton generation code will be in different (java/.NET) packages. - Mads Hansen
1